From 818334c592f57a59738a93ddbbf49bbc5f7bb857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 9 Sep 2022 09:55:01 +0200 Subject: [PATCH 01/69] atrac3: Allocate some extra bytes for the data buffer to workaround decoder bug. --- Core/HLE/sceAtrac.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index b22c439bc1..3e6fb45d2b 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -1948,7 +1948,12 @@ static int _AtracSetData(Atrac *atrac, u32 buffer, u32 readSize, u32 bufferSize, const char *codecName = atrac->codecType_ == PSP_MODE_AT_3 ? "atrac3" : "atrac3+"; const char *channelName = atrac->channels_ == 1 ? "mono" : "stereo"; - atrac->dataBuf_ = new u8[atrac->first_.filesize]; + // Over-allocate databuf to prevent going off the end if the bitstream is bad or if there are + // bugs in the decoder. This happens, see issue #15788. Arbitrary, but let's make it a whole page on the popular + // architecture that has the largest pages (M1). + const size_t overAllocBytes = 16384; + atrac->dataBuf_ = new u8[atrac->first_.filesize + overAllocBytes]; + memset(atrac->dataBuf_, 0, atrac->first_.filesize + overAllocBytes); if (!atrac->ignoreDataBuf_) { u32 copybytes = std::min(bufferSize, atrac->first_.filesize); Memory::Memcpy(atrac->dataBuf_, buffer, copybytes, "AtracSetData"); From e5d1bb5552f640e240aab273b42c7be54f5b1898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 9 Sep 2022 11:34:11 +0200 Subject: [PATCH 02/69] Warning fix --- Common/VR/PPSSPPVR.cpp | 2 +- Common/VR/PPSSPPVR.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 16b170e1fb..189bb67660 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -95,7 +95,7 @@ bool IsVRBuild() { return true; } -void InitVROnAndroid(void* vm, void* activity, int version, char* name) { +void InitVROnAndroid(void* vm, void* activity, int version, const char* name) { ovrJava java; java.Vm = (JavaVM*)vm; java.ActivityObject = (jobject)activity; diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index b41b69f1be..bb46d5a63a 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -7,7 +7,7 @@ // VR app flow integration bool IsVRBuild(); -void InitVROnAndroid(void* vm, void* activity, int version, char* name); +void InitVROnAndroid(void* vm, void* activity, int version, const char* name); void EnterVR(bool firstStart); void GetVRResolutionPerEye(int* width, int* height); void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale); @@ -30,7 +30,7 @@ void UpdateVRView(float* projMatrix, float* leftEye, float* rightEye); // VR app flow integration inline bool IsVRBuild() { return false; } -inline void InitVROnAndroid(void* vm, void* activity, int version, char* name) {} +inline void InitVROnAndroid(void* vm, void* activity, int version, const char* name) {} inline void EnterVR(bool firstTime) {} inline void GetVRResolutionPerEye(int* width, int* height) {} inline void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale) {} From 42b2b0a2663246a5bc2a6265a59cb77bf794bce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 9 Sep 2022 11:54:20 +0200 Subject: [PATCH 03/69] atrac3: Apply the overallocation workaround in a couple more places. Fixes #15788 . --- Core/HLE/sceAtrac.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 3e6fb45d2b..f336d8713b 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -116,6 +116,8 @@ const int PSP_ATRAC_LOOP_STREAM_DATA_IS_ON_MEMORY = -3; const u32 ATRAC3_MAX_SAMPLES = 0x400; const u32 ATRAC3PLUS_MAX_SAMPLES = 0x800; +const size_t overAllocBytes = 16384; + static const int atracDecodeDelay = 2300; #ifdef USE_FFMPEG @@ -264,7 +266,8 @@ struct Atrac { if (p.mode == p.MODE_READ) { if (dataBuf_) delete [] dataBuf_; - dataBuf_ = new u8[first_.filesize]; + dataBuf_ = new u8[first_.filesize + overAllocBytes]; + memset(dataBuf_, 0, first_.filesize + overAllocBytes); } DoArray(p, dataBuf_, first_.filesize); } @@ -453,7 +456,7 @@ struct Atrac { #else // Future versions may add other things to free, but avcodec_free_context didn't exist yet here. // Some old versions crash when we try to free extradata and subtitle_header, so let's not. A minor - // leak is better than a segfualt. + // leak is better than a segfault. // av_freep(&codecCtx_->extradata); // av_freep(&codecCtx_->subtitle_header); avcodec_close(codecCtx_); @@ -1951,7 +1954,6 @@ static int _AtracSetData(Atrac *atrac, u32 buffer, u32 readSize, u32 bufferSize, // Over-allocate databuf to prevent going off the end if the bitstream is bad or if there are // bugs in the decoder. This happens, see issue #15788. Arbitrary, but let's make it a whole page on the popular // architecture that has the largest pages (M1). - const size_t overAllocBytes = 16384; atrac->dataBuf_ = new u8[atrac->first_.filesize + overAllocBytes]; memset(atrac->dataBuf_, 0, atrac->first_.filesize + overAllocBytes); if (!atrac->ignoreDataBuf_) { @@ -2460,7 +2462,9 @@ static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) { atrac->first_.size = 0; atrac->first_.filesize = atrac->bytesPerFrame_; atrac->bufferState_ = ATRAC_STATUS_LOW_LEVEL; - atrac->dataBuf_ = new u8[atrac->first_.filesize]; + + atrac->dataBuf_ = new u8[atrac->first_.filesize + overAllocBytes]; + memset(atrac->dataBuf_, 0, atrac->first_.filesize + overAllocBytes); atrac->currentSample_ = 0; int ret = __AtracSetContext(atrac); From a6e4ec9973761ea223149ae5b7bb5f0c28696197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 9 Sep 2022 10:25:41 +0200 Subject: [PATCH 04/69] Atrac3+: Allocate some extra bytes for the data buffer to workaround decoder bug. --- Core/HLE/sceAtrac.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index f44ba65fe1..e0ec6a38a5 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -1940,7 +1940,12 @@ static int _AtracSetData(Atrac *atrac, u32 buffer, u32 readSize, u32 bufferSize, const char *codecName = atrac->codecType_ == PSP_MODE_AT_3 ? "atrac3" : "atrac3+"; const char *channelName = atrac->channels_ == 1 ? "mono" : "stereo"; - atrac->dataBuf_ = new u8[atrac->first_.filesize]; + // Over-allocate databuf to prevent going off the end if the bitstream is bad or if there are + // bugs in the decoder. This happens, see issue #15788. Arbitrary, but let's make it a whole page on the popular + // architecture that has the largest pages (M1). + const size_t overAllocBytes = 16384; + atrac->dataBuf_ = new u8[atrac->first_.filesize + overAllocBytes]; + memset(atrac->dataBuf_, 0, atrac->first_.filesize + overAllocBytes); if (!atrac->ignoreDataBuf_) { u32 copybytes = std::min(bufferSize, atrac->first_.filesize); Memory::Memcpy(atrac->dataBuf_, buffer, copybytes, "AtracSetData"); From 733152969b44a898f3a0a5ed6b6877eeb4e864aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 9 Sep 2022 11:54:20 +0200 Subject: [PATCH 05/69] atrac3: Apply the overallocation workaround in a couple more places. Fixes #15788 . --- Core/HLE/sceAtrac.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index e0ec6a38a5..087e534932 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -115,6 +115,8 @@ const int PSP_ATRAC_LOOP_STREAM_DATA_IS_ON_MEMORY = -3; const u32 ATRAC3_MAX_SAMPLES = 0x400; const u32 ATRAC3PLUS_MAX_SAMPLES = 0x800; +const size_t overAllocBytes = 16384; + static const int atracDecodeDelay = 2300; #ifdef USE_FFMPEG @@ -263,7 +265,8 @@ struct Atrac { if (p.mode == p.MODE_READ) { if (dataBuf_) delete [] dataBuf_; - dataBuf_ = new u8[first_.filesize]; + dataBuf_ = new u8[first_.filesize + overAllocBytes]; + memset(dataBuf_, 0, first_.filesize + overAllocBytes); } DoArray(p, dataBuf_, first_.filesize); } @@ -452,7 +455,7 @@ struct Atrac { #else // Future versions may add other things to free, but avcodec_free_context didn't exist yet here. // Some old versions crash when we try to free extradata and subtitle_header, so let's not. A minor - // leak is better than a segfualt. + // leak is better than a segfault. // av_freep(&codecCtx_->extradata); // av_freep(&codecCtx_->subtitle_header); avcodec_close(codecCtx_); @@ -1943,7 +1946,6 @@ static int _AtracSetData(Atrac *atrac, u32 buffer, u32 readSize, u32 bufferSize, // Over-allocate databuf to prevent going off the end if the bitstream is bad or if there are // bugs in the decoder. This happens, see issue #15788. Arbitrary, but let's make it a whole page on the popular // architecture that has the largest pages (M1). - const size_t overAllocBytes = 16384; atrac->dataBuf_ = new u8[atrac->first_.filesize + overAllocBytes]; memset(atrac->dataBuf_, 0, atrac->first_.filesize + overAllocBytes); if (!atrac->ignoreDataBuf_) { @@ -2452,7 +2454,9 @@ static int sceAtracLowLevelInitDecoder(int atracID, u32 paramsAddr) { atrac->first_.size = 0; atrac->first_.filesize = atrac->bytesPerFrame_; atrac->bufferState_ = ATRAC_STATUS_LOW_LEVEL; - atrac->dataBuf_ = new u8[atrac->first_.filesize]; + + atrac->dataBuf_ = new u8[atrac->first_.filesize + overAllocBytes]; + memset(atrac->dataBuf_, 0, atrac->first_.filesize + overAllocBytes); atrac->currentSample_ = 0; int ret = __AtracSetContext(atrac); From 4b66f967f4c6767f27e5be52a4e2b580001a4863 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 12 Aug 2022 23:48:25 -0700 Subject: [PATCH 06/69] softgpu: Correct bad munmap() size. --- GPU/Software/TransformUnit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 378b558bea..3719277141 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -46,7 +46,7 @@ TransformUnit::TransformUnit() { } TransformUnit::~TransformUnit() { - FreeMemoryPages(decoded_, DECODED_VERTEX_BUFFER_SIZE); + FreeMemoryPages(decoded_, TRANSFORM_BUF_SIZE); delete binner_; } From 6e5f056000a59ab59348e6219e6199af3f26bb6e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 00:16:08 -0700 Subject: [PATCH 07/69] Atrac: Avoid an uninitialized value. --- Core/HLE/sceAtrac.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 087e534932..ba7d5f57b7 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -404,7 +404,7 @@ struct Atrac { // Used by low-level decoding and to track streaming. u32 bufferPos_; u32 bufferValidBytes_; - u32 bufferHeaderSize_; + u32 bufferHeaderSize_ = 0; u16 channels_; u16 outputChannels_; From e356c495db5023af27eb48d053cb48579a9aa0e3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 08:09:16 -0700 Subject: [PATCH 08/69] Atrac: Avoid accessing uninitialized stream status. Only mess with this in a stream mode. --- Core/HLE/sceAtrac.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index ba7d5f57b7..4db3087283 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -622,10 +622,12 @@ struct Atrac { void ConsumeFrame() { bufferPos_ += bytesPerFrame_; - if (bufferValidBytes_ > bytesPerFrame_) { - bufferValidBytes_ -= bytesPerFrame_; - } else { - bufferValidBytes_ = 0; + if ((bufferState_ & ATRAC_STATUS_STREAMED_MASK) == ATRAC_STATUS_STREAMED_MASK) { + if (bufferValidBytes_ > bytesPerFrame_) { + bufferValidBytes_ -= bytesPerFrame_; + } else { + bufferValidBytes_ = 0; + } } if (bufferPos_ >= StreamBufferEnd()) { // Wrap around... theoretically, this should only happen at exactly StreamBufferEnd. From dab4365557c71b0a5208221fa97482d7f710cb1f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 08:10:46 -0700 Subject: [PATCH 09/69] Font: Correct uninitialized values. --- Core/HLE/sceFont.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 951b0700c0..e91eeef88b 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -486,8 +486,7 @@ public: // For save states only. } - FontLib(u32 paramPtr, u32 errorCodePtr) : fontHRes_(128.0f), fontVRes_(128.0f), altCharCode_(0x5F), charInfoBitmapAddress_(0) { - nfl_ = 0; + FontLib(u32 paramPtr, u32 errorCodePtr) { Memory::ReadStruct(paramPtr, ¶ms_); if (params_.numFonts > 9) { params_.numFonts = 9; @@ -753,14 +752,14 @@ private: std::vector fontRefCount_; FontNewLibParams params_; - float fontHRes_; - float fontVRes_; - int fileFontHandle_; - int handle_; - int altCharCode_; + float fontHRes_ = 128.0f; + float fontVRes_ = 128.0f; + int fileFontHandle_ = -1; + int handle_ = -1; + int altCharCode_ = 0x5F; std::vector openAllocatedAddresses_; - u32 charInfoBitmapAddress_; - PSPPointer nfl_; + u32 charInfoBitmapAddress_ = 0; + PSPPointer nfl_{}; DISALLOW_COPY_AND_ASSIGN(FontLib); }; From 024f8ef89bb40e80c755cb4ef04ecf5dcafc16f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 18 Aug 2022 15:20:16 +0200 Subject: [PATCH 10/69] Initialize a bunch of Dialog structs --- Core/Dialog/PSPDialog.h | 10 +++++----- Core/Dialog/PSPGamedataInstallDialog.h | 18 +++++++++--------- Core/Dialog/PSPMsgDialog.h | 6 +++--- Core/Dialog/PSPOskDialog.h | 9 ++++----- Core/Dialog/PSPSaveDialog.h | 6 +++--- Core/Dialog/SavedataParam.cpp | 11 +---------- Core/Dialog/SavedataParam.h | 13 ++++++------- 7 files changed, 31 insertions(+), 42 deletions(-) diff --git a/Core/Dialog/PSPDialog.h b/Core/Dialog/PSPDialog.h index 54a9488e36..636fc20334 100644 --- a/Core/Dialog/PSPDialog.h +++ b/Core/Dialog/PSPDialog.h @@ -99,7 +99,7 @@ protected: void ChangeStatus(DialogStatus newStatus, int delayUs); void ChangeStatusInit(int delayUs); void ChangeStatusShutdown(int delayUs); - DialogStatus ReadStatus() { + DialogStatus ReadStatus() const { return status; } @@ -117,10 +117,10 @@ protected: unsigned int lastButtons = 0; unsigned int buttons = 0; - float fadeTimer; - bool isFading; - bool fadeIn; - u32 fadeValue; + float fadeTimer = 0.0f; + bool isFading = false; + bool fadeIn = false; + u32 fadeValue = 0; ImageID okButtonImg; ImageID cancelButtonImg; diff --git a/Core/Dialog/PSPGamedataInstallDialog.h b/Core/Dialog/PSPGamedataInstallDialog.h index 3dfd8687ef..e669a31873 100644 --- a/Core/Dialog/PSPGamedataInstallDialog.h +++ b/Core/Dialog/PSPGamedataInstallDialog.h @@ -59,16 +59,16 @@ private: void CloseCurrentFile(); void WriteSfoFile(); - SceUtilityGamedataInstallParam request; + SceUtilityGamedataInstallParam request{}; PSPPointer param; std::vector inFileNames; - int numFiles; - int readFiles; - u64 allFilesSize; // use this to calculate progress value. - u64 allReadSize; // use this to calculate progress value. - int progressValue; + int numFiles = 0; + int readFiles = 0; + u64 allFilesSize = 0; // use this to calculate progress value. + u64 allReadSize = 0; // use this to calculate progress value. + int progressValue = 0; - int currentInputFile; - u32 currentInputBytesLeft; - int currentOutputFile; + int currentInputFile = 0; + u32 currentInputBytesLeft = 0; + int currentOutputFile = 0; }; diff --git a/Core/Dialog/PSPMsgDialog.h b/Core/Dialog/PSPMsgDialog.h index e5912d2ee3..78ee4e54f4 100644 --- a/Core/Dialog/PSPMsgDialog.h +++ b/Core/Dialog/PSPMsgDialog.h @@ -94,11 +94,11 @@ private: u32 flag = 0; - pspMessageDialog messageDialog; - int messageDialogAddr; + pspMessageDialog messageDialog{}; + int messageDialogAddr = 0; char msgText[512]; - int yesnoChoice; + int yesnoChoice = 0; float scrollPos_ = 0.0f; int framesUpHeld_ = 0; int framesDownHeld_ = 0; diff --git a/Core/Dialog/PSPOskDialog.h b/Core/Dialog/PSPOskDialog.h index 8eb55586c0..c760afb1e4 100644 --- a/Core/Dialog/PSPOskDialog.h +++ b/Core/Dialog/PSPOskDialog.h @@ -148,7 +148,6 @@ struct SceUtilityOskParams SceUtilityOskState_le state; // Maybe just padding? s32_le unk_60; - }; // Internal enum, not from PSP. @@ -245,16 +244,16 @@ private: std::string oskIntext; std::string oskOuttext; - int selectedChar; + int selectedChar = 0; std::u16string inputChars; OskKeyboardDisplay currentKeyboard; OskKeyboardLanguage currentKeyboardLanguage; - bool isCombinated; + bool isCombinated = false; std::mutex nativeMutex_; PSPOskNativeStatus nativeStatus_ = PSPOskNativeStatus::IDLE; std::string nativeValue_; - int i_level; // for Korean Keyboard support - int i_value[3]; // for Korean Keyboard support + int i_level = 0; // for Korean Keyboard support + int i_value[3]{}; // for Korean Keyboard support }; diff --git a/Core/Dialog/PSPSaveDialog.h b/Core/Dialog/PSPSaveDialog.h index 8058d8a962..90f8d6312a 100644 --- a/Core/Dialog/PSPSaveDialog.h +++ b/Core/Dialog/PSPSaveDialog.h @@ -139,13 +139,13 @@ private: DisplayState display = DS_NONE; SavedataParam param; - SceUtilitySavedataParam request; + SceUtilitySavedataParam request{}; // For detecting changes made by the game. - SceUtilitySavedataParam originalRequest; + SceUtilitySavedataParam originalRequest{}; u32 requestAddr = 0; int currentSelectedSave = 0; - int yesnoChoice; + int yesnoChoice = 0; enum SaveIOStatus { diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index f4ba47a20e..980a3edf31 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -193,16 +193,7 @@ void SaveFileInfo::DoState(PointerWrap &p) } } -SavedataParam::SavedataParam() - : pspParam(0) - , selectedSave(0) - , saveDataList(0) - , noSaveIcon(0) - , saveDataListCount(0) - , saveNameListDataCount(0) -{ - -} +SavedataParam::SavedataParam() { } void SavedataParam::Init() { diff --git a/Core/Dialog/SavedataParam.h b/Core/Dialog/SavedataParam.h index b7daa02845..e7bdf9ad46 100644 --- a/Core/Dialog/SavedataParam.h +++ b/Core/Dialog/SavedataParam.h @@ -265,7 +265,6 @@ struct SceUtilitySavedataParam // Function 22 GETSIZES PSPPointer sizeInfo; - }; // Non native, this one we can reorganize as we like @@ -377,10 +376,10 @@ private: std::set GetSecureFileNames(const std::string &dirPath); bool GetExpectedHash(const std::string &dirPath, const std::string &filename, u8 hash[16]); - SceUtilitySavedataParam* pspParam; - int selectedSave; - SaveFileInfo *saveDataList; - SaveFileInfo *noSaveIcon; - int saveDataListCount; - int saveNameListDataCount; + SceUtilitySavedataParam* pspParam = nullptr; + int selectedSave = 0; + SaveFileInfo *saveDataList = nullptr; + SaveFileInfo *noSaveIcon = nullptr; + int saveDataListCount = 0; + int saveNameListDataCount = 0; }; From 80e0bb9c1f8eb3f2abadc7f348992fc3331ebc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 1 Sep 2022 11:54:48 +0200 Subject: [PATCH 11/69] Remove a per-audio-frame allocation in sceAudio --- Core/HLE/__sceAudio.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Core/HLE/__sceAudio.cpp b/Core/HLE/__sceAudio.cpp index 9632d90e0b..3176d26130 100644 --- a/Core/HLE/__sceAudio.cpp +++ b/Core/HLE/__sceAudio.cpp @@ -64,8 +64,8 @@ int srcFrequency = 0; const int hwSampleRate = 44100; -int hwBlockSize = 64; -int hostAttemptBlockSize = 512; +const int hwBlockSize = 64; +const int hostAttemptBlockSize = 512; static int audioIntervalCycles; static int audioHostIntervalCycles; @@ -110,8 +110,6 @@ void __AudioInit() { chanQueueMaxSizeFactor = 2; chanQueueMinSizeFactor = 1; - hwBlockSize = 64; - hostAttemptBlockSize = 512; __AudioCPUMHzChange(); @@ -338,7 +336,8 @@ void __AudioUpdate(bool resetRecording) { // to the CPU. Much better to throttle the frame rate on frame display and just throw away audio // if the buffer somehow gets full. bool firstChannel = true; - std::vector srcBuffer; + const int16_t srcBufferSize = hwBlockSize * 2; + int16_t srcBuffer[srcBufferSize]; for (u32 i = 0; i < PSP_AUDIO_CHANNEL_MAX + 1; i++) { if (!chans[i].reserved) @@ -351,7 +350,7 @@ void __AudioUpdate(bool resetRecording) { } bool needsResample = i == PSP_AUDIO_CHANNEL_SRC && srcFrequency != 0 && srcFrequency != mixFrequency; - size_t sz = needsResample ? (hwBlockSize * 2 * srcFrequency) / mixFrequency : hwBlockSize * 2; + size_t sz = needsResample ? (srcBufferSize * srcFrequency) / mixFrequency : srcBufferSize; if (sz > chanSampleQueues[i].size()) { ERROR_LOG(SCEAUDIO, "Channel %i buffer underrun at %i of %i", i, (int)chanSampleQueues[i].size() / 2, (int)sz / 2); } @@ -372,13 +371,11 @@ void __AudioUpdate(bool resetRecording) { return buf1[sz1 - 1]; }; - srcBuffer.resize(hwBlockSize * 2); - // TODO: This is terrible, since it's doing it by small chunk and discarding frac. const uint32_t ratio = (uint32_t)(65536.0 * srcFrequency / (double)mixFrequency); uint32_t frac = 0; size_t readIndex = 0; - for (size_t outIndex = 0; readIndex < sz && outIndex < srcBuffer.size(); outIndex += 2) { + for (size_t outIndex = 0; readIndex < sz && outIndex < srcBufferSize; outIndex += 2) { size_t readIndex2 = readIndex + 2; int16_t l1 = read(readIndex); int16_t r1 = read(readIndex + 1); @@ -393,8 +390,8 @@ void __AudioUpdate(bool resetRecording) { frac &= 0xffff; } - buf1 = srcBuffer.data(); - sz1 = srcBuffer.size(); + buf1 = srcBuffer; + sz1 = srcBufferSize; buf2 = nullptr; sz2 = 0; } From 04a89950804623a9a4650e1b9fb4137b208cf11d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 22 Aug 2022 21:29:49 -0700 Subject: [PATCH 12/69] D3D11: Correct viewport offset sign handling. --- GPU/D3D11/DrawEngineD3D11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index 8715116b30..d4cb80738d 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -602,7 +602,7 @@ rotateVBO: int maxIndex = indexGen.MaxIndex(); SoftwareTransform swTransform(params); - const Lin::Vec3 trans(gstate_c.vpXOffset, gstate_c.vpYOffset, gstate_c.vpZOffset * 0.5f + 0.5f); + const Lin::Vec3 trans(gstate_c.vpXOffset, -gstate_c.vpYOffset, gstate_c.vpZOffset * 0.5f + 0.5f); const Lin::Vec3 scale(gstate_c.vpWidthScale, -gstate_c.vpHeightScale, gstate_c.vpDepthScale * 0.5f); swTransform.SetProjMatrix(gstate.projMatrix, gstate_c.vpWidth < 0, gstate_c.vpHeight < 0, trans, scale); From 79b864b89a8a656f43ae56ed2322f1161aec6385 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 22 Aug 2022 21:30:10 -0700 Subject: [PATCH 13/69] D3D9: Correct viewport offset sign. --- GPU/Directx9/DrawEngineDX9.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index 216bc7a8a0..154aa89b77 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -575,12 +575,10 @@ rotateVBO: SoftwareTransform swTransform(params); // Half pixel offset hack. - float xScale = gstate_c.vpWidth < 0 ? -1.0f : 1.0f; float xOffset = -1.0f / gstate_c.curRTRenderWidth; - float yScale = gstate_c.vpHeight > 0 ? -1.0f : 1.0f; float yOffset = 1.0f / gstate_c.curRTRenderHeight; - const Lin::Vec3 trans(gstate_c.vpXOffset * xScale + xOffset, gstate_c.vpYOffset * yScale + yOffset, gstate_c.vpZOffset * 0.5f + 0.5f); + const Lin::Vec3 trans(gstate_c.vpXOffset + xOffset, -gstate_c.vpYOffset + yOffset, gstate_c.vpZOffset * 0.5f + 0.5f); const Lin::Vec3 scale(gstate_c.vpWidthScale, gstate_c.vpHeightScale, gstate_c.vpDepthScale * 0.5f); swTransform.SetProjMatrix(gstate.projMatrix, gstate_c.vpWidth < 0, gstate_c.vpHeight > 0, trans, scale); From a5564c2ce252e917a57c06df069096f75d901194 Mon Sep 17 00:00:00 2001 From: iota97 Date: Fri, 29 Jul 2022 20:15:09 +0200 Subject: [PATCH 14/69] readme link --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 66485598b3..03df3bca66 100644 --- a/README.md +++ b/README.md @@ -512,4 +512,9 @@ Credit goes to: [#15687]: https://github.com/hrydgard/ppsspp/issues/15687 "Add Zettai Zetsumei Toshi 3" [#7295]: https://github.com/hrydgard/ppsspp/issues/7295 "Juiced 2: Hot Import Nights, screen artifacts and missing half of race tracks" [#15717]: https://github.com/hrydgard/ppsspp/issues/15717 "Allows \"merging\" render targets that overlap on the Y axis. Fixes Juiced 2" -[#15698]: https://github.com/hrydgard/ppsspp/issues/15698 "Osk: Allow upper/lower for all keyboards" \ No newline at end of file +[#15698]: https://github.com/hrydgard/ppsspp/issues/15698 "Osk: Allow upper/lower for all keyboards" +[#15738]: https://github.com/hrydgard/ppsspp/issues/15738 "Add confirmation dialog when generating a new Mac address" +[#15739]: https://github.com/hrydgard/ppsspp/issues/15739 "irjit: Correct another PurgeTemps case" +[#15740]: https://github.com/hrydgard/ppsspp/issues/15740 "Replacement: Clear cache on disable" +[#15734]: https://github.com/hrydgard/ppsspp/issues/15734 "Better pt-pt translation" +[#15733]: https://github.com/hrydgard/ppsspp/issues/15733 "Fix bug in blue-to-alpha - alpha blending could be on when it shouldn't be." From e56e5947d5d4cadad7e69f2f3c3dbfea5d95a15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 10 Sep 2022 00:26:23 +0200 Subject: [PATCH 15/69] Vulkan: Declare gl_Position as invariant. See #11583 The code that computes shader outputs declared as invariant gets certain optimizations disabled that could change the value - it makes it more likely that different ways to do the same calculations end up with the same value. This can help some types of Z fighting problems and similar. Generally not a big deal for performance, plus, we're rarely vshader-bottlenecked... --- GPU/Common/VertexShaderGenerator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index 071f1f4f5b..ccda9af86b 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -276,6 +276,9 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag // See the fragment shader generator WRITE(p, "layout (location = 3) out highp float v_fogdepth;\n"); } + + WRITE(p, "invariant gl_Position;\n"); + } else if (compat.shaderLanguage == HLSL_D3D11 || compat.shaderLanguage == HLSL_D3D9) { // Note: These two share some code after this hellishly large if/else. if (compat.shaderLanguage == HLSL_D3D11) { From d560c790198f0f5c502428d9edc2e1e106cb70fc Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Sat, 10 Sep 2022 01:54:13 +0000 Subject: [PATCH 16/69] Add Emulator to Categories in ppsspp.desktop.in Add the "Emulator" subcategory to the .desktop file so launchers can better auto-sort their contents. --- ppsspp.desktop.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ppsspp.desktop.in b/ppsspp.desktop.in index 49debf93c0..05fd1e7348 100644 --- a/ppsspp.desktop.in +++ b/ppsspp.desktop.in @@ -4,4 +4,4 @@ Exec=@TargetBin@ Icon=ppsspp Type=Application Comment=ppsspp (fast and portable PSP emulator) -Categories=Game +Categories=Game;Emulator From fbc02bdf1253f4977eff338050fbccdb5a70c2e0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 21 Aug 2022 00:27:31 -0700 Subject: [PATCH 17/69] softgpu: Correct morph weight updates. Broke LittleBigPlanet character's face, for example. --- GPU/Software/SoftGpu.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 6a4ddf88b7..502362104e 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -201,14 +201,14 @@ const SoftwareCommandTableEntry softgpuCommandTable[] = { { GE_CMD_CLUTFORMAT, 0, SoftDirty::SAMPLER_BASIC }, // Morph weights. TODO: Remove precomputation? - { GE_CMD_MORPHWEIGHT0, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, - { GE_CMD_MORPHWEIGHT1, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, - { GE_CMD_MORPHWEIGHT2, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, - { GE_CMD_MORPHWEIGHT3, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, - { GE_CMD_MORPHWEIGHT4, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, - { GE_CMD_MORPHWEIGHT5, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, - { GE_CMD_MORPHWEIGHT6, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, - { GE_CMD_MORPHWEIGHT7, 0, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT0, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT1, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT2, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT3, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT4, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT5, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT6, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, + { GE_CMD_MORPHWEIGHT7, FLAG_EXECUTEONCHANGE, SoftDirty::NONE, &GPUCommon::Execute_MorphWeight }, // No state of flushing required for patch parameters, currently. { GE_CMD_PATCHDIVISION }, From 38ba29240b4cff4fe075a9d0d11d4b12500fd987 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 20 Aug 2022 14:03:24 -0700 Subject: [PATCH 18/69] GPU: Dirty params when converting viewport state. This flag will be false when we convert next time, so parameters won't get updated as expected. --- GPU/D3D11/DrawEngineD3D11.cpp | 7 +++++++ GPU/Directx9/DrawEngineDX9.cpp | 7 +++++++ GPU/GLES/DrawEngineGLES.cpp | 7 +++++++ GPU/Vulkan/DrawEngineVulkan.cpp | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index d4cb80738d..73fc93f217 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -597,6 +597,13 @@ rotateVBO: framebufferManager_->GetRenderWidth(), framebufferManager_->GetRenderHeight(), framebufferManager_->GetTargetBufferWidth(), framebufferManager_->GetTargetBufferHeight(), vpAndScissor); + + if (vpAndScissor.dirtyProj) { + gstate_c.Dirty(DIRTY_PROJMATRIX); + } + if (vpAndScissor.dirtyDepth) { + gstate_c.Dirty(DIRTY_DEPTHRANGE); + } } int maxIndex = indexGen.MaxIndex(); diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index 154aa89b77..5fc0f29171 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -569,6 +569,13 @@ rotateVBO: framebufferManager_->GetRenderWidth(), framebufferManager_->GetRenderHeight(), framebufferManager_->GetTargetBufferWidth(), framebufferManager_->GetTargetBufferHeight(), vpAndScissor); + + if (vpAndScissor.dirtyProj) { + gstate_c.Dirty(DIRTY_PROJMATRIX); + } + if (vpAndScissor.dirtyDepth) { + gstate_c.Dirty(DIRTY_DEPTHRANGE); + } } int maxIndex = indexGen.MaxIndex(); diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index f8f7a2cbbc..7a06fd4c64 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -366,6 +366,13 @@ void DrawEngineGLES::DoFlush() { framebufferManager_->GetRenderWidth(), framebufferManager_->GetRenderHeight(), framebufferManager_->GetTargetBufferWidth(), framebufferManager_->GetTargetBufferHeight(), vpAndScissor); + + if (vpAndScissor.dirtyProj) { + gstate_c.Dirty(DIRTY_PROJMATRIX); + } + if (vpAndScissor.dirtyDepth) { + gstate_c.Dirty(DIRTY_DEPTHRANGE); + } } int maxIndex = indexGen.MaxIndex(); diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index 0c464853e6..5676980c7b 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -868,6 +868,13 @@ void DrawEngineVulkan::DoFlush() { framebufferManager_->GetRenderWidth(), framebufferManager_->GetRenderHeight(), framebufferManager_->GetTargetBufferWidth(), framebufferManager_->GetTargetBufferHeight(), vpAndScissor); + + if (vpAndScissor.dirtyProj) { + gstate_c.Dirty(DIRTY_PROJMATRIX); + } + if (vpAndScissor.dirtyDepth) { + gstate_c.Dirty(DIRTY_DEPTHRANGE); + } } int maxIndex = indexGen.MaxIndex(); From cc25ec5faa44fe91d4cf07aee2b56449d7e64b7c Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sat, 30 Jul 2022 20:50:56 +0000 Subject: [PATCH 19/69] CI: also upload release source tarball on tag push the mac os build action uses an action that automatically creates a release from a tag push, which circumvents triggering the regular release actions. also switch from the unmaintained actions/upload-release-asset@v1 to the active softprops/action-gh-release@v1 action. closes #15761 --- .github/workflows/tarball.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tarball.yml b/.github/workflows/tarball.yml index add0f685d8..d8c5fac636 100644 --- a/.github/workflows/tarball.yml +++ b/.github/workflows/tarball.yml @@ -5,6 +5,9 @@ on: release: types: - created + push: + tags: + - "v*.*.*" jobs: build: @@ -19,7 +22,9 @@ jobs: - name: archive id: archive run: | - VERSION=$(printf "%s\n" ${{ github.event.release.tag_name }} | sed 's/^v//') + VERSION=${GITHUB_REF##*/} + test -z "$VERSION" && VERSION=${{ github.event.release.tag_name }} + VERSION=$(printf "%s\n" "$VERSION" | sed 's/^v//') PKGNAME="ppsspp-$VERSION" mkdir -p /tmp/$PKGNAME mv * /tmp/$PKGNAME @@ -38,11 +43,7 @@ jobs: echo "::set-output name=tarball::$TARBALL" - name: upload tarball - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v1 with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ./${{ steps.archive.outputs.tarball }} - asset_name: ${{ steps.archive.outputs.tarball }} - asset_content_type: application/x-xz + files: ${{ steps.archive.outputs.tarball }} + token: ${{ secrets.GITHUB_TOKEN }} From d41b94d12d1a627002f153d3f5d6f3b146a2b55d Mon Sep 17 00:00:00 2001 From: rofl0r Date: Sun, 31 Jul 2022 04:41:19 +0000 Subject: [PATCH 20/69] CI: make indentation in tarball.yml consistent --- .github/workflows/tarball.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tarball.yml b/.github/workflows/tarball.yml index d8c5fac636..f7f625e3b4 100644 --- a/.github/workflows/tarball.yml +++ b/.github/workflows/tarball.yml @@ -45,5 +45,5 @@ jobs: - name: upload tarball uses: softprops/action-gh-release@v1 with: - files: ${{ steps.archive.outputs.tarball }} - token: ${{ secrets.GITHUB_TOKEN }} + files: ${{ steps.archive.outputs.tarball }} + token: ${{ secrets.GITHUB_TOKEN }} From 4090112bf80929c6ad22a711188e64742ba810dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 9 Sep 2022 11:16:25 +0200 Subject: [PATCH 21/69] Update README.md for v1.13.2 --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 03df3bca66..688da9568b 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,12 @@ If you want to download regularly updated builds for Android, Windows x86 and x6 For game compatibility, see [community compatibility feedback](https://report.ppsspp.org/games). +What's new in 1.13.2 +==================== +* Crashfix on Android 12 when playing certain background music ([#15990]) +* Fix Star Ocean battles in D3D backends (#[15889]) +* Minor fixes that might fix some other crashes + What's new in 1.13.1 ==================== @@ -518,3 +524,4 @@ Credit goes to: [#15740]: https://github.com/hrydgard/ppsspp/issues/15740 "Replacement: Clear cache on disable" [#15734]: https://github.com/hrydgard/ppsspp/issues/15734 "Better pt-pt translation" [#15733]: https://github.com/hrydgard/ppsspp/issues/15733 "Fix bug in blue-to-alpha - alpha blending could be on when it shouldn't be." +[#15990]: https://github.com/hrydgard/ppsspp/issues/15990 "Atrac3+: Allocate some extra bytes for the data buffer to workaround decoder bug." From 9fe6338e3bf397f8a009a51a282c139dfa180eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 10 Sep 2022 15:50:49 +0200 Subject: [PATCH 22/69] Update version to 1.13.2 --- android/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index fbb5332b0d..bee1ccda15 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -3,8 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" package="org.ppsspp.ppsspp" android:installLocation="auto" - android:versionCode="113010000" - android:versionName="1.13.1.0"> + android:versionCode="113020000" + android:versionName="1.13.2.0"> From 54fe342f4b0cfab29095b120f3f377704f0c4464 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 08:30:09 -0700 Subject: [PATCH 23/69] Vulkan: Wake compile thread when enqueued. Previously was being woken up every frame unconditionally, causing some logspam. --- Common/GPU/Vulkan/VulkanRenderManager.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 52f0b8fb27..10cc890009 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -553,6 +553,7 @@ void VulkanRenderManager::CompileThreadFunc() { void VulkanRenderManager::DrainCompileQueue() { std::unique_lock lock(compileMutex_); + compileCond_.notify_all(); while (!compileQueue_.empty()) { queueRunner_.WaitForCompileNotification(); } @@ -733,13 +734,17 @@ VKRGraphicsPipeline *VulkanRenderManager::CreateGraphicsPipeline(VKRGraphicsPipe }; VKRRenderPass *compatibleRenderPass = queueRunner_.GetRenderPass(key); compileMutex_.lock(); + bool needsCompile = false; for (int i = 0; i < RP_TYPE_COUNT; i++) { if (!(variantBitmask & (1 << i))) continue; RenderPassType rpType = (RenderPassType)i; pipeline->pipeline[rpType] = Promise::CreateEmpty(); compileQueue_.push_back(CompileQueueEntry(pipeline, compatibleRenderPass->Get(vulkan_, rpType), rpType)); + needsCompile = true; } + if (needsCompile) + compileCond_.notify_one(); compileMutex_.unlock(); } return pipeline; @@ -775,13 +780,16 @@ void VulkanRenderManager::EndCurRenderStep() { // Save the accumulated pipeline flags so we can use that to configure the render pass. // We'll often be able to avoid loading/saving the depth/stencil buffer. compileMutex_.lock(); + bool needsCompile = false; for (VKRGraphicsPipeline *pipeline : pipelinesToCheck_) { if (!pipeline->pipeline[rpType]) { pipeline->pipeline[rpType] = Promise::CreateEmpty(); compileQueue_.push_back(CompileQueueEntry(pipeline, renderPass->Get(vulkan_, rpType), rpType)); + needsCompile = true; } } - compileCond_.notify_one(); + if (needsCompile) + compileCond_.notify_one(); compileMutex_.unlock(); pipelinesToCheck_.clear(); From c200aa6f4b58f8ae33fd9e81167082b7fa34f377 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 08:52:50 -0700 Subject: [PATCH 24/69] GE Debugger: Correct cond break removal warnings. Oops, they were just always confirming. --- Windows/GEDebugger/TabState.cpp | 4 ++-- Windows/GEDebugger/TabVertices.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Windows/GEDebugger/TabState.cpp b/Windows/GEDebugger/TabState.cpp index da1baa10bf..200eb9ae75 100644 --- a/Windows/GEDebugger/TabState.cpp +++ b/Windows/GEDebugger/TabState.cpp @@ -910,7 +910,7 @@ void CtrlStateValues::OnDoubleClick(int row, int column) { if (column == STATEVALUES_COL_BREAKPOINT) { bool proceed = true; - if (IsCmdBreakpoint(info.cmd)) { + if (GetCmdBreakpointCond(info.cmd, nullptr)) { int ret = MessageBox(GetHandle(), L"This breakpoint has a custom condition.\nDo you want to remove it?", L"Confirmation", MB_YESNO); proceed = ret == IDYES; } @@ -993,7 +993,7 @@ void CtrlStateValues::OnRightClick(int row, int column, const POINT &point) { { case ID_DISASM_TOGGLEBREAKPOINT: { bool proceed = true; - if (IsCmdBreakpoint(info.cmd)) { + if (GetCmdBreakpointCond(info.cmd, nullptr)) { int ret = MessageBox(GetHandle(), L"This breakpoint has a custom condition.\nDo you want to remove it?", L"Confirmation", MB_YESNO); proceed = ret == IDYES; } diff --git a/Windows/GEDebugger/TabVertices.cpp b/Windows/GEDebugger/TabVertices.cpp index 9606672840..f7ab9af7ac 100644 --- a/Windows/GEDebugger/TabVertices.cpp +++ b/Windows/GEDebugger/TabVertices.cpp @@ -571,9 +571,11 @@ void CtrlMatrixList::ToggleBreakpoint(int row) { if (state) { GPUBreakpoints::AddCmdBreakpoint(info->cmd); } else { - int ret = MessageBox(GetHandle(), L"This breakpoint has a custom condition.\nDo you want to remove it?", L"Confirmation", MB_YESNO); - if (ret != IDYES) - return; + if (GPUBreakpoints::GetCmdBreakpointCond(info->cmd, nullptr)) { + int ret = MessageBox(GetHandle(), L"This breakpoint has a custom condition.\nDo you want to remove it?", L"Confirmation", MB_YESNO); + if (ret != IDYES) + return; + } GPUBreakpoints::RemoveCmdBreakpoint(info->cmd); } From a2ca85bc8723ec04c171dc8b308b3b69a43b227f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 10 Sep 2022 19:32:39 +0200 Subject: [PATCH 25/69] Add logging for LoadCLUT from framebuffer. See #15923 . Logs nicely in Burnout Dominator. --- GPU/Common/TextureCacheCommon.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 8d58346a8c..eaef9ea6da 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1177,6 +1177,7 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { // And is it inside the rendered area? Sometimes games pack data outside. bool matchRegion = ((offset / bpp) % framebuffer->fb_stride) < framebuffer->width; if (matchRange && matchRegion && offset < clutRenderOffset_) { + WARN_LOG_N_TIMES(clutfb, 5, G3D, "LoadCLUT(%d bytes) from framebuffer %08x (%s), byte offset %d", loadBytes, fb_address, GeBufferFormatToString(framebuffer->fb_format), offset); framebuffer->last_frame_clut = gpuStats.numFlips; framebuffer->usageFlags |= FB_USAGE_CLUT; clutRenderAddress_ = framebuffer->fb_address; From 6004d4a4596106056d1fbccfe00f66fa2348a2cb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 13:28:35 -0700 Subject: [PATCH 26/69] softgpu: Refactor duplicate rectangle compat check. This just moves the logic to a single place for changes. --- GPU/Software/RasterizerRectangle.cpp | 52 ++++++++++++---------------- GPU/Software/SoftGpu.cpp | 2 +- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index f25be97f64..7408b1558b 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -321,26 +321,32 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &b return false; } +static bool AreCoordsRectangleCompatible(const RasterizerState &state, const VertexData &data0, const VertexData &data1) { + if (!(data1.color0 == data0.color0)) + return false; + if (!(data1.screenpos.z == data0.screenpos.z)) { + // Sometimes, we don't actually care about z. + if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS) + return false; + } + if (!state.throughMode) { + if (!state.throughMode && !(data1.color1 == data0.color1)) + return false; + // Do we have to think about perspective correction or slope mip level? + if (state.enableTextures && data1.clippos.w != data0.clippos.w) + return false; + if (state.pixelID.applyFog && data1.fogdepth != data0.fogdepth) + return false; + } + return true; +} + bool DetectRectangleFromStrip(const RasterizerState &state, const VertexData data[4], int *tlIndex, int *brIndex) { // Color and Z must be flat. Also find the TL and BR meanwhile. int tl = 0, br = 0; for (int i = 1; i < 4; ++i) { - if (!(data[i].color0 == data[0].color0)) + if (!AreCoordsRectangleCompatible(state, data[i], data[0])) return false; - if (!(data[i].screenpos.z == data[0].screenpos.z)) { - // Sometimes, we don't actually care about z. - if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS) - return false; - } - if (!state.throughMode) { - if (!state.throughMode && !(data[i].color1 == data[0].color1)) - return false; - // Do we have to think about perspective correction or slope mip level? - if (state.enableTextures && data[i].clippos.w != data[0].clippos.w) - return false; - if (state.pixelID.applyFog && data[i].fogdepth != data[0].fogdepth) - return false; - } if (data[i].screenpos.x <= data[tl].screenpos.x && data[i].screenpos.y <= data[tl].screenpos.y) tl = i; @@ -394,22 +400,8 @@ bool DetectRectangleFromStrip(const RasterizerState &state, const VertexData dat bool DetectRectangleFromFan(const RasterizerState &state, const VertexData *data, int c, int *tlIndex, int *brIndex) { // Color and Z must be flat. for (int i = 1; i < c; ++i) { - if (!(data[i].color0 == data[0].color0)) + if (!AreCoordsRectangleCompatible(state, data[i], data[0])) return false; - if (!(data[i].screenpos.z == data[0].screenpos.z)) { - // Sometimes, we don't actually care about z. - if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS) - return false; - } - if (!state.throughMode) { - if (!state.throughMode && !(data[i].color1 == data[0].color1)) - return false; - // Do we have to think about perspective correction or slope mip level? - if (state.enableTextures && data[i].clippos.w != data[0].clippos.w) - return false; - if (state.pixelID.applyFog && data[i].fogdepth != data[0].fogdepth) - return false; - } } // Check for the common case: a single TL-TR-BR-BL. diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index a6fc160af3..18cdb0b314 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -838,7 +838,7 @@ void SoftGPU::Execute_Prim(u32 op, u32 diff) { return; } - const void *verts = Memory::GetPointer(gstate_c.vertexAddr); + const void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr); const void *indices = NULL; if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { if (!Memory::IsValidAddress(gstate_c.indexAddr)) { From e7d49cd7d0087fb9a423f3e16491f6f973c34f32 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 13:29:40 -0700 Subject: [PATCH 27/69] softgpu: Allow almost flat rectangles to go fast. Improves transform rectangles used in Chains of Olympus, for example on the title screen. --- GPU/Software/RasterizerRectangle.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index 7408b1558b..79162dc607 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -333,10 +333,18 @@ static bool AreCoordsRectangleCompatible(const RasterizerState &state, const Ver if (!state.throughMode && !(data1.color1 == data0.color1)) return false; // Do we have to think about perspective correction or slope mip level? - if (state.enableTextures && data1.clippos.w != data0.clippos.w) - return false; - if (state.pixelID.applyFog && data1.fogdepth != data0.fogdepth) - return false; + if (state.enableTextures && data1.clippos.w != data0.clippos.w) { + // If the w is off by less than a factor of 1/512, it should be safe to treat as a rectangle. + static constexpr float halftexel = 0.5f / 512.0f; + if (data1.clippos.w - halftexel > data0.clippos.w || data1.clippos.w + halftexel < data0.clippos.w) + return false; + } + if (state.pixelID.applyFog && data1.fogdepth != data0.fogdepth) { + // Similar to w, this only matters if they're farther apart than 1/255. + static constexpr float foghalfstep = 0.5f / 255.0f; + if (data1.fogdepth - foghalfstep > data0.fogdepth || data1.fogdepth + foghalfstep < data0.fogdepth) + return false; + } } return true; } From 2505ae28589c80d27ca3d7d3e04b9b5c4ce2ce7c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 13:36:01 -0700 Subject: [PATCH 28/69] GE Debugger: Fix logging of texture size. --- GPU/GeDisasm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/GeDisasm.cpp b/GPU/GeDisasm.cpp index b30218b44a..a645b5bc2b 100644 --- a/GPU/GeDisasm.cpp +++ b/GPU/GeDisasm.cpp @@ -605,7 +605,7 @@ void GeDisassembleOp(u32 pc, u32 op, u32 prev, char *buffer, int bufsize) { { int w = 1 << (data & 0xf); int h = 1 << ((data>>8) & 0xf); - if ((data & ~0x0F0F) && w <= 512 && h <= 512) + if ((data & ~0x0F0F) == 0 && w <= 512 && h <= 512) snprintf(buffer, bufsize, "Texture size %d: %dx%d", cmd - GE_CMD_TEXSIZE0, w, h); else snprintf(buffer, bufsize, "Texture size %d: %dx%d (extra %06x)", cmd - GE_CMD_TEXSIZE0, w, h, data); From 13ca08b2357e8dec7ffa79d04116dd842e623d1c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 14:56:13 -0700 Subject: [PATCH 29/69] softgpu: Avoid over-aggressive rect conversion. The TL and BR have to match between UVs and pos, not enough for UV to be in order. This was causing an artifact on Chains of Olympus' title. --- GPU/Software/RasterizerRectangle.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index 79162dc607..f3ba20840a 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -435,7 +435,9 @@ bool DetectRectangleFromFan(const RasterizerState &state, const VertexData *data if (textl.x == texbl.x && textr.x == texbr.x && textl.y == textr.y && texbl.y == texbr.y) { // Okay, the texture is also good, but let's avoid rotation issues. - return textl.y < texbr.y && textl.x < texbr.x; + const auto &postl = data[*tlIndex].screenpos; + const auto &posbr = data[*brIndex].screenpos; + return textl.y < texbr.y && postl.y < posbr.y && textl.x < texbr.x && postl.x < posbr.x; } } } From f5f5c9ea8775d5e73a163098e9df17cec2df6556 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 14:58:27 -0700 Subject: [PATCH 30/69] softgpu: Avoid calling unordered coords tl/br. These are just corners, we don't know if they're top or not at this point. --- GPU/Software/RasterizerRectangle.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index f3ba20840a..f30ae1c128 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -414,14 +414,14 @@ bool DetectRectangleFromFan(const RasterizerState &state, const VertexData *data // Check for the common case: a single TL-TR-BR-BL. if (c == 4) { - const auto &tl = data[0].screenpos, &tr = data[1].screenpos; - const auto &bl = data[3].screenpos, &br = data[2].screenpos; - if (tl.x == bl.x && tr.x == br.x && tl.y == tr.y && bl.y == br.y) { + const auto &pos0 = data[0].screenpos, &pos1 = data[1].screenpos; + const auto &pos2 = data[2].screenpos, &pos3 = data[3].screenpos; + if (pos0.x == pos3.x && pos1.x == pos2.x && pos0.y == pos1.y && pos3.y == pos2.y) { // Looking like yes. Set TL/BR based on y order first... - *tlIndex = tl.y > bl.y ? 2 : 0; - *brIndex = tl.y > bl.y ? 0 : 2; + *tlIndex = pos0.y > pos3.y ? 2 : 0; + *brIndex = pos0.y > pos3.y ? 0 : 2; // And if it's horizontally flipped, trade to the actual TL/BR. - if (tl.x > tr.x) { + if (pos0.x > pos1.x) { *tlIndex ^= 1; *brIndex ^= 1; } From 18c9a4d9c9d8eaa5166e160bb02c3f1fc4471643 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 19:31:53 -0700 Subject: [PATCH 31/69] GE Debugger: Fix crash stepping with large tex. Some math was overflowing in allocations, and it would allocate zero bytes. Let's just refuse textures more actively. --- GPU/Software/Rasterizer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index a387e3b943..4f230e1693 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -1401,7 +1401,11 @@ bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); - if (!texaddr || !Memory::IsValidRange(texaddr, (textureBitsPerPixel[texfmt] * texbufw * h) / 8)) + u32 sizeInBits = textureBitsPerPixel[texfmt] * (texbufw * (h - 1) + w); + if (!texaddr || !Memory::IsValidRange(texaddr, sizeInBits / 8)) + return false; + // We'll break trying to allocate this much. + if (w >= 0x8000 && h >= 0x8000) return false; buffer.Allocate(w, h, GE_FORMAT_8888, false); From 100cbec620fffec435143ac11e49b340589968cb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 19:44:44 -0700 Subject: [PATCH 32/69] GE Debugger: Fix crash on bp before list running. --- GPU/Debugger/Breakpoints.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GPU/Debugger/Breakpoints.cpp b/GPU/Debugger/Breakpoints.cpp index 8d76cbd5e7..225b25799d 100644 --- a/GPU/Debugger/Breakpoints.cpp +++ b/GPU/Debugger/Breakpoints.cpp @@ -29,6 +29,9 @@ namespace GPUBreakpoints { +static void NothingToDo(bool) { +} + struct BreakpointInfo { bool isConditional = false; PostfixExpression expression; @@ -45,7 +48,7 @@ static std::set breakRenderTargets; static size_t breakPCsCount = 0; static size_t breakTexturesCount = 0; static size_t breakRenderTargetsCount = 0; -static std::function notifyBreakpoints; +static std::function notifyBreakpoints = &NothingToDo; // If these are set, the above are also, but they should be temporary. static bool breakCmdsTemp[256]; From 6c6d817ce75377731346232bf7fee08ba398c327 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 20:14:37 -0700 Subject: [PATCH 33/69] Vulkan: Avoid crash if large texture attempted. Doesn't do the clamp/wrap thing, but at least this won't crash. --- Common/GPU/Vulkan/VulkanImage.cpp | 4 ++++ GPU/Vulkan/TextureCacheVulkan.cpp | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanImage.cpp b/Common/GPU/Vulkan/VulkanImage.cpp index c013f5d9ee..72eb339c12 100644 --- a/Common/GPU/Vulkan/VulkanImage.cpp +++ b/Common/GPU/Vulkan/VulkanImage.cpp @@ -36,6 +36,10 @@ bool VulkanTexture::CreateDirect(VkCommandBuffer cmd, int w, int h, int depth, i ERROR_LOG(G3D, "Can't create a zero-size VulkanTexture"); return false; } + if (w > 4096 || h > 4096) { + ERROR_LOG(G3D, "Can't create a texture this large"); + return false; + } Wipe(); diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index d11e92ba05..2800627593 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -389,13 +389,12 @@ void TextureCacheVulkan::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutB } void TextureCacheVulkan::BindTexture(TexCacheEntry *entry) { - if (!entry) { + if (!entry || !entry->vkTex) { imageView_ = VK_NULL_HANDLE; curSampler_ = VK_NULL_HANDLE; return; } - _dbg_assert_(entry->vkTex); entry->vkTex->Touch(); int maxLevel = (entry->status & TexCacheEntry::STATUS_NO_MIPS) ? 0 : entry->maxLevel; From 3242bb8d6688e7eb7071976653afebc1df97e22c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 20:15:43 -0700 Subject: [PATCH 34/69] TexCache: Allow valid bufw sizes. These don't cause crashes anymore. --- GPU/Common/TextureCacheCommon.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index eaef9ea6da..7e42991ee6 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -2271,12 +2271,6 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt // For the estimate, we assume cluts always point to 8888 for simplicity. cacheSizeEstimate_ += EstimateTexMemoryUsage(entry); - if ((entry->bufw == 0 || (gstate.texbufwidth[0] & 0xf800) != 0) && entry->addr >= PSP_GetKernelMemoryEnd()) { - ERROR_LOG_REPORT(G3D, "Texture with unexpected bufw (full=%d)", gstate.texbufwidth[0] & 0xffff); - // Proceeding here can cause a crash. - return false; - } - plan.badMipSizes = false; // maxLevel here is the max level to upload. Not the count. plan.levelsToLoad = entry->maxLevel + 1; From 1056301c95d3bbcaa94eb5c0f5cd383838a1b645 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 20:16:05 -0700 Subject: [PATCH 35/69] D3D11: Prevent crash on larger textures. --- GPU/D3D11/TextureCacheD3D11.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 2563825ea1..750c7427c5 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -300,6 +300,10 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) { int tw; int th; plan.GetMipSize(0, &tw, &th); + if (tw > 16384) + tw = 16384; + if (th > 16384) + th = 16384; if (plan.depth == 1) { // We don't yet have mip generation, so clamp the number of levels to the ones we can load directly. From 123d6dbb1160e46698898f2c39de1cac4d1414d3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 20:17:54 -0700 Subject: [PATCH 36/69] GE Debugger: Correct confusing block transfer size. --- Windows/GEDebugger/TabState.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Windows/GEDebugger/TabState.cpp b/Windows/GEDebugger/TabState.cpp index 200eb9ae75..63a7199ed6 100644 --- a/Windows/GEDebugger/TabState.cpp +++ b/Windows/GEDebugger/TabState.cpp @@ -63,6 +63,7 @@ enum CmdFormatType { CMD_FMT_XY, CMD_FMT_XYXY, CMD_FMT_XYZ, + CMD_FMT_XYPLUS1, CMD_FMT_TEXSIZE, CMD_FMT_F16_XY, CMD_FMT_VERTEXTYPE, @@ -233,7 +234,7 @@ static const TabStateRow stateSettingsRows[] = { { L"Transfer src pos", GE_CMD_TRANSFERSRCPOS, CMD_FMT_XY }, { L"Transfer dst", GE_CMD_TRANSFERDST, CMD_FMT_PTRWIDTH, 0, GE_CMD_TRANSFERDSTW }, { L"Transfer dst pos", GE_CMD_TRANSFERDSTPOS, CMD_FMT_XY }, - { L"Transfer size", GE_CMD_TRANSFERSIZE, CMD_FMT_XY }, + { L"Transfer size", GE_CMD_TRANSFERSIZE, CMD_FMT_XYPLUS1 }, { L"Vertex type", GE_CMD_VERTEXTYPE, CMD_FMT_VERTEXTYPE }, { L"Offset addr", GE_CMD_OFFSETADDR, CMD_FMT_OFFSETADDR }, { L"Vertex addr", GE_CMD_VADDR, CMD_FMT_VADDR }, @@ -376,6 +377,14 @@ void FormatStateRow(wchar_t *dest, const TabStateRow &info, u32 value, bool enab } break; + case CMD_FMT_XYPLUS1: + { + int x = value & 0x3FF; + int y = value >> 10; + swprintf(dest, 255, L"%d,%d", x + 1, y + 1); + } + break; + case CMD_FMT_XYXY: { int x1 = value & 0x3FF; From 90e009edb9c1cdfb53d8b2e1382244ae19857862 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 19:33:02 -0700 Subject: [PATCH 37/69] softgpu: Clamp/wrap textures at 512 pixels. A texture larger than 512 is "valid", but simply wraps/clamps at 512. Importantly, the texture coords are still calculated at the specified size, which can be up to 32768. --- GPU/Software/RasterizerRectangle.cpp | 4 ++++ GPU/Software/Sampler.cpp | 4 +++- GPU/Software/Sampler.h | 1 + GPU/Software/SamplerX86.cpp | 12 ++++++++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index f25be97f64..877b298ef9 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -265,6 +265,10 @@ bool g_needsClearAfterDialog = false; static inline bool NoClampOrWrap(const RasterizerState &state, const Vec2f &tc) { if (tc.x < 0 || tc.y < 0) return false; + if (state.samplerID.cached.sizes[0].w > 512 || state.samplerID.cached.sizes[0].h > 512) + return false; + if (!state.throughMode) + return tc.x <= 1.0f && tc.y <= 1.0f; return tc.x <= state.samplerID.cached.sizes[0].w && tc.y <= state.samplerID.cached.sizes[0].h; } diff --git a/GPU/Software/Sampler.cpp b/GPU/Software/Sampler.cpp index 8aad116b14..8c55e15760 100644 --- a/GPU/Software/Sampler.cpp +++ b/GPU/Software/Sampler.cpp @@ -383,13 +383,15 @@ inline static Nearest4 SOFTRAST_CALL SampleNearest(const int u[N], const int v[N static inline int ClampUV(int v, int height) { if (v >= height - 1) return height - 1; + if (v >= 511) + return 511; else if (v < 0) return 0; return v; } static inline int WrapUV(int v, int height) { - return v & (height - 1); + return v & (height - 1) & 511; } template diff --git a/GPU/Software/Sampler.h b/GPU/Software/Sampler.h index e663004cbf..2379c5edfb 100644 --- a/GPU/Software/Sampler.h +++ b/GPU/Software/Sampler.h @@ -114,6 +114,7 @@ private: const u8 *constVNext_ = nullptr; const u8 *constOnes32_ = nullptr; const u8 *constOnes16_ = nullptr; + const u8 *constMaxTexel32_ = nullptr; const u8 *const10All16_ = nullptr; const u8 *const10Low_ = nullptr; const u8 *const10All8_ = nullptr; diff --git a/GPU/Software/SamplerX86.cpp b/GPU/Software/SamplerX86.cpp index 415eed2723..932c6d1a62 100644 --- a/GPU/Software/SamplerX86.cpp +++ b/GPU/Software/SamplerX86.cpp @@ -903,6 +903,8 @@ void SamplerJitCache::WriteConstantPool(const SamplerID &id) { WriteSimpleConst4x32(constOnes32_, 1); WriteSimpleConst8x16(constOnes16_, 1); + // This is the mask for clamp or wrap, the max texel in the S or T direction. + WriteSimpleConst4x32(constMaxTexel32_, 511); if (constUNext_ == nullptr) { constUNext_ = AlignCode16(); @@ -927,8 +929,8 @@ void SamplerJitCache::WriteConstantPool(const SamplerID &id) { Write32(*(uint32_t *)&w256f); Write32(*(uint32_t *)&h256f); - WriteDynamicConst4x32(constWidthMinus1i_, (1 << id.width0Shift) - 1); - WriteDynamicConst4x32(constHeightMinus1i_, (1 << id.height0Shift) - 1); + WriteDynamicConst4x32(constWidthMinus1i_, id.width0Shift > 9 ? 511 : (1 << id.width0Shift) - 1); + WriteDynamicConst4x32(constHeightMinus1i_, id.height0Shift > 9 ? 511 : (1 << id.height0Shift) - 1); } else { constWidthHeight256f_ = nullptr; constWidthMinus1i_ = nullptr; @@ -2651,6 +2653,7 @@ bool SamplerJitCache::Jit_GetTexelCoords(const SamplerID &id) { } SUB(32, R(tempReg), Imm8(1)); + AND(32, R(tempReg), Imm32(0x000001FF)); if (clamp) { CMP(32, R(dest), R(tempReg)); CMOVcc(32, dest, R(tempReg), CC_G); @@ -2710,6 +2713,10 @@ bool SamplerJitCache::Jit_GetTexelCoords(const SamplerID &id) { AND(32, R(uReg), R(uReg)); auto applyClampWrap = [this](X64Reg dest, bool clamp, uint8_t shift) { + // Clamp and wrap both max out at 512. + if (shift > 9) + shift = 9; + if (clamp) { X64Reg tempReg = regCache_.Alloc(RegCache::GEN_TEMP0); MOV(32, R(tempReg), Imm32((1 << shift) - 1)); @@ -2802,6 +2809,7 @@ bool SamplerJitCache::Jit_GetTexelCoordsQuad(const SamplerID &id) { // For wrap/clamp purposes, we want width or height minus one. Do that now. PSUBD(sizesReg, M(constOnes32_)); + PAND(sizesReg, M(constMaxTexel32_)); } else { // Easy mode. UNPCKLPS(sReg, R(tReg)); From 15d5fa48f79af980a7c589d359f163fc699d2acd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 21:22:13 -0700 Subject: [PATCH 38/69] softgpu: Check depth test early on simple stencil. If we don't need to write stencil on sfail/zfail, we can do the depthtest early, which allows us to more often skip texture sampling. This gives a good improvement in Chains of Olympus. --- GPU/Software/DrawPixel.cpp | 10 ++-- GPU/Software/DrawPixel.h | 2 + GPU/Software/DrawPixelX86.cpp | 10 ++-- GPU/Software/FuncId.cpp | 7 +++ GPU/Software/FuncId.h | 3 +- GPU/Software/Rasterizer.cpp | 95 +++++++++++++++++++++++++++++------ 6 files changed, 104 insertions(+), 23 deletions(-) diff --git a/GPU/Software/DrawPixel.cpp b/GPU/Software/DrawPixel.cpp index 3585c9a3ff..ab244aacf8 100644 --- a/GPU/Software/DrawPixel.cpp +++ b/GPU/Software/DrawPixel.cpp @@ -325,6 +325,10 @@ static inline bool DepthTestPassed(GEComparison func, int x, int y, int stride, } } +bool CheckDepthTestPassed(GEComparison func, int x, int y, int stride, u16 z) { + return DepthTestPassed(func, x, y, stride, z); +} + static inline u32 ApplyLogicOp(GELogicOp op, u32 old_color, u32 new_color) { // All of the operations here intentionally preserve alpha/stencil. switch (op) { @@ -400,7 +404,7 @@ template void SOFTRAST_CALL DrawSinglePixel(int x, int y, int z, int fog, Vec4IntArg color_in, const PixelFuncID &pixelID) { Vec4 prim_color = Vec4(color_in).Clamp(0, 255); // Depth range test - applied in clear mode, if not through mode. - if (pixelID.applyDepthRange) + if (pixelID.applyDepthRange && !pixelID.earlyZChecks) if (z < pixelID.cached.minz || z > pixelID.cached.maxz) return; @@ -436,14 +440,14 @@ void SOFTRAST_CALL DrawSinglePixel(int x, int y, int z, int fog, Vec4IntArg colo } // Also apply depth at the same time. If disabled, same as passing. - if (pixelID.DepthTestFunc() != GE_COMP_ALWAYS && !DepthTestPassed(pixelID.DepthTestFunc(), x, y, pixelID.cached.depthbufStride, z)) { + if (!pixelID.earlyZChecks && pixelID.DepthTestFunc() != GE_COMP_ALWAYS && !DepthTestPassed(pixelID.DepthTestFunc(), x, y, pixelID.cached.depthbufStride, z)) { stencil = ApplyStencilOp(fbFormat, stencilReplace, pixelID.ZFail(), stencil); SetPixelStencil(fbFormat, pixelID.cached.framebufStride, targetWriteMask, x, y, stencil); return; } stencil = ApplyStencilOp(fbFormat, stencilReplace, pixelID.ZPass(), stencil); - } else { + } else if (!pixelID.earlyZChecks) { if (pixelID.DepthTestFunc() != GE_COMP_ALWAYS && !DepthTestPassed(pixelID.DepthTestFunc(), x, y, pixelID.cached.depthbufStride, z)) { return; } diff --git a/GPU/Software/DrawPixel.h b/GPU/Software/DrawPixel.h index b1063d59a1..982ee27765 100644 --- a/GPU/Software/DrawPixel.h +++ b/GPU/Software/DrawPixel.h @@ -41,6 +41,8 @@ SingleFunc GetSingleFunc(const PixelFuncID &id); void Init(); void Shutdown(); +bool CheckDepthTestPassed(GEComparison func, int x, int y, int stride, u16 z); + bool DescribeCodePtr(const u8 *ptr, std::string &name); struct PixelBlendState { diff --git a/GPU/Software/DrawPixelX86.cpp b/GPU/Software/DrawPixelX86.cpp index 536f1efb02..8f006bece4 100644 --- a/GPU/Software/DrawPixelX86.cpp +++ b/GPU/Software/DrawPixelX86.cpp @@ -149,7 +149,7 @@ RegCache::Reg PixelJitCache::GetColorOff(const PixelFuncID &id) { if (!regCache_.Has(RegCache::GEN_COLOR_OFF)) { Describe("GetColorOff"); if (id.useStandardStride && !id.dithering) { - bool loadDepthOff = id.depthWrite || id.DepthTestFunc() != GE_COMP_ALWAYS; + bool loadDepthOff = id.depthWrite || (id.DepthTestFunc() != GE_COMP_ALWAYS && !id.earlyZChecks); X64Reg depthTemp = INVALID_REG; X64Reg argYReg = regCache_.Find(RegCache::GEN_ARG_Y); X64Reg argXReg = regCache_.Find(RegCache::GEN_ARG_X); @@ -345,7 +345,7 @@ void PixelJitCache::WriteConstantPool(const PixelFuncID &id) { } bool PixelJitCache::Jit_ApplyDepthRange(const PixelFuncID &id) { - if (id.applyDepthRange) { + if (id.applyDepthRange && !id.earlyZChecks) { Describe("ApplyDepthR"); X64Reg argZReg = regCache_.Find(RegCache::GEN_ARG_Z); X64Reg idReg = GetPixelID(); @@ -365,7 +365,7 @@ bool PixelJitCache::Jit_ApplyDepthRange(const PixelFuncID &id) { // Since this is early on, try to free up the z reg if we don't need it anymore. if (id.clearMode && !id.DepthClear()) regCache_.ForceRelease(RegCache::GEN_ARG_Z); - else if (!id.clearMode && !id.depthWrite && id.DepthTestFunc() == GE_COMP_ALWAYS) + else if (!id.clearMode && !id.depthWrite && (id.DepthTestFunc() == GE_COMP_ALWAYS || id.earlyZChecks)) regCache_.ForceRelease(RegCache::GEN_ARG_Z); return true; @@ -721,7 +721,7 @@ bool PixelJitCache::Jit_StencilTest(const PixelFuncID &id, RegCache::Reg stencil } bool PixelJitCache::Jit_DepthTestForStencil(const PixelFuncID &id, RegCache::Reg stencilReg) { - if (id.DepthTestFunc() == GE_COMP_ALWAYS) + if (id.DepthTestFunc() == GE_COMP_ALWAYS || id.earlyZChecks) return true; X64Reg depthOffReg = GetDepthOff(id); @@ -964,7 +964,7 @@ bool PixelJitCache::Jit_WriteStencilOnly(const PixelFuncID &id, RegCache::Reg st } bool PixelJitCache::Jit_DepthTest(const PixelFuncID &id) { - if (id.DepthTestFunc() == GE_COMP_ALWAYS) + if (id.DepthTestFunc() == GE_COMP_ALWAYS || id.earlyZChecks) return true; if (id.DepthTestFunc() == GE_COMP_NEVER) { diff --git a/GPU/Software/FuncId.cpp b/GPU/Software/FuncId.cpp index 084c897829..0471114caa 100644 --- a/GPU/Software/FuncId.cpp +++ b/GPU/Software/FuncId.cpp @@ -163,6 +163,13 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) { id->applyLogicOp = gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_COPY; id->applyFog = gstate.isFogEnabled() && !throughMode; + + id->earlyZChecks = id->DepthTestFunc() != GE_COMP_ALWAYS; + if (id->stencilTest && id->earlyZChecks) { + // Can't do them early if stencil might need to write. + if (id->SFail() != GE_STENCILOP_KEEP || id->ZFail() != GE_STENCILOP_KEEP) + id->earlyZChecks = false; + } } // Cache some values for later convenience. diff --git a/GPU/Software/FuncId.h b/GPU/Software/FuncId.h index 72207ebd5a..46307fc55c 100644 --- a/GPU/Software/FuncId.h +++ b/GPU/Software/FuncId.h @@ -107,7 +107,8 @@ struct PixelFuncID { uint8_t sFail : 3; uint8_t zFail : 3; uint8_t zPass : 3; - // 60 bits, 4 free. + bool earlyZChecks : 1; + // 61 bits, 3 free. }; }; diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index a387e3b943..c534d37792 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -710,6 +710,11 @@ void DrawTriangleSlice( const bool flatColor1 = flatColorAll || (v0.color1 == v1.color1 && v0.color1 == v2.color1); const bool noFog = clearMode || !pixelID.applyFog || (v0.fogdepth >= 1.0f && v1.fogdepth >= 1.0f && v2.fogdepth >= 1.0f); + if (pixelID.applyDepthRange && flatZ) { + if (v0.screenpos.z < pixelID.cached.minz || v0.screenpos.z > pixelID.cached.maxz) + return; + } + #if defined(SOFTGPU_MEMORY_TAGGING_DETAILED) || defined(SOFTGPU_MEMORY_TAGGING_BASIC) uint32_t bpp = pixelID.FBFormat() == GE_FORMAT_8888 ? 4 : 2; std::string tag = StringFromFormat("DisplayListT_%08x", state.listPC); @@ -754,6 +759,32 @@ void DrawTriangleSlice( if (AnyMask(mask)) { Vec4 wsum_recip = EdgeRecip(w0, w1, w2); + Vec4 z; + if (flatZ) { + z = Vec4::AssignToAll(v2.screenpos.z); + } else { + // Z is interpolated pretty much directly. + Vec4 zfloats = w0.Cast() * v0.screenpos.z + w1.Cast() * v1.screenpos.z + w2.Cast() * v2.screenpos.z; + z = (zfloats * wsum_recip).Cast(); + } + + if (pixelID.earlyZChecks) { + for (int i = 0; i < 4; ++i) { + if (pixelID.applyDepthRange) { + if (z[i] < pixelID.cached.minz || z[i] > pixelID.cached.maxz) + mask[i] = -1; + } + if (mask[i] < 0) + continue; + + int x = p.x + (i & 1); + int y = p.y + (i / 2); + if (!CheckDepthTestPassed(pixelID.DepthTestFunc(), x, y, pixelID.cached.depthbufStride, z[i])) { + mask[i] = -1; + } + } + } + // Color interpolation is not perspective corrected on the PSP. Vec4 prim_color[4]; if (!flatColor0) { @@ -816,15 +847,6 @@ void DrawTriangleSlice( } } - Vec4 z; - if (flatZ) { - z = Vec4::AssignToAll(v2.screenpos.z); - } else { - // Z is interpolated pretty much directly. - Vec4 zfloats = w0.Cast() * v0.screenpos.z + w1.Cast() * v1.screenpos.z + w2.Cast() * v2.screenpos.z; - z = (zfloats * wsum_recip).Cast(); - } - PROFILE_THIS_SCOPE("draw_tri_px"); DrawingCoords subp = p; for (int i = 0; i < 4; ++i) { @@ -947,6 +969,12 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords & Vec4 z = Vec4::AssignToAll(v1.screenpos.z); Vec3 sec_color = v1.color1; + if (state.pixelID.applyDepthRange) { + // We can bail early since the Z is flat. + if (v1.screenpos.z < state.pixelID.cached.minz || v1.screenpos.z > state.pixelID.cached.maxz) + return; + } + #if defined(SOFTGPU_MEMORY_TAGGING_DETAILED) || defined(SOFTGPU_MEMORY_TAGGING_BASIC) uint32_t bpp = state.pixelID.FBFormat() == GE_FORMAT_8888 ? 4 : 2; std::string tag = StringFromFormat("DisplayListR_%08x", state.listPC); @@ -972,6 +1000,19 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords & prim_color[i] = v1.color0; } + if (state.pixelID.earlyZChecks) { + for (int i = 0; i < 4; ++i) { + if (mask[i] < 0) + continue; + + int x = p.x + (i & 1); + int y = p.y + (i / 2); + if (!CheckDepthTestPassed(state.pixelID.DepthTestFunc(), x, y, state.pixelID.cached.depthbufStride, z[i])) { + mask[i] = -1; + } + } + } + if (state.enableTextures) { Vec4 s, t; s = Vec4::AssignToAll(st.s()) + sto4; @@ -1038,6 +1079,20 @@ void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerSta auto &pixelID = state.pixelID; auto &samplerID = state.samplerID; + DrawingCoords p = TransformUnit::ScreenToDrawing(pos); + u16 z = pos.z; + + if (pixelID.earlyZChecks) { + if (pixelID.applyDepthRange) { + if (z < pixelID.cached.minz || z > pixelID.cached.maxz) + return; + } + + if (!CheckDepthTestPassed(pixelID.DepthTestFunc(), p.x, p.y, pixelID.cached.depthbufStride, z)) { + return; + } + } + if (state.enableTextures) { float s = v0.texturecoords.s(); float t = v0.texturecoords.t(); @@ -1060,9 +1115,6 @@ void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerSta if (!pixelID.clearMode) prim_color += Vec4(sec_color, 0); - DrawingCoords p = TransformUnit::ScreenToDrawing(pos); - u16 z = pos.z; - u8 fog = 255; if (pixelID.applyFog) { fog = ClampFogDepth(v0.fogdepth); @@ -1302,7 +1354,23 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range double z = a.z; const int steps1 = steps == 0 ? 1 : steps; for (int i = 0; i < steps; i++) { - if (x >= range.x1 && y >= range.y1 && x <= range.x2 && y <= range.y2) { + DrawingCoords p = TransformUnit::ScreenToDrawing(x, y); + + bool maskOK = x >= range.x1 && y >= range.y1 && x <= range.x2 && y <= range.y2; + if (maskOK) { + if (pixelID.earlyZChecks) { + if (pixelID.applyDepthRange) { + if (z < pixelID.cached.minz || z > pixelID.cached.maxz) + maskOK = false; + } + + if (!CheckDepthTestPassed(pixelID.DepthTestFunc(), x, y, pixelID.cached.depthbufStride, z)) { + maskOK = false; + } + } + } + + if (maskOK) { // Interpolate between the two points. Vec4 prim_color; Vec3 sec_color; @@ -1368,7 +1436,6 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range prim_color += Vec4(sec_color, 0); PROFILE_THIS_SCOPE("draw_px"); - DrawingCoords p = TransformUnit::ScreenToDrawing(x, y); state.drawPixel(p.x, p.y, z, fog, ToVec4IntArg(prim_color), pixelID); #if defined(SOFTGPU_MEMORY_TAGGING_DETAILED) || defined(SOFTGPU_MEMORY_TAGGING_BASIC) From 4889d5285d422cfb6ce12b7f09b9f271649ed80e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 2 Feb 2022 22:10:32 -0800 Subject: [PATCH 39/69] vertexjit: Use consistent skinInDecode. Just a little cleanup. --- GPU/Common/VertexDecoderArm.cpp | 2 +- GPU/Common/VertexDecoderArm64.cpp | 2 +- GPU/Common/VertexDecoderCommon.cpp | 2 +- GPU/Common/VertexDecoderCommon.h | 1 + GPU/Common/VertexDecoderX86.cpp | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/GPU/Common/VertexDecoderArm.cpp b/GPU/Common/VertexDecoderArm.cpp index c2f6ae46fd..e3d5b11f6b 100644 --- a/GPU/Common/VertexDecoderArm.cpp +++ b/GPU/Common/VertexDecoderArm.cpp @@ -204,7 +204,7 @@ JittedVertexDecoder VertexDecoderJitCache::Compile(const VertexDecoder &dec, int // Add code to convert matrices to 4x4. // Later we might want to do this when the matrices are loaded instead. - if (dec.weighttype && g_Config.bSoftwareSkinning) { + if (dec.skinInDecode) { // Copying from R3 to R4 MOVP2R(R3, gstate.boneMatrix); MOVP2R(R4, bones); diff --git a/GPU/Common/VertexDecoderArm64.cpp b/GPU/Common/VertexDecoderArm64.cpp index 32cc5bc291..5ff1d605f3 100644 --- a/GPU/Common/VertexDecoderArm64.cpp +++ b/GPU/Common/VertexDecoderArm64.cpp @@ -190,7 +190,7 @@ JittedVertexDecoder VertexDecoderJitCache::Compile(const VertexDecoder &dec, int // Add code to convert matrices to 4x4. // Later we might want to do this when the matrices are loaded instead. - if (dec.weighttype && g_Config.bSoftwareSkinning) { + if (dec.skinInDecode) { // Copying from R3 to R4 MOVP2R(X3, gstate.boneMatrix); MOVP2R(X4, bones); diff --git a/GPU/Common/VertexDecoderCommon.cpp b/GPU/Common/VertexDecoderCommon.cpp index 6ac9806c01..a9b4a1039a 100644 --- a/GPU/Common/VertexDecoderCommon.cpp +++ b/GPU/Common/VertexDecoderCommon.cpp @@ -1083,7 +1083,7 @@ void VertexDecoder::SetVertexType(u32 fmt, const VertexDecoderOptions &options, DEBUG_LOG(G3D, "VTYPE: THRU=%i TC=%i COL=%i POS=%i NRM=%i WT=%i NW=%i IDX=%i MC=%i", (int)throughmode, tc, col, pos, nrm, weighttype, nweights, idx, morphcount); } - bool skinInDecode = weighttype != 0 && g_Config.bSoftwareSkinning; + skinInDecode = weighttype != 0 && g_Config.bSoftwareSkinning; if (weighttype) { // && nweights? weightoff = size; diff --git a/GPU/Common/VertexDecoderCommon.h b/GPU/Common/VertexDecoderCommon.h index 5ec55ebe4c..983f76f9b2 100644 --- a/GPU/Common/VertexDecoderCommon.h +++ b/GPU/Common/VertexDecoderCommon.h @@ -458,6 +458,7 @@ public: DecVtxFormat decFmt; bool throughmode; + bool skinInDecode; u8 size; u8 onesize_; diff --git a/GPU/Common/VertexDecoderX86.cpp b/GPU/Common/VertexDecoderX86.cpp index 611bf56c21..d684078989 100644 --- a/GPU/Common/VertexDecoderX86.cpp +++ b/GPU/Common/VertexDecoderX86.cpp @@ -219,7 +219,7 @@ JittedVertexDecoder VertexDecoderJitCache::Compile(const VertexDecoder &dec, int // Add code to convert matrices to 4x4. // Later we might want to do this when the matrices are loaded instead. - if (dec.weighttype && g_Config.bSoftwareSkinning) { + if (dec.skinInDecode) { MOV(PTRBITS, R(tempReg1), ImmPtr(&threeMasks)); MOVAPS(XMM4, MatR(tempReg1)); MOV(PTRBITS, R(tempReg1), ImmPtr(&aOne)); From 33a93e238ae42ea8fcfb040518676b01da9388f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 10:26:01 +0200 Subject: [PATCH 40/69] CLUT download: Replace the broken block transfer check with a new compat flag. This compat flag should be temporary until we've implemented a readback-free path for CLUTs from framebuffers, both when texturing from static textures and other framebuffers. --- Core/Compatibility.cpp | 1 + Core/Compatibility.h | 1 + GPU/Common/TextureCacheCommon.cpp | 9 ++++++--- assets/compat.ini | 3 +++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Core/Compatibility.cpp b/Core/Compatibility.cpp index 11233bf1bb..c9bb3428a8 100644 --- a/Core/Compatibility.cpp +++ b/Core/Compatibility.cpp @@ -98,6 +98,7 @@ void Compatibility::CheckSettings(IniFile &iniFile, const std::string &gameID) { CheckSetting(iniFile, gameID, "DeswizzleDepth", &flags_.DeswizzleDepth); CheckSetting(iniFile, gameID, "SplitFramebufferMargin", &flags_.SplitFramebufferMargin); CheckSetting(iniFile, gameID, "ForceLowerResolutionForEffectsOn", &flags_.ForceLowerResolutionForEffectsOn); + CheckSetting(iniFile, gameID, "AllowDownloadCLUT", &flags_.AllowDownloadCLUT); } void Compatibility::CheckSetting(IniFile &iniFile, const std::string &gameID, const char *option, bool *flag) { diff --git a/Core/Compatibility.h b/Core/Compatibility.h index 9b1dfa5fd7..060ee3c268 100644 --- a/Core/Compatibility.h +++ b/Core/Compatibility.h @@ -88,6 +88,7 @@ struct CompatFlags { bool DeswizzleDepth; bool SplitFramebufferMargin; bool ForceLowerResolutionForEffectsOn; + bool AllowDownloadCLUT; }; class IniFile; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index eaef9ea6da..b5abfbde59 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1177,7 +1177,7 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { // And is it inside the rendered area? Sometimes games pack data outside. bool matchRegion = ((offset / bpp) % framebuffer->fb_stride) < framebuffer->width; if (matchRange && matchRegion && offset < clutRenderOffset_) { - WARN_LOG_N_TIMES(clutfb, 5, G3D, "LoadCLUT(%d bytes) from framebuffer %08x (%s), byte offset %d", loadBytes, fb_address, GeBufferFormatToString(framebuffer->fb_format), offset); + WARN_LOG_N_TIMES(clutfb, 5, G3D, "Detected LoadCLUT(%d bytes) from framebuffer %08x (%s), byte offset %d", loadBytes, fb_address, GeBufferFormatToString(framebuffer->fb_format), offset); framebuffer->last_frame_clut = gpuStats.numFlips; framebuffer->usageFlags |= FB_USAGE_CLUT; clutRenderAddress_ = framebuffer->fb_address; @@ -1191,15 +1191,18 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { NotifyMemInfo(MemBlockFlags::ALLOC, clutAddr, loadBytes, "CLUT"); } - // It's possible for a game to (successfully) access outside valid memory. + // It's possible for a game to load CLUT outside valid memory without crashing, should result in zeroes. u32 bytes = Memory::ValidSize(clutAddr, loadBytes); - if (clutRenderAddress_ != 0xFFFFFFFF && !g_Config.bBlockTransferGPU) { + if (clutRenderAddress_ != 0xFFFFFFFF && PSP_CoreParameter().compat.flags().AllowDownloadCLUT) { framebufferManager_->DownloadFramebufferForClut(clutRenderAddress_, clutRenderOffset_ + bytes); Memory::MemcpyUnchecked(clutBufRaw_, clutAddr, bytes); if (bytes < loadBytes) { memset((u8 *)clutBufRaw_ + bytes, 0x00, loadBytes - bytes); } } else { + // Here we could check for clutRenderAddres_ != 0xFFFFFFFF and zero the CLUT or something, + // but choosing not to for now. Though the results of loading the CLUT from RAM here is + // almost certainly going to be bogus. #ifdef _M_SSE if (bytes == loadBytes) { const __m128i *source = (const __m128i *)Memory::GetPointerUnchecked(clutAddr); diff --git a/assets/compat.ini b/assets/compat.ini index 976edb0959..63a4f168f7 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -1294,3 +1294,6 @@ ULES01301 = true ULES00262 = true ULUS10064 = true ULKS46087 = true + +[AllowDownloadCLUT] +# Temporary compatibility option, while developing a GPU CLUT-from-framebuffer path. From 5e6b06483511fd247bba57ccf437d775b3262ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 10:30:43 +0200 Subject: [PATCH 41/69] DownloadFramebufferForCLUT: Apply the fix mentioned in #8590 --- GPU/Common/FramebufferManagerCommon.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index 3cbe6543f0..e4ecfb4192 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -2552,6 +2552,11 @@ void FramebufferManagerCommon::DownloadFramebufferForClut(u32 fb_address, u32 lo int w = std::min(pixels % vfb->fb_stride, (int)vfb->width); int h = std::min((pixels + vfb->fb_stride - 1) / vfb->fb_stride, (int)vfb->height); + if (w == 0 || h > 1) { + // Exactly aligned, or more than one row. + w = std::min(vfb->fb_stride, vfb->width); + } + // We might still have a pending draw to the fb in question, flush if so. FlushBeforeCopy(); From 9bd8b11bf8a5019b74e03cbb75b9366ca1af7e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 13:27:17 +0200 Subject: [PATCH 42/69] Implement shader depal for D3D11. --- Common/GPU/ShaderWriter.cpp | 35 +++++++++++++++ Common/GPU/ShaderWriter.h | 2 + GPU/Common/FragmentShaderGenerator.cpp | 62 ++++++++++++++------------ GPU/Common/TextureCacheCommon.cpp | 1 - GPU/D3D11/D3D11Util.cpp | 5 ++- GPU/D3D11/TextureCacheD3D11.cpp | 5 ++- GPU/GLES/ShaderManagerGLES.cpp | 14 +++--- 7 files changed, 84 insertions(+), 40 deletions(-) diff --git a/Common/GPU/ShaderWriter.cpp b/Common/GPU/ShaderWriter.cpp index 0332e4d346..62d5760408 100644 --- a/Common/GPU/ShaderWriter.cpp +++ b/Common/GPU/ShaderWriter.cpp @@ -24,6 +24,7 @@ const char * const hlsl_preamble_fs = "#define vec4 float4\n" "#define uvec3 uint3\n" "#define uvec4 uint4\n" +"#define ivec2 int2\n" "#define ivec3 int3\n" "#define ivec4 int4\n" "#define mat4 float4x4\n" @@ -424,6 +425,40 @@ ShaderWriter &ShaderWriter::SampleTexture2D(const char *sampName, const char *uv return *this; } +ShaderWriter &ShaderWriter::SampleTexture2DOffset(const char *sampName, const char *uv, int offX, int offY) { + switch (lang_.shaderLanguage) { + case HLSL_D3D11: + F("%s.Sample(%sSamp, %s, int2(%d, %d))", sampName, sampName, uv, offX, offY); + break; + case HLSL_D3D9: + // Not supported, we do a normal sample here to not crash or something + F("tex2D(%s, %s)", sampName, uv); + break; + default: + // Note: we ignore the sampler. make sure you bound samplers to the textures correctly. + F("%sOffset(%s, %s, ivec2(%d, %d))", lang_.texture, sampName, uv, offX, offY); + break; + } + return *this; +} + +ShaderWriter &ShaderWriter::LoadTexture2D(const char *sampName, const char *uv, int level) { + switch (lang_.shaderLanguage) { + case HLSL_D3D11: + F("%s.Load(ivec3(%s, %d))", sampName, uv, level); + break; + case HLSL_D3D9: + // Not supported, we return a bad value + C("float4(1.0, 0.0, 1.0, 1.0)"); + break; + default: + // Note: we ignore the sampler. make sure you bound samplers to the textures correctly. + F("texelFetch(%s, %s, %d)", lang_.texture, sampName, uv, level); + break; + } + return *this; +} + ShaderWriter &ShaderWriter::GetTextureSize(const char *szVariable, const char *texName) { switch (lang_.shaderLanguage) { case HLSL_D3D11: diff --git a/Common/GPU/ShaderWriter.h b/Common/GPU/ShaderWriter.h index 7464ebc652..f6a04c828b 100644 --- a/Common/GPU/ShaderWriter.h +++ b/Common/GPU/ShaderWriter.h @@ -78,6 +78,8 @@ public: void ConstFloat(const char *name, float value); ShaderWriter &SampleTexture2D(const char *texName, const char *uv); + ShaderWriter &SampleTexture2DOffset(const char *texName, const char *uv, int offX, int offY); + ShaderWriter &LoadTexture2D(const char *texName, const char *integer_uv, int level); ShaderWriter &GetTextureSize(const char *szVariable, const char *texName); // Simple shaders with no special tricks. diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index db1d886b1f..feec43ff75 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -221,7 +221,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, "float u_mipBias : register(c%i);\n", CONST_PS_MIPBIAS); } } else { - WRITE(p, "SamplerState samp : register(s0);\n"); + WRITE(p, "SamplerState texSamp : register(s0);\n"); if (texture3D) { WRITE(p, "Texture3D tex : register(t0);\n"); } else { @@ -231,6 +231,12 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu // No sampler required, we Load WRITE(p, "Texture2D fbotex : register(t1);\n"); } + + if (shaderDepal) { + WRITE(p, "SamplerState palSamp : register(s3);\n"); + WRITE(p, "Texture2D pal : register(t3);\n"); + } + WRITE(p, "cbuffer base : register(b0) {\n%s};\n", ub_baseStr); if (shaderDepal) { @@ -561,15 +567,15 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu if (compat.shaderLanguage == HLSL_D3D11) { if (texture3D) { if (doTextureProjection) { - WRITE(p, " vec4 t = tex.Sample(samp, vec3(v_texcoord.xy / v_texcoord.z, u_mipBias))%s;\n", bgraTexture ? ".bgra" : ""); + WRITE(p, " vec4 t = tex.Sample(texSamp, vec3(v_texcoord.xy / v_texcoord.z, u_mipBias))%s;\n", bgraTexture ? ".bgra" : ""); } else { - WRITE(p, " vec4 t = tex.Sample(samp, vec3(%s.xy, u_mipBias))%s;\n", texcoord, bgraTexture ? ".bgra" : ""); + WRITE(p, " vec4 t = tex.Sample(texSamp, vec3(%s.xy, u_mipBias))%s;\n", texcoord, bgraTexture ? ".bgra" : ""); } } else { if (doTextureProjection) { - WRITE(p, " vec4 t = tex.Sample(samp, v_texcoord.xy / v_texcoord.z)%s;\n", bgraTexture ? ".bgra" : ""); + WRITE(p, " vec4 t = tex.Sample(texSamp, v_texcoord.xy / v_texcoord.z)%s;\n", bgraTexture ? ".bgra" : ""); } else { - WRITE(p, " vec4 t = tex.Sample(samp, %s.xy)%s;\n", texcoord, bgraTexture ? ".bgra" : ""); + WRITE(p, " vec4 t = tex.Sample(texSamp, %s.xy)%s;\n", texcoord, bgraTexture ? ".bgra" : ""); } } } else if (compat.shaderLanguage == HLSL_D3D9) { @@ -608,28 +614,28 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu if (doTextureProjection) { // We don't use textureProj because we need better control and it's probably not much of a savings anyway. // However it is good for precision on older hardware like PowerVR. - WRITE(p, " vec2 uv = %s.xy/%s.z;\n vec2 uv_round;\n", texcoord, texcoord); + p.F(" vec2 uv = %s.xy/%s.z;\n vec2 uv_round;\n", texcoord, texcoord); } else { - WRITE(p, " vec2 uv = %s.xy;\n vec2 uv_round;\n", texcoord); + p.F(" vec2 uv = %s.xy;\n vec2 uv_round;\n", texcoord); } // Restrictions on this are checked before setting the smoothed flag. // Only RGB565 and RGBA5551 are supported, and only the specific shifts hitting the // channels directly. // Also, since we know the CLUT is smooth, we do not need to do the bilinear filter manually, we can just // lookup with the filtered value once. - WRITE(p, " vec4 t = %s(tex, %s.xy);\n", compat.texture, texcoord); - WRITE(p, " uint depalShift = (u_depal_mask_shift_off_fmt >> 8) & 0xFFU;\n"); - WRITE(p, " uint depalFmt = (u_depal_mask_shift_off_fmt >> 24) & 0x3U;\n"); - WRITE(p, " float index0 = t.r;\n"); - WRITE(p, " float factor = 31.0 / 256.0;\n"); - WRITE(p, " if (depalFmt == 0u) {\n"); // yes, different versions of Test Drive use different formats. Could do compile time by adding more compat flags but meh. - WRITE(p, " if (depalShift == 5u) { index0 = t.g; factor = 63.0 / 256.0; }\n"); - WRITE(p, " else if (depalShift == 11u) { index0 = t.b; }\n"); - WRITE(p, " } else {\n"); - WRITE(p, " if (depalShift == 5u) { index0 = t.g; }\n"); - WRITE(p, " else if (depalShift == 10u) { index0 = t.b; }\n"); - WRITE(p, " }\n"); - WRITE(p, " t = %s(pal, vec2(index0 * factor, 0.0));\n", compat.texture); + p.F(" vec4 t = ").SampleTexture2D("tex", "uv").C(";\n"); + p.C(" uint depalShift = (u_depal_mask_shift_off_fmt >> 8) & 0xFFU;\n"); + p.C(" uint depalFmt = (u_depal_mask_shift_off_fmt >> 24) & 0x3U;\n"); + p.C(" float index0 = t.r;\n"); + p.C(" float factor = 31.0 / 256.0;\n"); + p.C(" if (depalFmt == 0u) {\n"); // yes, different versions of Test Drive use different formats. Could do compile time by adding more compat flags but meh. + p.C(" if (depalShift == 5u) { index0 = t.g; factor = 63.0 / 256.0; }\n"); + p.C(" else if (depalShift == 11u) { index0 = t.b; }\n"); + p.C(" } else {\n"); + p.C(" if (depalShift == 5u) { index0 = t.g; }\n"); + p.C(" else if (depalShift == 10u) { index0 = t.b; }\n"); + p.C(" }\n"); + p.F(" t = ").SampleTexture2D("pal", "vec2(index0 * factor, 0.0)").C(";\n"); } else { if (doTextureProjection) { // We don't use textureProj because we need better control and it's probably not much of a savings anyway. @@ -648,10 +654,10 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, " } else {\n"); WRITE(p, " uv_round = uv;\n"); WRITE(p, " }\n"); - WRITE(p, " highp vec4 t = %s(tex, uv_round);\n", compat.texture); - WRITE(p, " highp vec4 t1 = %sOffset(tex, uv_round, ivec2(1, 0));\n", compat.texture); - WRITE(p, " highp vec4 t2 = %sOffset(tex, uv_round, ivec2(0, 1));\n", compat.texture); - WRITE(p, " highp vec4 t3 = %sOffset(tex, uv_round, ivec2(1, 1));\n", compat.texture); + p.C(" highp vec4 t = ").SampleTexture2D("tex", "uv_round").C(";\n"); + p.C(" highp vec4 t1 = ").SampleTexture2DOffset("tex", "uv_round", 1, 0).C(";\n"); + p.C(" highp vec4 t2 = ").SampleTexture2DOffset("tex", "uv_round", 0, 1).C(";\n"); + p.C(" highp vec4 t3 = ").SampleTexture2DOffset("tex", "uv_round", 1, 1).C(";\n"); WRITE(p, " uint depalMask = (u_depal_mask_shift_off_fmt & 0xFFU);\n"); WRITE(p, " uint depalShift = (u_depal_mask_shift_off_fmt >> 8) & 0xFFU;\n"); WRITE(p, " uint depalOffset = ((u_depal_mask_shift_off_fmt >> 16) & 0xFFU) << 4;\n"); @@ -708,14 +714,14 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, " break;\n"); WRITE(p, " };\n"); WRITE(p, " index0 = ((index0 >> depalShift) & depalMask) | depalOffset;\n"); - WRITE(p, " t = texelFetch(pal, ivec2(index0, 0), 0);\n"); + p.C(" t = ").LoadTexture2D("pal", "ivec2(index0, 0)", 0).C(";\n"); WRITE(p, " if (bilinear && !(index0 == index1 && index1 == index2 && index2 == index3)) {\n"); WRITE(p, " index1 = ((index1 >> depalShift) & depalMask) | depalOffset;\n"); WRITE(p, " index2 = ((index2 >> depalShift) & depalMask) | depalOffset;\n"); WRITE(p, " index3 = ((index3 >> depalShift) & depalMask) | depalOffset;\n"); - WRITE(p, " t1 = texelFetch(pal, ivec2(index1, 0), 0);\n"); - WRITE(p, " t2 = texelFetch(pal, ivec2(index2, 0), 0);\n"); - WRITE(p, " t3 = texelFetch(pal, ivec2(index3, 0), 0);\n"); + p.C(" t1 = ").LoadTexture2D("pal", "ivec2(index1, 0)", 0).C(";\n"); + p.C(" t2 = ").LoadTexture2D("pal", "ivec2(index2, 0)", 0).C(";\n"); + p.C(" t3 = ").LoadTexture2D("pal", "ivec2(index3, 0)", 0).C(";\n"); WRITE(p, " t = mix(t, t1, fraction.x);\n"); WRITE(p, " t2 = mix(t2, t3, fraction.x);\n"); WRITE(p, " t = mix(t, t2, fraction.y);\n"); diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index b5abfbde59..cefc86f4c5 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1924,7 +1924,6 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer // TODO: Implement shader depal in the fragment shader generator for D3D11 at least. switch (draw_->GetShaderLanguageDesc().shaderLanguage) { - case ShaderLanguage::HLSL_D3D11: case ShaderLanguage::HLSL_D3D9: useShaderDepal = false; break; diff --git a/GPU/D3D11/D3D11Util.cpp b/GPU/D3D11/D3D11Util.cpp index d8a68c5f14..9fd4c64a48 100644 --- a/GPU/D3D11/D3D11Util.cpp +++ b/GPU/D3D11/D3D11Util.cpp @@ -26,13 +26,14 @@ std::vector CompileShaderToBytecodeD3D11(const char *code, size_t codeS std::string errors; if (errorMsgs) { errors = std::string((const char *)errorMsgs->GetBufferPointer(), errorMsgs->GetBufferSize()); + std::string numberedCode = LineNumberString(code); if (SUCCEEDED(result)) { WARN_LOG(G3D, "%s: %s", "warnings", errors.c_str()); } else { - ERROR_LOG(G3D, "%s: %s", "errors", errors.c_str()); + ERROR_LOG(G3D, "%s: %s\n\n%s", "errors", errors.c_str(), numberedCode.c_str()); } - OutputDebugStringA(LineNumberString(code).c_str()); OutputDebugStringA(errors.c_str()); + OutputDebugStringA(numberedCode.c_str()); errorMsgs->Release(); } if (compiledCode) { diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index 2563825ea1..c656f3d7dd 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -180,8 +180,8 @@ void TextureCacheD3D11::ReleaseTexture(TexCacheEntry *entry, bool delete_them) { void TextureCacheD3D11::ForgetLastTexture() { InvalidateLastTexture(); - ID3D11ShaderResourceView *nullTex[2]{}; - context_->PSSetShaderResources(0, 2, nullTex); + ID3D11ShaderResourceView *nullTex[4]{}; + context_->PSSetShaderResources(0, 4, nullTex); } void TextureCacheD3D11::InvalidateLastTexture() { @@ -258,6 +258,7 @@ void TextureCacheD3D11::BindTexture(TexCacheEntry *entry) { SamplerCacheKey samplerKey = GetSamplingParams(maxLevel, entry); ID3D11SamplerState *state = samplerCache_.GetOrCreateSampler(device_, samplerKey); context_->PSSetSamplers(0, 1, &state); + gstate_c.SetUseShaderDepal(false, false); } void TextureCacheD3D11::ApplySamplingParams(const SamplerCacheKey &key) { diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index 2780fa7799..69bd1384ca 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -184,13 +184,13 @@ LinkedShader::LinkedShader(GLRenderManager *render, VShaderID VSID, Shader *vs, availableUniforms = vs->GetUniformMask() | fs->GetUniformMask(); std::vector initialize; - initialize.push_back({ &u_tex, 0, 0 }); - initialize.push_back({ &u_fbotex, 0, 1 }); - initialize.push_back({ &u_testtex, 0, 2 }); - initialize.push_back({ &u_pal, 0, 3 }); // CLUT - initialize.push_back({ &u_tess_points, 0, 4 }); // Control Points - initialize.push_back({ &u_tess_weights_u, 0, 5 }); - initialize.push_back({ &u_tess_weights_v, 0, 6 }); + initialize.push_back({ &u_tex, 0, TEX_SLOT_PSP_TEXTURE }); + initialize.push_back({ &u_fbotex, 0, TEX_SLOT_SHADERBLEND_SRC }); + initialize.push_back({ &u_testtex, 0, TEX_SLOT_ALPHATEST }); + initialize.push_back({ &u_pal, 0, TEX_SLOT_CLUT }); // CLUT + initialize.push_back({ &u_tess_points, 0, TEX_SLOT_SPLINE_POINTS }); // Control Points + initialize.push_back({ &u_tess_weights_u, 0, TEX_SLOT_SPLINE_WEIGHTS_U }); + initialize.push_back({ &u_tess_weights_v, 0, TEX_SLOT_SPLINE_WEIGHTS_V }); bool useDualSource = (gstate_c.featureFlags & GPU_SUPPORTS_DUALSOURCE_BLEND) != 0; bool useClip0 = VSID.Bit(VS_BIT_VERTEX_RANGE_CULLING) && gstate_c.Supports(GPU_SUPPORTS_CLIP_DISTANCE); From 694dbe1271085155433ef2ddf52d7305dc8a8bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 14:14:18 +0200 Subject: [PATCH 43/69] Add ShaderDepalMode enum, use in shader ID. Replaces smoothed bit. --- GPU/Common/FragmentShaderGenerator.cpp | 36 ++++++++++++++++---------- GPU/Common/ShaderId.cpp | 16 +++++++----- GPU/Common/ShaderId.h | 7 +++-- GPU/Common/TextureCacheCommon.cpp | 6 ++--- GPU/D3D11/TextureCacheD3D11.cpp | 2 +- GPU/GLES/TextureCacheGLES.cpp | 2 +- GPU/GPU.h | 7 +++++ GPU/GPUState.h | 10 +++---- GPU/Vulkan/ShaderManagerVulkan.cpp | 2 +- GPU/Vulkan/TextureCacheVulkan.cpp | 2 +- unittest/TestShaderGenerators.cpp | 1 - 11 files changed, 53 insertions(+), 38 deletions(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index feec43ff75..d1aabac698 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -92,8 +92,11 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu bool flatBug = bugs.Has(Draw::Bugs::BROKEN_FLAT_IN_SHADER) && g_Config.bVendorBugChecksEnabled; bool doFlatShading = id.Bit(FS_BIT_FLATSHADE) && !flatBug; - bool shaderDepal = id.Bit(FS_BIT_SHADER_DEPAL) && !texture3D; // combination with texture3D not supported. Enforced elsewhere too. - bool smoothedDepal = id.Bit(FS_BIT_SHADER_SMOOTHED_DEPAL); + ShaderDepalMode shaderDepalMode = (ShaderDepalMode)id.Bits(FS_BIT_SHADER_DEPAL_MODE, 2); + if (texture3D) { + shaderDepalMode = ShaderDepalMode::OFF; + } + bool bgraTexture = id.Bit(FS_BIT_BGRA_TEXTURE); bool colorWriteMask = id.Bit(FS_BIT_COLOR_WRITEMASK) && compat.bitwiseOps; @@ -134,7 +137,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu bool needFragCoord = readFramebuffer || gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT); bool writeDepth = gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT); - if (shaderDepal && !doTexture) { + if (shaderDepalMode != ShaderDepalMode::OFF && !doTexture) { *errorString = "depal requires a texture"; return false; } @@ -153,7 +156,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, "layout (binding = 1) uniform sampler2D fbotex;\n"); } - if (shaderDepal) { + if (shaderDepalMode != ShaderDepalMode::OFF) { WRITE(p, "layout (binding = 2) uniform sampler2D pal;\n"); } @@ -232,16 +235,13 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, "Texture2D fbotex : register(t1);\n"); } - if (shaderDepal) { + if (shaderDepalMode != ShaderDepalMode::OFF) { WRITE(p, "SamplerState palSamp : register(s3);\n"); WRITE(p, "Texture2D pal : register(t3);\n"); + WRITE(p, "float2 textureSize(Texture2D tex, int mip) { float2 size; tex.GetDimensions(size.x, size.y); return size; }\n"); } WRITE(p, "cbuffer base : register(b0) {\n%s};\n", ub_baseStr); - - if (shaderDepal) { - WRITE(p, "float2 textureSize(Texture2D tex, int mip) { float2 size; tex.GetDimensions(size.x, size.y); return size; }\n"); - } } if (enableAlphaTest) { @@ -302,7 +302,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, "};\n"); } } else if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) { - if ((shaderDepal || colorWriteMask) && gl_extensions.IsGLES) { + if ((shaderDepalMode != ShaderDepalMode::OFF || colorWriteMask) && gl_extensions.IsGLES) { WRITE(p, "precision highp int;\n"); } @@ -353,7 +353,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu } } - if (shaderDepal) { + if (shaderDepalMode != ShaderDepalMode::OFF) { WRITE(p, "uniform sampler2D pal;\n"); WRITE(p, "uniform uint u_depal_mask_shift_off_fmt;\n"); *uniformMask |= DIRTY_DEPAL; @@ -563,7 +563,8 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu doTextureProjection = false; } - if (!shaderDepal) { + switch (shaderDepalMode) { + case ShaderDepalMode::OFF: if (compat.shaderLanguage == HLSL_D3D11) { if (texture3D) { if (doTextureProjection) { @@ -609,7 +610,8 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu } } } - } else if (shaderDepal && smoothedDepal) { + break; + case ShaderDepalMode::SMOOTHED: // Specific mode for Test Drive. Fixes the banding. if (doTextureProjection) { // We don't use textureProj because we need better control and it's probably not much of a savings anyway. @@ -636,7 +638,8 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu p.C(" else if (depalShift == 10u) { index0 = t.b; }\n"); p.C(" }\n"); p.F(" t = ").SampleTexture2D("pal", "vec2(index0 * factor, 0.0)").C(";\n"); - } else { + break; + case ShaderDepalMode::NORMAL: if (doTextureProjection) { // We don't use textureProj because we need better control and it's probably not much of a savings anyway. // However it is good for precision on older hardware like PowerVR. @@ -726,6 +729,11 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, " t2 = mix(t2, t3, fraction.x);\n"); WRITE(p, " t = mix(t, t2, fraction.y);\n"); WRITE(p, " }\n"); + break; + case ShaderDepalMode::CLUT8_8888: + // Not yet implemented. + WRITE(p, " t = vec4(0.0, 0.0, 0.0, 0.0);\n"); + break; } if (texFunc != GE_TEXFUNC_REPLACE || !doTextureAlpha) diff --git a/GPU/Common/ShaderId.cpp b/GPU/Common/ShaderId.cpp index d05cc3a986..f873024c39 100644 --- a/GPU/Common/ShaderId.cpp +++ b/GPU/Common/ShaderId.cpp @@ -180,8 +180,12 @@ std::string FragmentShaderDesc(const FShaderID &id) { if (id.Bit(FS_BIT_COLOR_DOUBLE)) desc << "2x "; if (id.Bit(FS_BIT_FLATSHADE)) desc << "Flat "; if (id.Bit(FS_BIT_BGRA_TEXTURE)) desc << "BGRA "; - if (id.Bit(FS_BIT_SHADER_DEPAL)) desc << "Depal "; - if (id.Bit(FS_BIT_SHADER_SMOOTHED_DEPAL)) desc << "SmoothDepal "; + switch ((ShaderDepalMode)id.Bit(FS_BIT_SHADER_DEPAL_MODE)) { + case ShaderDepalMode::OFF: break; + case ShaderDepalMode::NORMAL: desc << "Depal "; break; + case ShaderDepalMode::SMOOTHED: desc << "SmoothDepal "; break; + case ShaderDepalMode::CLUT8_8888: desc << "CLUT8From8888Depal"; break; + } if (id.Bit(FS_BIT_COLOR_WRITEMASK)) desc << "WriteMask "; if (id.Bit(FS_BIT_SHADER_TEX_CLAMP)) { desc << "TClamp"; @@ -261,8 +265,9 @@ void ComputeFragmentShaderID(FShaderID *id_out, const ComputedPipelineState &pip bool doTextureProjection = (gstate.getUVGenMode() == GE_TEXMAP_TEXTURE_MATRIX && MatrixNeedsProjection(gstate.tgenMatrix)); bool doTextureAlpha = gstate.isTextureAlphaUsed(); bool doFlatShading = gstate.getShadeMode() == GE_SHADE_FLAT; - bool useShaderDepal = gstate_c.useShaderDepal; - bool useSmoothedDepal = gstate_c.useSmoothedShaderDepal; + + ShaderDepalMode shaderDepalMode = gstate_c.shaderDepalMode; + bool colorWriteMask = pipelineState.maskState.applyFramebufferRead; ReplaceBlendType replaceBlend = pipelineState.blendState.replaceBlend; @@ -289,8 +294,7 @@ void ComputeFragmentShaderID(FShaderID *id_out, const ComputedPipelineState &pip id.SetBit(FS_BIT_TEXTURE_AT_OFFSET, textureAtOffset); } id.SetBit(FS_BIT_BGRA_TEXTURE, gstate_c.bgraTexture); - id.SetBit(FS_BIT_SHADER_DEPAL, useShaderDepal); - id.SetBit(FS_BIT_SHADER_SMOOTHED_DEPAL, useSmoothedDepal); + id.SetBits(FS_BIT_SHADER_DEPAL_MODE, 2, (int)shaderDepalMode); id.SetBit(FS_BIT_3D_TEXTURE, gstate_c.curTextureIs3D); } diff --git a/GPU/Common/ShaderId.h b/GPU/Common/ShaderId.h index bd54e2bd82..999faf2e44 100644 --- a/GPU/Common/ShaderId.h +++ b/GPU/Common/ShaderId.h @@ -66,7 +66,7 @@ enum FShaderBit : uint8_t { FS_BIT_DO_TEXTURE = 1, FS_BIT_TEXFUNC = 2, // 3 bits FS_BIT_TEXALPHA = 5, - FS_BIT_SHADER_DEPAL = 6, + FS_BIT_3D_TEXTURE = 6, FS_BIT_SHADER_TEX_CLAMP = 7, FS_BIT_CLAMP_S = 8, FS_BIT_CLAMP_T = 9, @@ -93,9 +93,8 @@ enum FShaderBit : uint8_t { FS_BIT_TEST_DISCARD_TO_ZERO = 48, FS_BIT_NO_DEPTH_CANNOT_DISCARD_STENCIL = 49, FS_BIT_COLOR_WRITEMASK = 50, - FS_BIT_3D_TEXTURE = 51, - FS_BIT_SHADER_SMOOTHED_DEPAL = 52, - FS_BIT_REPLACE_LOGIC_OP = 53, // 4 bits. GE_LOGIC_COPY means no-op/off. + FS_BIT_REPLACE_LOGIC_OP = 51, // 4 bits. GE_LOGIC_COPY means no-op/off. + FS_BIT_SHADER_DEPAL_MODE = 55, // 2 bits (ShaderDepalMode) }; static inline FShaderBit operator +(FShaderBit bit, int i) { diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index cefc86f4c5..1be81f8abc 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1956,7 +1956,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer // Since we started/ended render passes, might need these. gstate_c.Dirty(DIRTY_DEPAL); - gstate_c.SetUseShaderDepal(true, smoothedDepal); + gstate_c.SetUseShaderDepal(smoothedDepal ? ShaderDepalMode::SMOOTHED : ShaderDepalMode::NORMAL); gstate_c.depalFramebufferFormat = framebuffer->fb_format; const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16); @@ -1972,7 +1972,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer depthUpperBits = (depth && framebuffer->fb_format == GE_FORMAT_8888) ? ((gstate.getTextureAddress(0) & 0x600000) >> 20) : 0; textureShader = textureShaderCache_->GetDepalettizeShader(clutMode, texFormat, depth ? GE_FORMAT_DEPTH16 : framebuffer->fb_format, smoothedDepal, depthUpperBits); - gstate_c.SetUseShaderDepal(false, false); + gstate_c.SetUseShaderDepal(ShaderDepalMode::OFF); } if (textureShader) { @@ -2045,7 +2045,7 @@ void TextureCacheCommon::ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer framebufferManager_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET); BoundFramebufferTexture(); - gstate_c.SetUseShaderDepal(false, false); + gstate_c.SetUseShaderDepal(ShaderDepalMode::OFF); gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650); } diff --git a/GPU/D3D11/TextureCacheD3D11.cpp b/GPU/D3D11/TextureCacheD3D11.cpp index c656f3d7dd..799f905514 100644 --- a/GPU/D3D11/TextureCacheD3D11.cpp +++ b/GPU/D3D11/TextureCacheD3D11.cpp @@ -258,7 +258,7 @@ void TextureCacheD3D11::BindTexture(TexCacheEntry *entry) { SamplerCacheKey samplerKey = GetSamplingParams(maxLevel, entry); ID3D11SamplerState *state = samplerCache_.GetOrCreateSampler(device_, samplerKey); context_->PSSetSamplers(0, 1, &state); - gstate_c.SetUseShaderDepal(false, false); + gstate_c.SetUseShaderDepal(ShaderDepalMode::OFF); } void TextureCacheD3D11::ApplySamplingParams(const SamplerCacheKey &key) { diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 928854f1e2..14ebad20be 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -230,7 +230,7 @@ void TextureCacheGLES::BindTexture(TexCacheEntry *entry) { int maxLevel = (entry->status & TexCacheEntry::STATUS_NO_MIPS) ? 0 : entry->maxLevel; SamplerCacheKey samplerKey = GetSamplingParams(maxLevel, entry); ApplySamplingParams(samplerKey); - gstate_c.SetUseShaderDepal(false, false); + gstate_c.SetUseShaderDepal(ShaderDepalMode::OFF); } void TextureCacheGLES::Unbind() { diff --git a/GPU/GPU.h b/GPU/GPU.h index 5410fb43d5..1fd455c662 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -40,6 +40,13 @@ enum SkipDrawReasonFlags { SKIPDRAW_WINDOW_MINIMIZED = 8, // Don't draw when the host window is minimized. }; +enum class ShaderDepalMode { + OFF = 0, + NORMAL = 1, + SMOOTHED = 2, + CLUT8_8888 = 3, // Read 8888 framebuffer as 8-bit CLUT. +}; + // Global GPU-related utility functions. // Nothing directly Ge-related in here. diff --git a/GPU/GPUState.h b/GPU/GPUState.h index f31d31e176..cbfb58395d 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -529,10 +529,9 @@ struct GPUStateCache { bool IsDirty(u64 what) const { return (dirty & what) != 0ULL; } - void SetUseShaderDepal(bool depal, bool smoothed) { - if (depal != useShaderDepal) { - useShaderDepal = depal; - useSmoothedShaderDepal = smoothed; + void SetUseShaderDepal(ShaderDepalMode mode) { + if (mode != shaderDepalMode) { + shaderDepalMode = mode; Dirty(DIRTY_FRAGMENTSHADER_STATE); } } @@ -628,8 +627,7 @@ struct GPUStateCache { SubmitType submitType; int spline_num_points_u; - bool useShaderDepal; - bool useSmoothedShaderDepal; + ShaderDepalMode shaderDepalMode; GEBufferFormat depalFramebufferFormat; u32 getRelativeAddress(u32 data) const; diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index b3e5ff339f..9cb91e00c6 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -371,7 +371,7 @@ VulkanFragmentShader *ShaderManagerVulkan::GetFragmentShaderFromModule(VkShaderM // instantaneous. #define CACHE_HEADER_MAGIC 0xff51f420 -#define CACHE_VERSION 25 +#define CACHE_VERSION 26 struct VulkanCacheHeader { uint32_t magic; uint32_t version; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index d11e92ba05..bbb0f611bb 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -403,7 +403,7 @@ void TextureCacheVulkan::BindTexture(TexCacheEntry *entry) { curSampler_ = samplerCache_.GetOrCreateSampler(samplerKey); imageView_ = entry->vkTex->GetImageView(); drawEngine_->SetDepalTexture(VK_NULL_HANDLE, false); - gstate_c.SetUseShaderDepal(false, false); + gstate_c.SetUseShaderDepal(ShaderDepalMode::OFF); } void TextureCacheVulkan::ApplySamplingParams(const SamplerCacheKey &key) { diff --git a/unittest/TestShaderGenerators.cpp b/unittest/TestShaderGenerators.cpp index 7bdb0b3e8c..8cf73cd8b4 100644 --- a/unittest/TestShaderGenerators.cpp +++ b/unittest/TestShaderGenerators.cpp @@ -402,7 +402,6 @@ bool TestFragmentShaders() { // bits we don't need to test because they are irrelevant on d3d11 id.SetBit(FS_BIT_NO_DEPTH_CANNOT_DISCARD_STENCIL, false); - id.SetBit(FS_BIT_SHADER_DEPAL, false); // DX9 disabling: if (static_cast(id.Bits(FS_BIT_STENCIL_TO_ALPHA, 2)) == ReplaceAlphaType::REPLACE_ALPHA_DUALSOURCE) From 4491c480a62ad3e1a6ce47d9fb4d7e04dbbc142b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 14:46:00 +0200 Subject: [PATCH 44/69] Texture/framebuffer matching: Do margin check in bytes. --- GPU/Common/FramebufferManagerCommon.h | 1 + GPU/Common/TextureCacheCommon.cpp | 41 +++++++++++++++------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/GPU/Common/FramebufferManagerCommon.h b/GPU/Common/FramebufferManagerCommon.h index e4e2b86cf6..b54cc0611d 100644 --- a/GPU/Common/FramebufferManagerCommon.h +++ b/GPU/Common/FramebufferManagerCommon.h @@ -148,6 +148,7 @@ struct VirtualFramebuffer { // Convenience methods inline int WidthInBytes() const { return width * BufferFormatBytesPerPixel(fb_format); } + inline int BufferWidthInBytes() const { return bufferWidth * BufferFormatBytesPerPixel(fb_format); } inline int FbStrideInBytes() const { return fb_stride * BufferFormatBytesPerPixel(fb_format); } inline int ZStrideInBytes() const { return z_stride * 2; } }; diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 1be81f8abc..1e7b7137a8 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -915,10 +915,11 @@ bool TextureCacheCommon::MatchFramebuffer( const bool noOffset = texaddr == addr; const bool exactMatch = noOffset && entry.format < 4 && channel == RASTER_COLOR && fb_stride_in_bytes == tex_stride_in_bytes; - const u32 w = 1 << ((entry.dim >> 0) & 0xf); - const u32 h = 1 << ((entry.dim >> 8) & 0xf); + const u32 texWidth = 1 << ((entry.dim >> 0) & 0xf); + const u32 texHeight = 1 << ((entry.dim >> 8) & 0xf); + // 512 on a 272 framebuffer is sane, so let's be lenient. - const u32 minSubareaHeight = h / 4; + const u32 minSubareaHeight = texHeight / 4; // If they match "exactly", it's non-CLUT and from the top left. if (exactMatch) { @@ -948,19 +949,20 @@ bool TextureCacheCommon::MatchFramebuffer( (fb_format == GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT32) || (fb_format != GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT16); - const int bitOffset = (texaddr - addr) * 8; - if (bitOffset != 0) { - const int pixelOffset = bitOffset / (int)std::max(1U, (u32)textureBitsPerPixel[entry.format]); + const int texBitsPerPixel = std::max(1U, (u32)textureBitsPerPixel[entry.format]); + const int byteOffset = texaddr - addr; + if (byteOffset != 0) { + const int texelOffset = byteOffset * 8 / texBitsPerPixel; - if (pixelOffset > 0) { - matchInfo->yOffset = entry.bufw == 0 ? 0 : pixelOffset / (int)entry.bufw; - matchInfo->xOffset = entry.bufw == 0 ? 0 : pixelOffset % (int)entry.bufw; - } else if (pixelOffset < 0) { + if (texelOffset > 0) { + matchInfo->yOffset = entry.bufw == 0 ? 0 : texelOffset / (int)entry.bufw; + matchInfo->xOffset = entry.bufw == 0 ? 0 : texelOffset % (int)entry.bufw; + } else if (texelOffset < 0) { // We don't support negative Y offsets, and negative X offsets are only for the Killzone workaround. - if (pixelOffset < -(int)entry.bufw || !PSP_CoreParameter().compat.flags().SplitFramebufferMargin) { + if (texelOffset < -(int)entry.bufw || !PSP_CoreParameter().compat.flags().SplitFramebufferMargin) { return false; } - matchInfo->xOffset = entry.bufw == 0 ? 0 : -(-pixelOffset % (int)entry.bufw); + matchInfo->xOffset = entry.bufw == 0 ? 0 : -(-texelOffset % (int)entry.bufw); } } @@ -969,13 +971,11 @@ bool TextureCacheCommon::MatchFramebuffer( return false; } - if (fb_stride_in_bytes != tex_stride_in_bytes) { - // Probably irrelevant. - return false; - } - // Check if it's in bufferWidth (which might be higher than width and may indicate the framebuffer includes the data.) - if (matchInfo->xOffset >= framebuffer->bufferWidth && matchInfo->xOffset + w <= (u32)fb_stride) { + // Do the computation in bytes so that it's valid even in case of weird reinterpret scenarios. + const int xOffsetInBytes = matchInfo->xOffset * 8 / texBitsPerPixel; + const int texWidthInBytes = texWidth * 8 / texBitsPerPixel; + if (xOffsetInBytes >= framebuffer->BufferWidthInBytes() && xOffsetInBytes + texWidthInBytes <= (int)fb_stride_in_bytes) { // This happens in Brave Story, see #10045 - the texture is in the space between strides, with matching stride. return false; } @@ -987,6 +987,11 @@ bool TextureCacheCommon::MatchFramebuffer( return false; } + if (fb_stride_in_bytes != tex_stride_in_bytes) { + // Probably irrelevant. Although, as we shall see soon, there are exceptions. + return false; + } + // Check for CLUT. The framebuffer is always RGB, but it can be interpreted as a CLUT texture. // 3rd Birthday (and a bunch of other games) render to a 16 bit clut texture. if (matchingClutFormat) { From a30896e21facb291357c72fd65207b1933983061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 15:08:47 +0200 Subject: [PATCH 45/69] Switch more texture matching calculations to use bytes for matching. --- GPU/Common/TextureCacheCommon.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 1e7b7137a8..94742aad19 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -883,6 +883,11 @@ bool TextureCacheCommon::MatchFramebuffer( return false; } + if (!fb_stride) { + // Hard to make decisions. + return false; + } + switch (entry.format) { case GE_TFMT_DXT1: case GE_TFMT_DXT3: @@ -947,23 +952,21 @@ bool TextureCacheCommon::MatchFramebuffer( (fb_format == GE_FORMAT_DEPTH16 && entry.format == GE_TFMT_CLUT16) || (fb_format == GE_FORMAT_DEPTH16 && entry.format == GE_TFMT_5650) || (fb_format == GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT32) || - (fb_format != GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT16); + (fb_format != GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT16) || + (fb_format == GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT8); // Mixed byte size, format, reinterpret in depal! const int texBitsPerPixel = std::max(1U, (u32)textureBitsPerPixel[entry.format]); const int byteOffset = texaddr - addr; - if (byteOffset != 0) { - const int texelOffset = byteOffset * 8 / texBitsPerPixel; - - if (texelOffset > 0) { - matchInfo->yOffset = entry.bufw == 0 ? 0 : texelOffset / (int)entry.bufw; - matchInfo->xOffset = entry.bufw == 0 ? 0 : texelOffset % (int)entry.bufw; - } else if (texelOffset < 0) { - // We don't support negative Y offsets, and negative X offsets are only for the Killzone workaround. - if (texelOffset < -(int)entry.bufw || !PSP_CoreParameter().compat.flags().SplitFramebufferMargin) { - return false; - } - matchInfo->xOffset = entry.bufw == 0 ? 0 : -(-texelOffset % (int)entry.bufw); + if (byteOffset > 0) { + matchInfo->yOffset = byteOffset / fb_stride_in_bytes; + matchInfo->xOffset = 8 * (byteOffset % fb_stride_in_bytes) / texBitsPerPixel; + } else if (byteOffset < 0) { + int texelOffset = 8 * byteOffset / texBitsPerPixel; + // We don't support negative Y offsets, and negative X offsets are only for the Killzone workaround. + if (texelOffset < -(int)entry.bufw || !PSP_CoreParameter().compat.flags().SplitFramebufferMargin) { + return false; } + matchInfo->xOffset = entry.bufw == 0 ? 0 : -(-texelOffset % (int)entry.bufw); } if (matchInfo->yOffset > 0 && matchInfo->yOffset + minSubareaHeight >= framebuffer->height) { From 3e7f6b57aaaffc2eef534aae3b786e8942475593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 16:17:38 +0200 Subject: [PATCH 46/69] Shadergen issues found by the test --- Common/GPU/ShaderWriter.cpp | 2 +- GPU/Common/FragmentShaderGenerator.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Common/GPU/ShaderWriter.cpp b/Common/GPU/ShaderWriter.cpp index 62d5760408..b260d05fc9 100644 --- a/Common/GPU/ShaderWriter.cpp +++ b/Common/GPU/ShaderWriter.cpp @@ -453,7 +453,7 @@ ShaderWriter &ShaderWriter::LoadTexture2D(const char *sampName, const char *uv, break; default: // Note: we ignore the sampler. make sure you bound samplers to the textures correctly. - F("texelFetch(%s, %s, %d)", lang_.texture, sampName, uv, level); + F("texelFetch(%s, %s, %d)", sampName, uv, level); break; } return *this; diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index d1aabac698..fe3d685f28 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -96,7 +96,10 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu if (texture3D) { shaderDepalMode = ShaderDepalMode::OFF; } - + if (!compat.bitwiseOps && shaderDepalMode != ShaderDepalMode::OFF) { + *errorString = "depal requires bitwise ops"; + return false; + } bool bgraTexture = id.Bit(FS_BIT_BGRA_TEXTURE); bool colorWriteMask = id.Bit(FS_BIT_COLOR_WRITEMASK) && compat.bitwiseOps; @@ -732,7 +735,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu break; case ShaderDepalMode::CLUT8_8888: // Not yet implemented. - WRITE(p, " t = vec4(0.0, 0.0, 0.0, 0.0);\n"); + WRITE(p, " vec4 t = vec4(0.0, 0.0, 0.0, 0.0);\n"); break; } From 2e3b73abaace9dbf10f467bd2f0443aba5923b49 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 08:22:37 -0700 Subject: [PATCH 47/69] softgpu: Restrict sprite fast path to throughmode. Its UV checks already should have generally, but let's be safe. It doesn't validate state like fog, etc. --- GPU/Software/RasterizerRectangle.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index 424c4549bd..c94e23beb6 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -267,8 +267,6 @@ static inline bool NoClampOrWrap(const RasterizerState &state, const Vec2f &tc) return false; if (state.samplerID.cached.sizes[0].w > 512 || state.samplerID.cached.sizes[0].h > 512) return false; - if (!state.throughMode) - return tc.x <= 1.0f && tc.y <= 1.0f; return tc.x <= state.samplerID.cached.sizes[0].w && tc.y <= state.samplerID.cached.sizes[0].h; } @@ -288,7 +286,7 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &b // Currently only works for TL/BR, which is the most common but not required. bool orient_check = xdiff >= 0 && ydiff >= 0; // We already have a fast path for clear in ClearRectangle. - bool state_check = !state.pixelID.clearMode && !state.samplerID.hasAnyMips && NoClampOrWrap(state, v0.texturecoords) && NoClampOrWrap(state, v1.texturecoords); + bool state_check = state.throughMode && !state.pixelID.clearMode && !state.samplerID.hasAnyMips && NoClampOrWrap(state, v0.texturecoords) && NoClampOrWrap(state, v1.texturecoords); // This doesn't work well with offset drawing, see #15876. Through never has a subpixel offset. bool subpixel_check = ((v0.screenpos.x | v0.screenpos.y | v1.screenpos.x | v1.screenpos.y) & 0xF) == 0; if ((coord_check || !state.enableTextures) && orient_check && state_check && subpixel_check) { From b90fc7137f2ec58246294c68a5eb30a05ee9451d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 08:24:40 -0700 Subject: [PATCH 48/69] softgpu: Correct accuracy of fog calculation. This matches values from a PSP exactly, with the help of immediate mode vertex values (since this directly allows specifying the fog factor without any floating point math.) --- GPU/Math3D.h | 10 +++++----- GPU/Software/DrawPixel.cpp | 4 +++- GPU/Software/Rasterizer.cpp | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/GPU/Math3D.h b/GPU/Math3D.h index dd1991f917..a87cce8318 100644 --- a/GPU/Math3D.h +++ b/GPU/Math3D.h @@ -228,11 +228,11 @@ public: Vec3() {} Vec3(const T a[3]) : x(a[0]), y(a[1]), z(a[2]) {} - Vec3(const T& _x, const T& _y, const T& _z) : x(_x), y(_y), z(_z) {} + constexpr Vec3(const T& _x, const T& _y, const T& _z) : x(_x), y(_y), z(_z) {} Vec3(const Vec2& _xy, const T& _z) : x(_xy.x), y(_xy.y), z(_z) {} #if defined(_M_SSE) - Vec3(const __m128 &_vec) : vec(_vec) {} - Vec3(const __m128i &_ivec) : ivec(_ivec) {} + constexpr Vec3(const __m128 &_vec) : vec(_vec) {} + constexpr Vec3(const __m128i &_ivec) : ivec(_ivec) {} Vec3(const Vec3Packed &_xyz) { vec = _mm_loadu_ps(_xyz.AsArray()); } @@ -249,7 +249,7 @@ public: #endif template - Vec3 Cast() const + constexpr Vec3 Cast() const { return Vec3((T2)x, (T2)y, (T2)z); } @@ -258,7 +258,7 @@ public: static Vec3 FromRGB(unsigned int rgb); unsigned int ToRGB() const; // alpha bits set to zero - static Vec3 AssignToAll(const T& f) + static constexpr Vec3 AssignToAll(const T& f) { return Vec3(f, f, f); } diff --git a/GPU/Software/DrawPixel.cpp b/GPU/Software/DrawPixel.cpp index ab244aacf8..2194c69e55 100644 --- a/GPU/Software/DrawPixel.cpp +++ b/GPU/Software/DrawPixel.cpp @@ -415,7 +415,9 @@ void SOFTRAST_CALL DrawSinglePixel(int x, int y, int z, int fog, Vec4IntArg colo // Fog is applied prior to color test. if (pixelID.applyFog && !clearMode) { Vec3 fogColor = Vec3::FromRGB(pixelID.cached.fogColor); - fogColor = (prim_color.rgb() * fog + fogColor * (255 - fog)) / 255; + // This is very similar to the BLEND texfunc, and simply always rounds up. + static constexpr Vec3 roundup = Vec3::AssignToAll(255); + fogColor = (prim_color.rgb() * fog + fogColor * (255 - fog) + roundup) / 256; prim_color.r() = fogColor.r(); prim_color.g() = fogColor.g(); prim_color.b() = fogColor.b(); diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index ed8848ce80..0348f6d57a 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -348,7 +348,7 @@ Vec3 AlphaBlendingResult(const PixelFuncID &pixelID, const Vec4 &sourc return Vec3(_mm_unpacklo_epi16(_mm_adds_epi16(s, d), _mm_setzero_si128())); #else - Vec3 half = Vec3::AssignToAll(1); + static constexpr Vec3 half = Vec3::AssignToAll(1); Vec3 lhs = ((source.rgb() * 2 + half) * (srcfactor * 2 + half)) / 1024; Vec3 rhs = ((dst.rgb() * 2 + half) * (dstfactor * 2 + half)) / 1024; return lhs + rhs; @@ -370,7 +370,7 @@ Vec3 AlphaBlendingResult(const PixelFuncID &pixelID, const Vec4 &sourc return Vec3(_mm_unpacklo_epi16(_mm_max_epi16(_mm_subs_epi16(s, d), _mm_setzero_si128()), _mm_setzero_si128())); #else - Vec3 half = Vec3::AssignToAll(1); + static constexpr Vec3 half = Vec3::AssignToAll(1); Vec3 lhs = ((source.rgb() * 2 + half) * (srcfactor * 2 + half)) / 1024; Vec3 rhs = ((dst.rgb() * 2 + half) * (dstfactor * 2 + half)) / 1024; return lhs - rhs; @@ -392,7 +392,7 @@ Vec3 AlphaBlendingResult(const PixelFuncID &pixelID, const Vec4 &sourc return Vec3(_mm_unpacklo_epi16(_mm_max_epi16(_mm_subs_epi16(d, s), _mm_setzero_si128()), _mm_setzero_si128())); #else - Vec3 half = Vec3::AssignToAll(1); + static constexpr Vec3 half = Vec3::AssignToAll(1); Vec3 lhs = ((source.rgb() * 2 + half) * (srcfactor * 2 + half)) / 1024; Vec3 rhs = ((dst.rgb() * 2 + half) * (dstfactor * 2 + half)) / 1024; return rhs - lhs; From e72309745eb330d3c04b4f13c6fd8ed957e869a3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 08:50:07 -0700 Subject: [PATCH 49/69] softjit: Implement accurate fog color blending. --- GPU/Software/DrawPixel.cpp | 2 -- GPU/Software/DrawPixel.h | 2 -- GPU/Software/DrawPixelX86.cpp | 26 ++++++++++++-------------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/GPU/Software/DrawPixel.cpp b/GPU/Software/DrawPixel.cpp index 2194c69e55..ee47c27b94 100644 --- a/GPU/Software/DrawPixel.cpp +++ b/GPU/Software/DrawPixel.cpp @@ -550,8 +550,6 @@ void PixelJitCache::Clear() { constBlendHalf_11_4s_ = nullptr; constBlendInvert_11_4s_ = nullptr; - const255_16s_ = nullptr; - constBy255i_ = nullptr; } std::string PixelJitCache::DescribeCodePtr(const u8 *ptr) { diff --git a/GPU/Software/DrawPixel.h b/GPU/Software/DrawPixel.h index 982ee27765..f813bf61c1 100644 --- a/GPU/Software/DrawPixel.h +++ b/GPU/Software/DrawPixel.h @@ -106,8 +106,6 @@ private: const u8 *constBlendHalf_11_4s_ = nullptr; const u8 *constBlendInvert_11_4s_ = nullptr; - const u8 *const255_16s_ = nullptr; - const u8 *constBy255i_ = nullptr; #if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64) void Discard(); diff --git a/GPU/Software/DrawPixelX86.cpp b/GPU/Software/DrawPixelX86.cpp index 8f006bece4..dc53be1c62 100644 --- a/GPU/Software/DrawPixelX86.cpp +++ b/GPU/Software/DrawPixelX86.cpp @@ -336,12 +336,6 @@ void PixelJitCache::WriteConstantPool(const PixelFuncID &id) { // This is used for shifted blend factors, to inverse them. WriteSimpleConst8x16(constBlendInvert_11_4s_, 0xFF << 4); - - // A set of 255s, used to inverse fog. - WriteSimpleConst8x16(const255_16s_, 0xFF); - - // This is used for a multiply that divides by 255 with shifting. - WriteSimpleConst8x16(constBy255i_, 0x8081); } bool PixelJitCache::Jit_ApplyDepthRange(const PixelFuncID &id) { @@ -535,7 +529,8 @@ bool PixelJitCache::Jit_ApplyFog(const PixelFuncID &id) { // Load a set of 255s at 16 bit into a reg for later... X64Reg invertReg = regCache_.Alloc(RegCache::VEC_TEMP2); - MOVDQA(invertReg, M(const255_16s_)); + PCMPEQW(invertReg, R(invertReg)); + PSRLW(invertReg, 8); // Expand (we clamped) color to 16 bit as well, so we can multiply with fog. X64Reg argColorReg = regCache_.Find(RegCache::VEC_ARG_COLOR); @@ -568,21 +563,24 @@ bool PixelJitCache::Jit_ApplyFog(const PixelFuncID &id) { // We can free up the actual fog reg now. regCache_.ForceRelease(RegCache::GEN_ARG_FOG); + // Our goal here is to calculate this formula: + // (argColor * fog + fogColor * (255 - fog) + 255) / 256 + // Now we multiply the existing color by fog... PMULLW(argColorReg, R(fogMultReg)); - // And then inverse the fog value using those 255s we loaded, and multiply by fog color. - PSUBUSW(invertReg, R(fogMultReg)); + // Before inversing, let's add that 255 we loaded in as well, since we have it. + PADDW(argColorReg, R(invertReg)); + // And then inverse the fog value using those 255s, and multiply by fog color. + PSUBW(invertReg, R(fogMultReg)); PMULLW(fogColorReg, R(invertReg)); // At this point, argColorReg and fogColorReg are multiplied at 16-bit, so we need to sum. - PADDUSW(argColorReg, R(fogColorReg)); + PADDW(argColorReg, R(fogColorReg)); regCache_.Release(fogColorReg, RegCache::VEC_TEMP1); regCache_.Release(invertReg, RegCache::VEC_TEMP2); regCache_.Release(fogMultReg, RegCache::VEC_TEMP3); - // Now to divide by 255, we use bit tricks: multiply by 0x8081, and shift right by 16+7. - PMULHUW(argColorReg, M(constBy255i_)); - // Now shift right by 7 (PMULHUW already did 16 of the shift.) - PSRLW(argColorReg, 7); + // Now we simply divide by 256, or in other words shift by 8. + PSRLW(argColorReg, 8); // Okay, put A back in, we'll shrink it to 8888 when needed. PINSRW(argColorReg, R(alphaReg), 3); From 8c55e18ea81ce7dde6c27a6010d3ebaf134f4ccb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 08:54:34 -0700 Subject: [PATCH 50/69] softgpu: Switch vert continue buffer to members. Better this than static. May be easier to handle imm prims correctly. --- GPU/Software/TransformUnit.cpp | 123 ++++++++++++++++----------------- GPU/Software/TransformUnit.h | 6 ++ 2 files changed, 65 insertions(+), 64 deletions(-) diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 2a8eeeffa6..28a91a7a8c 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -482,16 +482,11 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G VertexReader vreader(decoded_, vtxfmt, vertex_type); - static VertexData data[4]; // Normally max verts per prim is 3, but we temporarily need 4 to detect rectangles from strips. - // This is the index of the next vert in data (or higher, may need modulus.) - static int data_index = 0; - - static GEPrimitiveType prev_prim = GE_PRIM_POINTS; if (prim_type != GE_PRIM_KEEP_PREVIOUS) { - data_index = 0; - prev_prim = prim_type; + data_index_ = 0; + prev_prim_ = prim_type; } else { - prim_type = prev_prim; + prim_type = prev_prim_; } int vtcs_per_prim; @@ -530,14 +525,14 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G vreader.Goto(vtx); } - data[data_index++] = ReadVertex(vreader, transformState, outside_range_flag); - if (data_index < vtcs_per_prim) { + data_[data_index_++] = ReadVertex(vreader, transformState, outside_range_flag); + if (data_index_ < vtcs_per_prim) { // Keep reading. Note: an incomplete prim will stay read for GE_PRIM_KEEP_PREVIOUS. continue; } // Okay, we've got enough verts. Reset the index for next time. - data_index = 0; + data_index_ = 0; if (outside_range_flag) { // Cull the prim if it was outside, and move to the next prim. outside_range_flag = false; @@ -548,22 +543,22 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G case GE_PRIM_TRIANGLES: { if (cullType == CullType::OFF) { - Clipper::ProcessTriangle(data[0], data[1], data[2], data[2], *binner_); - Clipper::ProcessTriangle(data[2], data[1], data[0], data[2], *binner_); + Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[2], *binner_); + Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[2], *binner_); } else if (cullType == CullType::CW) { - Clipper::ProcessTriangle(data[2], data[1], data[0], data[2], *binner_); + Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[2], *binner_); } else { - Clipper::ProcessTriangle(data[0], data[1], data[2], data[2], *binner_); + Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[2], *binner_); } break; } case GE_PRIM_LINES: - Clipper::ProcessLine(data[0], data[1], *binner_); + Clipper::ProcessLine(data_[0], data_[1], *binner_); break; case GE_PRIM_POINTS: - Clipper::ProcessPoint(data[0], *binner_); + Clipper::ProcessPoint(data_[0], *binner_); break; default: @@ -581,45 +576,45 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G vreader.Goto(vtx); } - data[data_index++] = ReadVertex(vreader, transformState, outside_range_flag); + data_[data_index_++] = ReadVertex(vreader, transformState, outside_range_flag); if (outside_range_flag) { outside_range_flag = false; // Note: this is the post increment index. If odd, we set the first vert. - if (data_index & 1) { + if (data_index_ & 1) { // Skip the next one and forget this one. vtx++; - data_index--; + data_index_--; } else { // Forget both of the last 2. - data_index -= 2; + data_index_ -= 2; } } - if (data_index == 4 && vreader.isThrough() && cullType == CullType::OFF) { - if (Rasterizer::DetectRectangleThroughModeSlices(binner_->State(), data)) { - data[1] = data[3]; - data_index = 2; + if (data_index_ == 4 && vreader.isThrough() && cullType == CullType::OFF) { + if (Rasterizer::DetectRectangleThroughModeSlices(binner_->State(), data_)) { + data_[1] = data_[3]; + data_index_ = 2; } } - if (data_index == 4) { - Clipper::ProcessRect(data[0], data[1], *binner_); - Clipper::ProcessRect(data[2], data[3], *binner_); - data_index = 0; + if (data_index_ == 4) { + Clipper::ProcessRect(data_[0], data_[1], *binner_); + Clipper::ProcessRect(data_[2], data_[3], *binner_); + data_index_ = 0; } } - if (data_index >= 2) { - Clipper::ProcessRect(data[0], data[1], *binner_); - data_index -= 2; + if (data_index_ >= 2) { + Clipper::ProcessRect(data_[0], data_[1], *binner_); + data_index_ -= 2; } break; case GE_PRIM_LINE_STRIP: { // Don't draw a line when loading the first vertex. - // If data_index is 1 or 2, etc., it means we're continuing a line strip. - int skip_count = data_index == 0 ? 1 : 0; + // If data_index_ is 1 or 2, etc., it means we're continuing a line strip. + int skip_count = data_index_ == 0 ? 1 : 0; for (int vtx = 0; vtx < vertex_count; ++vtx) { if (indices) { vreader.Goto(ConvertIndex(vtx) - index_lower_bound); @@ -627,7 +622,7 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G vreader.Goto(vtx); } - data[(data_index++) & 1] = ReadVertex(vreader, transformState, outside_range_flag); + data_[(data_index_++) & 1] = ReadVertex(vreader, transformState, outside_range_flag); if (outside_range_flag) { // Drop all primitives containing the current vertex skip_count = 2; @@ -638,8 +633,8 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G if (skip_count) { --skip_count; } else { - // We already incremented data_index, so data_index & 1 is previous one. - Clipper::ProcessLine(data[data_index & 1], data[(data_index & 1) ^ 1], *binner_); + // We already incremented data_index_, so data_index_ & 1 is previous one. + Clipper::ProcessLine(data_[data_index_ & 1], data_[(data_index_ & 1) ^ 1], *binner_); } } break; @@ -648,11 +643,11 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G case GE_PRIM_TRIANGLE_STRIP: { // Don't draw a triangle when loading the first two vertices. - int skip_count = data_index >= 2 ? 0 : 2 - data_index; + int skip_count = data_index_ >= 2 ? 0 : 2 - data_index_; // If index count == 4, check if we can convert to a rectangle. // This is for Darkstalkers (and should speed up many 2D games). - if (data_index == 0 && vertex_count == 4 && cullType == CullType::OFF) { + if (data_index_ == 0 && vertex_count == 4 && cullType == CullType::OFF) { for (int vtx = 0; vtx < 4; ++vtx) { if (indices) { vreader.Goto(ConvertIndex(vtx) - index_lower_bound); @@ -660,13 +655,13 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G else { vreader.Goto(vtx); } - data[vtx] = ReadVertex(vreader, transformState, outside_range_flag); + data_[vtx] = ReadVertex(vreader, transformState, outside_range_flag); } // If a strip is effectively a rectangle, draw it as such! int tl = -1, br = -1; - if (!outside_range_flag && Rasterizer::DetectRectangleFromStrip(binner_->State(), data, &tl, &br)) { - Clipper::ProcessRect(data[tl], data[br], *binner_); + if (!outside_range_flag && Rasterizer::DetectRectangleFromStrip(binner_->State(), data_, &tl, &br)) { + Clipper::ProcessRect(data_[tl], data_[br], *binner_); break; } } @@ -679,8 +674,8 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G vreader.Goto(vtx); } - int provoking_index = (data_index++) % 3; - data[provoking_index] = ReadVertex(vreader, transformState, outside_range_flag); + int provoking_index = (data_index_++) % 3; + data_[provoking_index] = ReadVertex(vreader, transformState, outside_range_flag); if (outside_range_flag) { // Drop all primitives containing the current vertex skip_count = 2; @@ -694,14 +689,14 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G } if (cullType == CullType::OFF) { - Clipper::ProcessTriangle(data[0], data[1], data[2], data[provoking_index], *binner_); - Clipper::ProcessTriangle(data[2], data[1], data[0], data[provoking_index], *binner_); - } else if ((!(int)cullType) ^ ((data_index - 1) % 2)) { + Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); + Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); + } else if ((!(int)cullType) ^ ((data_index_ - 1) % 2)) { // We need to reverse the vertex order for each second primitive, // but we additionally need to do that for every primitive if CCW cullmode is used. - Clipper::ProcessTriangle(data[2], data[1], data[0], data[provoking_index], *binner_); + Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); } else { - Clipper::ProcessTriangle(data[0], data[1], data[2], data[provoking_index], *binner_); + Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); } } break; @@ -711,18 +706,18 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G { // Don't draw a triangle when loading the first two vertices. // (this doesn't count the central one.) - int skip_count = data_index <= 1 ? 1 : 0; + int skip_count = data_index_ <= 1 ? 1 : 0; int start_vtx = 0; // Only read the central vertex if we're not continuing. - if (data_index == 0) { + if (data_index_ == 0) { if (indices) { vreader.Goto(ConvertIndex(0) - index_lower_bound); } else { vreader.Goto(0); } - data[0] = ReadVertex(vreader, transformState, outside_range_flag); - data_index++; + data_[0] = ReadVertex(vreader, transformState, outside_range_flag); + data_index_++; start_vtx = 1; // If the central vertex is outside range, all the points are toast. @@ -730,19 +725,19 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G break; } - if (data_index == 1 && vertex_count == 4 && cullType == CullType::OFF) { + if (data_index_ == 1 && vertex_count == 4 && cullType == CullType::OFF) { for (int vtx = start_vtx; vtx < vertex_count; ++vtx) { if (indices) { vreader.Goto(ConvertIndex(vtx) - index_lower_bound); } else { vreader.Goto(vtx); } - data[vtx] = ReadVertex(vreader, transformState, outside_range_flag); + data_[vtx] = ReadVertex(vreader, transformState, outside_range_flag); } int tl = -1, br = -1; - if (!outside_range_flag && Rasterizer::DetectRectangleFromFan(binner_->State(), data, vertex_count, &tl, &br)) { - Clipper::ProcessRect(data[tl], data[br], *binner_); + if (!outside_range_flag && Rasterizer::DetectRectangleFromFan(binner_->State(), data_, vertex_count, &tl, &br)) { + Clipper::ProcessRect(data_[tl], data_[br], *binner_); break; } } @@ -755,8 +750,8 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G vreader.Goto(vtx); } - int provoking_index = 2 - ((data_index++) % 2); - data[provoking_index] = ReadVertex(vreader, transformState, outside_range_flag); + int provoking_index = 2 - ((data_index_++) % 2); + data_[provoking_index] = ReadVertex(vreader, transformState, outside_range_flag); if (outside_range_flag) { // Drop all primitives containing the current vertex skip_count = 2; @@ -770,14 +765,14 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G } if (cullType == CullType::OFF) { - Clipper::ProcessTriangle(data[0], data[1], data[2], data[provoking_index], *binner_); - Clipper::ProcessTriangle(data[2], data[1], data[0], data[provoking_index], *binner_); - } else if ((!(int)cullType) ^ ((data_index - 1) % 2)) { + Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); + Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); + } else if ((!(int)cullType) ^ ((data_index_ - 1) % 2)) { // We need to reverse the vertex order for each second primitive, // but we additionally need to do that for every primitive if CCW cullmode is used. - Clipper::ProcessTriangle(data[2], data[1], data[0], data[provoking_index], *binner_); + Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); } else { - Clipper::ProcessTriangle(data[0], data[1], data[2], data[provoking_index], *binner_); + Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); } } break; diff --git a/GPU/Software/TransformUnit.h b/GPU/Software/TransformUnit.h index 54f9fb5f5e..faa761639c 100644 --- a/GPU/Software/TransformUnit.h +++ b/GPU/Software/TransformUnit.h @@ -136,6 +136,12 @@ private: u8 *decoded_ = nullptr; BinManager *binner_ = nullptr; + + // Normally max verts per prim is 3, but we temporarily need 4 to detect rectangles from strips. + VertexData data_[4]; + // This is the index of the next vert in data (or higher, may need modulus.) + int data_index_ = 0; + GEPrimitiveType prev_prim_ = GE_PRIM_POINTS; }; class SoftwareDrawEngine : public DrawEngineCommon { From cf959a846774308cf5f8750188bf5ff856d5b4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Sep 2022 19:33:31 +0200 Subject: [PATCH 51/69] Remove CLUT matching case that shouldn't be there yet. --- GPU/Common/TextureCacheCommon.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 94742aad19..ff8ff95098 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -952,8 +952,7 @@ bool TextureCacheCommon::MatchFramebuffer( (fb_format == GE_FORMAT_DEPTH16 && entry.format == GE_TFMT_CLUT16) || (fb_format == GE_FORMAT_DEPTH16 && entry.format == GE_TFMT_5650) || (fb_format == GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT32) || - (fb_format != GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT16) || - (fb_format == GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT8); // Mixed byte size, format, reinterpret in depal! + (fb_format != GE_FORMAT_8888 && entry.format == GE_TFMT_CLUT16); const int texBitsPerPixel = std::max(1U, (u32)textureBitsPerPixel[entry.format]); const int byteOffset = texaddr - addr; From aa377662dd0ccf7fc9bca7f05d8b87af6fddb998 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 10:57:04 -0700 Subject: [PATCH 52/69] GE Debugger: Provide addrs in breakpoint conds. Easier to just refer to the full address. --- GPU/Common/GPUDebugInterface.cpp | 46 ++++++++++++++++++++++++++++++-- GPU/Debugger/GECommandTable.cpp | 22 +++++++-------- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/GPU/Common/GPUDebugInterface.cpp b/GPU/Common/GPUDebugInterface.cpp index d5d9c564db..a058d6cbf6 100644 --- a/GPU/Common/GPUDebugInterface.cpp +++ b/GPU/Common/GPUDebugInterface.cpp @@ -31,6 +31,18 @@ enum class GEReferenceIndex : uint32_t { BFLAG, OP, DATA, + CLUTADDR, + TRANSFERSRC, + TRANSFERDST, + + TEXADDR0, + TEXADDR1, + TEXADDR2, + TEXADDR3, + TEXADDR4, + TEXADDR5, + TEXADDR6, + TEXADDR7, BONE_MATRIX = 0x200, WORLD_MATRIX = 0x260, @@ -56,6 +68,17 @@ static constexpr ReferenceName referenceNames[] = { { GEReferenceIndex::BFLAG, "boundflag" }, { GEReferenceIndex::OP, "op" }, { GEReferenceIndex::DATA, "data" }, + { GEReferenceIndex::CLUTADDR, "clutaddr" }, + { GEReferenceIndex::TRANSFERSRC, "transfersrc" }, + { GEReferenceIndex::TRANSFERDST, "transferdst" }, + { GEReferenceIndex::TEXADDR0, "texaddr0" }, + { GEReferenceIndex::TEXADDR1, "texaddr1" }, + { GEReferenceIndex::TEXADDR2, "texaddr2" }, + { GEReferenceIndex::TEXADDR3, "texaddr3" }, + { GEReferenceIndex::TEXADDR4, "texaddr4" }, + { GEReferenceIndex::TEXADDR5, "texaddr5" }, + { GEReferenceIndex::TEXADDR6, "texaddr6" }, + { GEReferenceIndex::TEXADDR7, "texaddr7" }, }; class GEExpressionFunctions : public IExpressionFunctions { @@ -133,15 +156,15 @@ bool GEExpressionFunctions::parseSymbol(char *str, uint32_t &symbolValue) { } uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) { + GPUgstate state = gpu_->GetGState(); if (referenceIndex < 0x100) { - uint32_t value = gpu_->GetGState().cmdmem[referenceIndex]; + uint32_t value = state.cmdmem[referenceIndex]; // TODO: Later, support float values and similar. return value & 0x00FFFFFF; } // We return the matrix value as float bits, which gets interpreted correctly in the parser. if (referenceIndex >= (uint32_t)GEReferenceIndex::BONE_MATRIX && referenceIndex < (uint32_t)GEReferenceIndex::MATRIX_END) { - GPUgstate state = gpu_->GetGState(); float value; if (referenceIndex >= (uint32_t)GEReferenceIndex::TGEN_MATRIX) { value = state.tgenMatrix[referenceIndex - (uint32_t)GEReferenceIndex::TGEN_MATRIX]; @@ -197,6 +220,25 @@ uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) { } return 0; + case GEReferenceIndex::CLUTADDR: + return state.getClutAddress(); + + case GEReferenceIndex::TRANSFERSRC: + return state.getTransferSrcAddress(); + + case GEReferenceIndex::TRANSFERDST: + return state.getTransferDstAddress(); + + case GEReferenceIndex::TEXADDR0: + case GEReferenceIndex::TEXADDR1: + case GEReferenceIndex::TEXADDR2: + case GEReferenceIndex::TEXADDR3: + case GEReferenceIndex::TEXADDR4: + case GEReferenceIndex::TEXADDR5: + case GEReferenceIndex::TEXADDR6: + case GEReferenceIndex::TEXADDR7: + return state.getTextureAddress((int)ref - (int)GEReferenceIndex::TEXADDR0); + case GEReferenceIndex::BONE_MATRIX: case GEReferenceIndex::WORLD_MATRIX: case GEReferenceIndex::VIEW_MATRIX: diff --git a/GPU/Debugger/GECommandTable.cpp b/GPU/Debugger/GECommandTable.cpp index 16304b9d75..e0e9573211 100644 --- a/GPU/Debugger/GECommandTable.cpp +++ b/GPU/Debugger/GECommandTable.cpp @@ -188,14 +188,14 @@ static constexpr GECmdInfo geCmdInfo[] = { { GE_CMD_FRAMEBUFWIDTH, "fbstride", GECmdFormat::STRIDE }, { GE_CMD_ZBUFPTR, "zbptr", GECmdFormat::LOW_ADDR_ONLY }, { GE_CMD_ZBUFWIDTH, "zbstride", GECmdFormat::STRIDE }, - { GE_CMD_TEXADDR0, "texaddr0", GECmdFormat::LOW_ADDR }, - { GE_CMD_TEXADDR1, "texaddr1", GECmdFormat::LOW_ADDR }, - { GE_CMD_TEXADDR2, "texaddr2", GECmdFormat::LOW_ADDR }, - { GE_CMD_TEXADDR3, "texaddr3", GECmdFormat::LOW_ADDR }, - { GE_CMD_TEXADDR4, "texaddr4", GECmdFormat::LOW_ADDR }, - { GE_CMD_TEXADDR5, "texaddr5", GECmdFormat::LOW_ADDR }, - { GE_CMD_TEXADDR6, "texaddr6", GECmdFormat::LOW_ADDR }, - { GE_CMD_TEXADDR7, "texaddr7", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR0, "texaddr0low", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR1, "texaddr1low", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR2, "texaddr2low", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR3, "texaddr3low", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR4, "texaddr4low", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR5, "texaddr5low", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR6, "texaddr6low", GECmdFormat::LOW_ADDR }, + { GE_CMD_TEXADDR7, "texaddr7low", GECmdFormat::LOW_ADDR }, { GE_CMD_TEXBUFWIDTH0, "texbufw0", GECmdFormat::STRIDE_HIGH_ADDR }, { GE_CMD_TEXBUFWIDTH1, "texbufw1", GECmdFormat::STRIDE_HIGH_ADDR }, { GE_CMD_TEXBUFWIDTH2, "texbufw2", GECmdFormat::STRIDE_HIGH_ADDR }, @@ -204,11 +204,11 @@ static constexpr GECmdInfo geCmdInfo[] = { { GE_CMD_TEXBUFWIDTH5, "texbufw5", GECmdFormat::STRIDE_HIGH_ADDR }, { GE_CMD_TEXBUFWIDTH6, "texbufw6", GECmdFormat::STRIDE_HIGH_ADDR }, { GE_CMD_TEXBUFWIDTH7, "texbufw7", GECmdFormat::STRIDE_HIGH_ADDR }, - { GE_CMD_CLUTADDR, "clutaddr", GECmdFormat::LOW_ADDR }, + { GE_CMD_CLUTADDR, "clutaddrlow", GECmdFormat::LOW_ADDR }, { GE_CMD_CLUTADDRUPPER, "clutaddrhigh", GECmdFormat::HIGH_ADDR }, - { GE_CMD_TRANSFERSRC, "transfersrc", GECmdFormat::LOW_ADDR }, + { GE_CMD_TRANSFERSRC, "transfersrclow", GECmdFormat::LOW_ADDR }, { GE_CMD_TRANSFERSRCW, "transfersrcstride", GECmdFormat::STRIDE_HIGH_ADDR }, - { GE_CMD_TRANSFERDST, "transferdst", GECmdFormat::LOW_ADDR }, + { GE_CMD_TRANSFERDST, "transferdstlow", GECmdFormat::LOW_ADDR }, { GE_CMD_TRANSFERDSTW, "transferdststride", GECmdFormat::STRIDE_HIGH_ADDR }, { GE_CMD_UNKNOWN_B6, "unknownb6", GECmdFormat::NONE }, { GE_CMD_UNKNOWN_B7, "unknownb7", GECmdFormat::NONE }, From 55c70332a1edbfc39ecb26baf3a9829d533f28db Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 11:05:30 -0700 Subject: [PATCH 53/69] GE Debugger: Eval breakpoints as if register set. --- GPU/Debugger/Breakpoints.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/GPU/Debugger/Breakpoints.cpp b/GPU/Debugger/Breakpoints.cpp index 225b25799d..97fbca57ee 100644 --- a/GPU/Debugger/Breakpoints.cpp +++ b/GPU/Debugger/Breakpoints.cpp @@ -171,7 +171,24 @@ bool IsRenderTargetCmdBreakpoint(u32 op) { return false; } -static bool HitAddressBreakpoint(u32 pc) { +static bool HitBreakpointCond(BreakpointInfo &bp, u32 op) { + u8 cmd = op >> 24; + + // Temporarily set the value while running the breakpoint. + // It makes more intuitive sense for the referenced data to already be set. + // Note this won't perform actions, like matrix uploads. + u32 diff = gstate.cmdmem[cmd] ^ op; + gstate.cmdmem[cmd] ^= diff; + + u32 result = 1; + if (!GPUDebugExecExpression(gpuDebug, bp.expression, result)) + result = 0; + + gstate.cmdmem[cmd] ^= diff; + return result != 0; +} + +static bool HitAddressBreakpoint(u32 pc, u32 op) { if (breakPCsCount == 0) return false; @@ -181,10 +198,7 @@ static bool HitAddressBreakpoint(u32 pc) { return false; if (entry->second.isConditional) { - u32 result = 1; - if (!GPUDebugExecExpression(gpuDebug, breakPCs[pc].expression, result)) - return false; - return result != 0; + return HitBreakpointCond(entry->second, op); } return true; } @@ -196,17 +210,14 @@ static bool HitOpBreakpoint(u32 op) { if (breakCmdsInfo[cmd].isConditional) { std::lock_guard guard(breaksLock); - u32 result = 1; - if (!GPUDebugExecExpression(gpuDebug, breakCmdsInfo[cmd].expression, result)) - return false; - return result != 0; + return HitBreakpointCond(breakCmdsInfo[cmd], op); } return true; } bool IsBreakpoint(u32 pc, u32 op) { - if (HitAddressBreakpoint(pc) || HitOpBreakpoint(op)) { + if (HitAddressBreakpoint(pc, op) || HitOpBreakpoint(op)) { return true; } From d25602f01bf58f32973e024946d95ecd057828b7 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Sun, 11 Sep 2022 21:47:07 +0200 Subject: [PATCH 54/69] Add Rewrite to DrawSyncEatCycles hack, softlocks without it --- assets/compat.ini | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/assets/compat.ini b/assets/compat.ini index 63a4f168f7..3d2846d377 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -325,6 +325,11 @@ UCJS18036 = true UCAS40292 = true UCJS18053 = true +# Rewrite +# fixes softlocks, see #15904 +ULJM06364 = true +ULJM06365 = true + # Crash Tag Team Racing used to need it to pass checking memory stick screen. # ULES00168 = true # ULES00169 = true From 7d07e4e75df8a80e8be261a8f8fda82a5bd89700 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 13:09:03 -0700 Subject: [PATCH 55/69] GE Debugger: Add fields to register expressions. This means a conditional breakpoint can now use, for example, vtype.through == 1 to check the through mode flag. No constants, but this makes it easier to get right. Would be nice to have an autocomplete of the field names, of course... --- GPU/Common/GPUDebugInterface.cpp | 454 ++++++++++++++++++++++++++++++- GPU/Debugger/GECommandTable.h | 2 +- 2 files changed, 452 insertions(+), 4 deletions(-) diff --git a/GPU/Common/GPUDebugInterface.cpp b/GPU/Common/GPUDebugInterface.cpp index a058d6cbf6..34cb050ffd 100644 --- a/GPU/Common/GPUDebugInterface.cpp +++ b/GPU/Common/GPUDebugInterface.cpp @@ -50,6 +50,9 @@ enum class GEReferenceIndex : uint32_t { PROJ_MATRIX = 0x278, TGEN_MATRIX = 0x288, MATRIX_END = 0x294, + + FIELD_START = 0x1000, + FIELD_END = 0xFF000, }; ENUM_CLASS_BITOPS(GEReferenceIndex); @@ -81,6 +84,228 @@ static constexpr ReferenceName referenceNames[] = { { GEReferenceIndex::TEXADDR7, "texaddr7" }, }; +enum class GECmdField : uint8_t { + DATA, // Alias for the entire data. + LOW_FLAG, + LOW_U2, + LOW_U4, + LOW_U7, + LOW_U8, + LOW_U10, + LOW_U10_P1, + LOW_U11, + LOW_U16, + MID_U8, + MID_U10, // At 10, 10 bits. + MID_U10_P1, // At 10, 10 bits (add 1 to value.) + TOP_U8, + FLAG_AFTER_1, // At 1, 1 bit. + FLAG_AFTER_2, // At 2, 1 bit. + FLAG_AFTER_8, // At 8, 1 bit. + FLAG_AFTER_9, // At 9, 1 bit. + FLAG_AFTER_10, // At 10, 1 bit. + FLAG_AFTER_11, // At 11, 1 bit. + FLAG_AFTER_16, // At 16, 1 bit. + FLAG_AFTER_18, // At 18, 1 bit. + FLAG_AFTER_19, // At 19, 1 bit. + FLAG_AFTER_20, // At 20, 1 bit. + FLAG_AFTER_21, // At 21, 1 bit. + FLAG_AFTER_22, // At 22, 1 bit. + FLAG_AFTER_23, // At 23, 1 bit. + U2_AFTER_8, // At 8, 2 bits. + U3_AFTER_16, // At 16, 3 bits. + U12_AFTER_4, // At 4, 12 bits. + PRIM_TYPE, // At 16, 3 bits. + SPLINE_UTYPE, // At 16, 2 bits. + SPLINE_VTYPE, // At 18, 2 bits. + SIGNAL_TYPE, // At 16, 8 bits. + VTYPE_TC, // At 0, 2 bits. + VTYPE_COL, // At 2, 3 bits. + VTYPE_NRM, // At 5, 2 bits. + VTYPE_POS, // At 7, 2 bits. + VTYPE_WEIGHTTYPE, // At 9, 2 bits. + VTYPE_INDEX, // At 11, 2 bits. + VTYPE_WEIGHTCOUNT, // At 14, 3 bits. + VTYPE_MORPHCOUNT, // At 18, 3 bits. + PATCH_PRIM_TYPE, // At 0, 2 bits. + LIGHT_COMP, // At 0, 2 bits. + LIGHT_TYPE, // At 8, 2 bits. + LIGHT_TYPE_SPECULAR, // 1 if comp is 1 (but not 3.) + HIGH_ADDR, // At 16, 8 bits moved left to top 8 bits. + TEX_W, // At 0, 4 bits - 1 to this power. + TEX_H, // At 8, 4 bits - 1 to this power. + UVGEN_TYPE, // At 0, 2 bits. + UVGEN_PROJ, // At 8, 2 bits. + TEX_FORMAT, // At 0, 4 bits. + TEX_MINFILTER, // At 0, 3 bits. + TEX_MAGFILTER, // At 8, 1 bit. + TEX_LEVEL_MODE, // At 0, 2 bits. + LOW_U12_4_FLOAT, // At 0, 12.4 converted to float. + HIGH_S4_4_FLOAT, // At 16, s.3.4 converted to float. + TEX_FUNC, // At 0, 3 bits. + CLUT_BYTES, // At 0, 6 bits, multiplied by 8. + CLUT_FORMAT, // At 0, 2 bits. + CLUT_SHIFT, // At 2, 5 bits. + CLUT_OFFSET, // At 16, 5 bits, multiplied by 16. + COMPARE_FUNC2, // At 0, 2 bits. + COMPARE_FUNC3, // At 0, 3 bits. + STENCIL_OP_AT_0, // At 0, 3 bits. + STENCIL_OP_AT_8, // At 8, 3 bits. + STENCIL_OP_AT_16, // At 16, 3 bits. + BLEND_SRC, // At 0, 4 bits. + BLEND_DST, // At 4, 4 bits. + BLEND_EQUATION, // At 8, 3 bits. + LOGIC_OP, // At 0, 4 bits. +}; + +struct FieldName { + GECmdFormat fmt; + GECmdField field; + const char *name; +}; + +static constexpr FieldName fieldNames[] = { + { GECmdFormat::PRIM, GECmdField::LOW_U16, "count" }, + { GECmdFormat::PRIM, GECmdField::PRIM_TYPE, "type" }, + { GECmdFormat::BEZIER, GECmdField::LOW_U8, "ucount" }, + { GECmdFormat::BEZIER, GECmdField::LOW_U8, "u" }, + { GECmdFormat::BEZIER, GECmdField::MID_U8, "vcount" }, + { GECmdFormat::BEZIER, GECmdField::MID_U8, "v" }, + { GECmdFormat::SPLINE, GECmdField::LOW_U8, "ucount" }, + { GECmdFormat::SPLINE, GECmdField::LOW_U8, "u" }, + { GECmdFormat::SPLINE, GECmdField::MID_U8, "vcount" }, + { GECmdFormat::SPLINE, GECmdField::MID_U8, "v" }, + { GECmdFormat::SPLINE, GECmdField::SPLINE_UTYPE, "utype" }, + { GECmdFormat::SPLINE, GECmdField::SPLINE_VTYPE, "vtype" }, + { GECmdFormat::SIGNAL, GECmdField::LOW_U16, "data" }, + { GECmdFormat::SIGNAL, GECmdField::SIGNAL_TYPE, "type" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_TC, "texcoord" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_TC, "tc" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_COL, "col" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_COL, "color" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_NRM, "normal" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_POS, "pos" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_POS, "position" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_WEIGHTTYPE, "weighttype" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_WEIGHTTYPE, "weight" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_INDEX, "index" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_WEIGHTCOUNT, "weightcount" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_MORPHCOUNT, "morphcount" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::FLAG_AFTER_23, "through" }, + { GECmdFormat::VERTEX_TYPE, GECmdField::FLAG_AFTER_23, "throughmode" }, + { GECmdFormat::X10_Y10, GECmdField::LOW_U10, "x" }, + { GECmdFormat::X10_Y10, GECmdField::MID_U10, "y" }, + { GECmdFormat::X10_Y10, GECmdField::LOW_U10_P1, "w" }, + { GECmdFormat::X10_Y10, GECmdField::MID_U10_P1, "h" }, + { GECmdFormat::FLAG, GECmdField::LOW_FLAG, "flag" }, + { GECmdFormat::BONE_NUM, GECmdField::LOW_U7, "num" }, + { GECmdFormat::MATRIX_NUM, GECmdField::LOW_U4, "num" }, + { GECmdFormat::FLOAT, GECmdField::DATA, "data" }, + { GECmdFormat::PATCH_DIVISION, GECmdField::LOW_U8, "u" }, + { GECmdFormat::PATCH_DIVISION, GECmdField::MID_U8, "v" }, + { GECmdFormat::PATCH_PRIM, GECmdField::PATCH_PRIM_TYPE, "type" }, + { GECmdFormat::SUBPIXEL_COORD, GECmdField::LOW_U4, "frac" }, + { GECmdFormat::SUBPIXEL_COORD, GECmdField::LOW_U4, "sub" }, + { GECmdFormat::SUBPIXEL_COORD, GECmdField::LOW_U4, "subpixels" }, + { GECmdFormat::SUBPIXEL_COORD, GECmdField::U12_AFTER_4, "int" }, + { GECmdFormat::SUBPIXEL_COORD, GECmdField::U12_AFTER_4, "integer" }, + { GECmdFormat::SUBPIXEL_COORD, GECmdField::LOW_U12_4_FLOAT, "pixels" }, + { GECmdFormat::MATERIAL_UPDATE, GECmdField::LOW_FLAG, "ambient" }, + { GECmdFormat::MATERIAL_UPDATE, GECmdField::FLAG_AFTER_1, "diffuse" }, + { GECmdFormat::MATERIAL_UPDATE, GECmdField::FLAG_AFTER_2, "specular" }, + { GECmdFormat::RGB, GECmdField::LOW_U8, "r" }, + { GECmdFormat::RGB, GECmdField::LOW_U8, "red" }, + { GECmdFormat::RGB, GECmdField::MID_U8, "g" }, + { GECmdFormat::RGB, GECmdField::MID_U8, "green" }, + { GECmdFormat::RGB, GECmdField::TOP_U8, "b" }, + { GECmdFormat::RGB, GECmdField::TOP_U8, "blue" }, + { GECmdFormat::LIGHT_TYPE, GECmdField::LIGHT_COMP, "computation" }, + { GECmdFormat::LIGHT_TYPE, GECmdField::LIGHT_TYPE, "type" }, + { GECmdFormat::LIGHT_TYPE, GECmdField::LIGHT_TYPE_SPECULAR, "specular" }, + { GECmdFormat::STRIDE, GECmdField::LOW_U11, "stride" }, + { GECmdFormat::STRIDE_HIGH_ADDR, GECmdField::HIGH_ADDR, "highaddr" }, + { GECmdFormat::HIGH_ADDR, GECmdField::HIGH_ADDR, "highaddr" }, + { GECmdFormat::HIGH_ADDR_ONLY, GECmdField::HIGH_ADDR, "highaddr" }, + { GECmdFormat::TEX_SIZE, GECmdField::TEX_W, "w" }, + { GECmdFormat::TEX_SIZE, GECmdField::TEX_W, "width" }, + { GECmdFormat::TEX_SIZE, GECmdField::TEX_H, "h" }, + { GECmdFormat::TEX_SIZE, GECmdField::TEX_H, "height" }, + { GECmdFormat::TEX_MAP_MODE, GECmdField::UVGEN_TYPE, "type" }, + { GECmdFormat::TEX_MAP_MODE, GECmdField::UVGEN_TYPE, "uv" }, + { GECmdFormat::TEX_MAP_MODE, GECmdField::UVGEN_PROJ, "proj" }, + { GECmdFormat::TEX_MAP_MODE, GECmdField::UVGEN_PROJ, "factor" }, + { GECmdFormat::TEX_LIGHT_SRC, GECmdField::LOW_U2, "u" }, + { GECmdFormat::TEX_LIGHT_SRC, GECmdField::U2_AFTER_8, "v" }, + { GECmdFormat::TEX_MODE, GECmdField::LOW_FLAG, "swizzle" }, + { GECmdFormat::TEX_MODE, GECmdField::FLAG_AFTER_8, "separateclut" }, + { GECmdFormat::TEX_MODE, GECmdField::FLAG_AFTER_8, "separate" }, + { GECmdFormat::TEX_MODE, GECmdField::U3_AFTER_16, "maxlevel" }, + { GECmdFormat::TEX_MODE, GECmdField::U3_AFTER_16, "level" }, + { GECmdFormat::TEX_FORMAT, GECmdField::TEX_FORMAT, "format" }, + { GECmdFormat::TEX_FORMAT, GECmdField::TEX_FORMAT, "fmt" }, + { GECmdFormat::TEX_FORMAT, GECmdField::FLAG_AFTER_2, "indexed" }, + { GECmdFormat::TEX_FILTER, GECmdField::TEX_MINFILTER, "min" }, + { GECmdFormat::TEX_FILTER, GECmdField::TEX_MINFILTER, "minify" }, + { GECmdFormat::TEX_FILTER, GECmdField::TEX_MAGFILTER, "mag" }, + { GECmdFormat::TEX_FILTER, GECmdField::TEX_MAGFILTER, "magnify" }, + { GECmdFormat::TEX_CLAMP, GECmdField::LOW_FLAG, "s" }, + { GECmdFormat::TEX_CLAMP, GECmdField::FLAG_AFTER_8, "t" }, + { GECmdFormat::TEX_LEVEL_MODE, GECmdField::TEX_LEVEL_MODE, "mode" }, + { GECmdFormat::TEX_LEVEL_MODE, GECmdField::HIGH_S4_4_FLOAT, "bias" }, + { GECmdFormat::TEX_FUNC, GECmdField::TEX_FUNC, "func" }, + { GECmdFormat::TEX_FUNC, GECmdField::TEX_FUNC, "function" }, + { GECmdFormat::TEX_FUNC, GECmdField::FLAG_AFTER_8, "alpha" }, + { GECmdFormat::TEX_FUNC, GECmdField::FLAG_AFTER_8, "a" }, + { GECmdFormat::TEX_FUNC, GECmdField::FLAG_AFTER_16, "double" }, + { GECmdFormat::TEX_FUNC, GECmdField::FLAG_AFTER_16, "doubling" }, + { GECmdFormat::CLUT_FORMAT, GECmdField::CLUT_FORMAT, "format" }, + { GECmdFormat::CLUT_FORMAT, GECmdField::CLUT_FORMAT, "fmt" }, + { GECmdFormat::CLUT_FORMAT, GECmdField::CLUT_SHIFT, "shift" }, + { GECmdFormat::CLUT_FORMAT, GECmdField::MID_U8, "mask" }, + { GECmdFormat::CLUT_FORMAT, GECmdField::CLUT_OFFSET, "offset" }, + { GECmdFormat::CLUT_FORMAT, GECmdField::CLUT_OFFSET, "base" }, + { GECmdFormat::CLEAR_MODE, GECmdField::LOW_FLAG, "on" }, + { GECmdFormat::CLEAR_MODE, GECmdField::LOW_FLAG, "enable" }, + { GECmdFormat::CLEAR_MODE, GECmdField::LOW_FLAG, "flag" }, + { GECmdFormat::CLEAR_MODE, GECmdField::FLAG_AFTER_8, "color" }, + { GECmdFormat::CLEAR_MODE, GECmdField::FLAG_AFTER_9, "alpha" }, + { GECmdFormat::CLEAR_MODE, GECmdField::FLAG_AFTER_9, "stencil" }, + { GECmdFormat::CLEAR_MODE, GECmdField::FLAG_AFTER_10, "depth" }, + { GECmdFormat::COLOR_TEST_FUNC, GECmdField::COMPARE_FUNC2, "func" }, + { GECmdFormat::ALPHA_TEST, GECmdField::COMPARE_FUNC3, "func" }, + { GECmdFormat::ALPHA_TEST, GECmdField::MID_U8, "ref" }, + { GECmdFormat::ALPHA_TEST, GECmdField::MID_U8, "reference" }, + { GECmdFormat::ALPHA_TEST, GECmdField::TOP_U8, "mask" }, + { GECmdFormat::STENCIL_OP, GECmdField::STENCIL_OP_AT_0, "sfail" }, + { GECmdFormat::STENCIL_OP, GECmdField::STENCIL_OP_AT_8, "zfail" }, + { GECmdFormat::STENCIL_OP, GECmdField::STENCIL_OP_AT_16, "zpass" }, + { GECmdFormat::STENCIL_OP, GECmdField::STENCIL_OP_AT_16, "pass" }, + { GECmdFormat::DEPTH_TEST_FUNC, GECmdField::COMPARE_FUNC3, "func" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_SRC, "src" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_SRC, "srcfactor" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_DST, "dst" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_DST, "dstfactor" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_DST, "dest" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_DST, "destfactor" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_EQUATION, "eq" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_EQUATION, "equation" }, + { GECmdFormat::BLEND_MODE, GECmdField::BLEND_EQUATION, "mode" }, + { GECmdFormat::LOGIC_OP, GECmdField::LOGIC_OP, "op" }, + { GECmdFormat::LOGIC_OP, GECmdField::LOGIC_OP, "mode" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::LOW_U8, "alpha" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::PRIM_TYPE, "type" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::PRIM_TYPE, "prim" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_11, "antialias" }, + // TODO: Clip bits? + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_18, "shading" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_18, "gouraud" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_19, "cull" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_20, "cullccw" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_21, "tex" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_22, "fog" }, + { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_23, "dither" }, +}; + class GEExpressionFunctions : public IExpressionFunctions { public: GEExpressionFunctions(GPUDebugInterface *gpu) : gpu_(gpu) {} @@ -92,6 +317,10 @@ public: bool getMemoryValue(uint32_t address, int size, uint32_t &dest, char *error) override; private: + bool parseFieldReference(const char *ref, const char *field, uint32_t &referenceIndex); + uint32_t getFieldValue(GECmdFormat fmt, GECmdField field, uint32_t value); + ExpressionType getFieldType(GECmdFormat fmt, GECmdField field); + GPUDebugInterface *gpu_; }; @@ -104,6 +333,15 @@ bool GEExpressionFunctions::parseReference(char *str, uint32_t &referenceIndex) return true; } + char *dot = strchr(str, '.'); + if (dot != nullptr) { + *dot = '\0'; + bool success = parseFieldReference(str, dot + 1, referenceIndex); + *dot = '.'; + if (success) + return true; + } + // Also allow non-register references. for (const auto &entry : referenceNames) { if (strcasecmp(str, entry.name) == 0) { @@ -150,6 +388,22 @@ bool GEExpressionFunctions::parseReference(char *str, uint32_t &referenceIndex) return false; } +bool GEExpressionFunctions::parseFieldReference(const char *ref, const char *field, uint32_t &referenceIndex) { + GECmdInfo info; + if (!GECmdInfoByName(ref, info)) { + return false; + } + + for (const auto &entry : fieldNames) { + if (entry.fmt == info.fmt && strcasecmp(field, entry.name) == 0) { + referenceIndex = (info.reg << 12) | (uint32_t)entry.field; + return true; + } + } + + return false; +} + bool GEExpressionFunctions::parseSymbol(char *str, uint32_t &symbolValue) { // Mainly useful for checking memory addresses. return g_symbolMap->GetLabelValue(str, symbolValue); @@ -158,11 +412,19 @@ bool GEExpressionFunctions::parseSymbol(char *str, uint32_t &symbolValue) { uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) { GPUgstate state = gpu_->GetGState(); if (referenceIndex < 0x100) { + GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex)).fmt; uint32_t value = state.cmdmem[referenceIndex]; - // TODO: Later, support float values and similar. + if (fmt == GECmdFormat::FLOAT) + return value << 8; return value & 0x00FFFFFF; } + if (referenceIndex >= (uint32_t)GEReferenceIndex::FIELD_START && referenceIndex <= (uint32_t)GEReferenceIndex::FIELD_END) { + uint32_t value = state.cmdmem[referenceIndex >> 12] & 0x00FFFFFF; + GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex >> 12)).fmt; + return getFieldValue(fmt, GECmdField(referenceIndex & 0xFF), value); + } + // We return the matrix value as float bits, which gets interpreted correctly in the parser. if (referenceIndex >= (uint32_t)GEReferenceIndex::BONE_MATRIX && referenceIndex < (uint32_t)GEReferenceIndex::MATRIX_END) { float value; @@ -209,7 +471,6 @@ uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) { } return 0; case GEReferenceIndex::OP: - // TODO: Support fields under this as per the cmd format? if (gpu_->GetCurrentDisplayList(list)) { return Memory::Read_U32(list.pc); } @@ -245,6 +506,8 @@ uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) { case GEReferenceIndex::PROJ_MATRIX: case GEReferenceIndex::TGEN_MATRIX: case GEReferenceIndex::MATRIX_END: + case GEReferenceIndex::FIELD_START: + case GEReferenceIndex::FIELD_END: // Shouldn't have gotten here. break; } @@ -253,17 +516,202 @@ uint32_t GEExpressionFunctions::getReferenceValue(uint32_t referenceIndex) { return 0; } +uint32_t GEExpressionFunctions::getFieldValue(GECmdFormat fmt, GECmdField field, uint32_t value) { + switch (field) { + case GECmdField::DATA: + return value; + case GECmdField::LOW_FLAG: + return value & 1; + case GECmdField::LOW_U2: + return value & 3; + case GECmdField::LOW_U4: + return value & 0xF; + case GECmdField::LOW_U7: + return value & 0x7F; + case GECmdField::LOW_U8: + return value & 0xFF; + case GECmdField::LOW_U10: + return value & 0x03FF; + case GECmdField::LOW_U10_P1: + return (value & 0x03FF) + 1; + case GECmdField::LOW_U11: + return value & 0x07FF; + case GECmdField::LOW_U16: + return value & 0xFFFF; + case GECmdField::MID_U8: + return (value >> 8) & 0xFF; + case GECmdField::MID_U10: + return (value >> 10) & 0x03FF; + case GECmdField::MID_U10_P1: + return ((value >> 10) & 0x03FF) + 1; + case GECmdField::TOP_U8: + return (value >> 16) & 0xFF; + case GECmdField::FLAG_AFTER_1: + return (value >> 1) & 1; + case GECmdField::FLAG_AFTER_2: + return (value >> 2) & 1; + case GECmdField::FLAG_AFTER_8: + return (value >> 8) & 1; + case GECmdField::FLAG_AFTER_9: + return (value >> 8) & 1; + case GECmdField::FLAG_AFTER_10: + return (value >> 10) & 1; + case GECmdField::FLAG_AFTER_11: + return (value >> 11) & 1; + case GECmdField::FLAG_AFTER_16: + return (value >> 16) & 1; + case GECmdField::FLAG_AFTER_18: + return (value >> 18) & 1; + case GECmdField::FLAG_AFTER_19: + return (value >> 19) & 1; + case GECmdField::FLAG_AFTER_20: + return (value >> 20) & 1; + case GECmdField::FLAG_AFTER_21: + return (value >> 21) & 1; + case GECmdField::FLAG_AFTER_22: + return (value >> 22) & 1; + case GECmdField::FLAG_AFTER_23: + return (value >> 23) & 1; + case GECmdField::U2_AFTER_8: + return (value >> 8) & 3; + case GECmdField::U3_AFTER_16: + return (value >> 16) & 7; + case GECmdField::U12_AFTER_4: + return (value >> 4) & 0x0FFF; + + // Below here are "typed" values, maybe they'll be exposed differently than integers someday. + + case GECmdField::PRIM_TYPE: + return (value >> 16) & 7; + case GECmdField::SPLINE_UTYPE: + return (value >> 16) & 3; + case GECmdField::SPLINE_VTYPE: + return (value >> 18) & 3; + case GECmdField::SIGNAL_TYPE: + return (value >> 16) & 0xFF; + case GECmdField::VTYPE_TC: + return value & 3; + case GECmdField::VTYPE_COL: + return (value >> 2) & 7; + case GECmdField::VTYPE_NRM: + return (value >> 5) & 3; + case GECmdField::VTYPE_POS: + return (value >> 7) & 3; + case GECmdField::VTYPE_WEIGHTTYPE: + return (value >> 9) & 3; + case GECmdField::VTYPE_INDEX: + return (value >> 11) & 3; + case GECmdField::VTYPE_WEIGHTCOUNT: + return ((value >> 14) & 7) + 1; + case GECmdField::VTYPE_MORPHCOUNT: + return ((value >> 18) & 7) + 1; + case GECmdField::PATCH_PRIM_TYPE: + return value & 3; + case GECmdField::LIGHT_COMP: + return value & 3; + case GECmdField::LIGHT_TYPE: + return (value >> 8) & 3; + case GECmdField::LIGHT_TYPE_SPECULAR: + return (value & 3) == 1; + case GECmdField::HIGH_ADDR: + return (value << 8) & 0xFF000000; + case GECmdField::TEX_W: + return 1 << (value & 0xF); + case GECmdField::TEX_H: + return 1 << ((value >> 8) & 0xF); + case GECmdField::UVGEN_TYPE: + return value & 3; + case GECmdField::UVGEN_PROJ: + return (value >> 8) & 3; + case GECmdField::TEX_FORMAT: + return value & 0xF; + case GECmdField::TEX_MINFILTER: + return value & 7; + case GECmdField::TEX_MAGFILTER: + return (value >> 8) & 1; + case GECmdField::TEX_LEVEL_MODE: + return value & 3; + case GECmdField::LOW_U12_4_FLOAT: + { + float f = (value & 0xFFFF) / 16.0f; + uint32_t result; + memcpy(&result, &f, sizeof(result)); + return result; + } + case GECmdField::HIGH_S4_4_FLOAT: // At 16, s.3.4 converted to float. + { + int value8 = (int)(s8)((value >> 16) & 0xFF); + float f = value8 / 16.0f; + uint32_t result; + memcpy(&result, &f, sizeof(result)); + return result; + } + case GECmdField::TEX_FUNC: + return value & 7; + case GECmdField::CLUT_BYTES: + return (value & 0x3F) * 8; + case GECmdField::CLUT_FORMAT: + return value & 3; + case GECmdField::CLUT_SHIFT: + return (value >> 2) & 0x1F; + case GECmdField::CLUT_OFFSET: + return ((value >> 16) & 0x1F) << 4; + case GECmdField::COMPARE_FUNC2: + return value & 3; + case GECmdField::COMPARE_FUNC3: + return value & 7; + case GECmdField::STENCIL_OP_AT_0: + return value & 7; + case GECmdField::STENCIL_OP_AT_8: + return (value >> 8) & 7; + case GECmdField::STENCIL_OP_AT_16: + return (value >> 16) & 7; + case GECmdField::BLEND_SRC: + return value & 0xF; + case GECmdField::BLEND_DST: + return (value >> 4) & 0xF; + case GECmdField::BLEND_EQUATION: + return (value >> 8) & 7; + case GECmdField::LOGIC_OP: + return value & 0xF; + } + + _assert_msg_(false, "Invalid field type"); + return 0; +} + ExpressionType GEExpressionFunctions::getReferenceType(uint32_t referenceIndex) { if (referenceIndex < 0x100) { - // TODO: Later, support float values and similar. + GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex)).fmt; + if (fmt == GECmdFormat::FLOAT) + return EXPR_TYPE_FLOAT; return EXPR_TYPE_UINT; } + if (referenceIndex >= (uint32_t)GEReferenceIndex::FIELD_START && referenceIndex <= (uint32_t)GEReferenceIndex::FIELD_END) { + GECmdFormat fmt = GECmdInfoByCmd(GECommand(referenceIndex >> 12)).fmt; + return getFieldType(fmt, GECmdField(referenceIndex & 0xFF)); + } + if (referenceIndex >= (uint32_t)GEReferenceIndex::BONE_MATRIX && referenceIndex < (uint32_t)GEReferenceIndex::MATRIX_END) return EXPR_TYPE_FLOAT; return EXPR_TYPE_UINT; } +ExpressionType GEExpressionFunctions::getFieldType(GECmdFormat fmt, GECmdField field) { + switch (field) { + case GECmdField::LOW_U12_4_FLOAT: + case GECmdField::HIGH_S4_4_FLOAT: + return EXPR_TYPE_FLOAT; + + default: + // Almost all of these are uint, so not listing each one. + break; + } + + return EXPR_TYPE_UINT; +} + bool GEExpressionFunctions::getMemoryValue(uint32_t address, int size, uint32_t &dest, char *error) { if (!Memory::IsValidRange(address, size)) { sprintf(error, "Invalid address or size %08x + %d", address, size); diff --git a/GPU/Debugger/GECommandTable.h b/GPU/Debugger/GECommandTable.h index 95b4eddf0f..01d2059079 100644 --- a/GPU/Debugger/GECommandTable.h +++ b/GPU/Debugger/GECommandTable.h @@ -48,7 +48,7 @@ enum class GECmdFormat { STRIDE, // 11 bits. STRIDE_HIGH_ADDR, // 11 bits stride, 5 ignored, 8 bits high address. TEX_SIZE, // 4 bits width power, 4 bits ignored, 4 bits height power. - TEX_MAP_MODE, // 8 bits mode (2 bits), 2 bits environment factor. + TEX_MAP_MODE, // 8 bits mode (2 bits), 2 bits matrix factor. TEX_LIGHT_SRC, // 8 bits lightu (2 bits), 2 bits lightv. TEX_MODE, // 8 bits swizzle (1 bit), 8 bits separate clut4 (1 bit), 3 bits max level. TEX_FORMAT, // 4 bits format. From f02e6b8e399b34ec2392be6e454844a08243852d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 13:51:10 -0700 Subject: [PATCH 56/69] GE Debugger: Add some constants to expressions. Hard to remember, but at least can be copy/pasted. Allows for things like "alphatest.func == GREATER". --- GPU/Common/GPUDebugInterface.cpp | 221 +++++++++++++++++++++++++++++-- 1 file changed, 212 insertions(+), 9 deletions(-) diff --git a/GPU/Common/GPUDebugInterface.cpp b/GPU/Common/GPUDebugInterface.cpp index 34cb050ffd..1f7d04369e 100644 --- a/GPU/Common/GPUDebugInterface.cpp +++ b/GPU/Common/GPUDebugInterface.cpp @@ -106,6 +106,7 @@ enum class GECmdField : uint8_t { FLAG_AFTER_10, // At 10, 1 bit. FLAG_AFTER_11, // At 11, 1 bit. FLAG_AFTER_16, // At 16, 1 bit. + FLAG_AFTER_17, // At 17, 1 bit. FLAG_AFTER_18, // At 18, 1 bit. FLAG_AFTER_19, // At 19, 1 bit. FLAG_AFTER_20, // At 20, 1 bit. @@ -116,8 +117,6 @@ enum class GECmdField : uint8_t { U3_AFTER_16, // At 16, 3 bits. U12_AFTER_4, // At 4, 12 bits. PRIM_TYPE, // At 16, 3 bits. - SPLINE_UTYPE, // At 16, 2 bits. - SPLINE_VTYPE, // At 18, 2 bits. SIGNAL_TYPE, // At 16, 8 bits. VTYPE_TC, // At 0, 2 bits. VTYPE_COL, // At 2, 3 bits. @@ -175,8 +174,10 @@ static constexpr FieldName fieldNames[] = { { GECmdFormat::SPLINE, GECmdField::LOW_U8, "u" }, { GECmdFormat::SPLINE, GECmdField::MID_U8, "vcount" }, { GECmdFormat::SPLINE, GECmdField::MID_U8, "v" }, - { GECmdFormat::SPLINE, GECmdField::SPLINE_UTYPE, "utype" }, - { GECmdFormat::SPLINE, GECmdField::SPLINE_VTYPE, "vtype" }, + { GECmdFormat::SPLINE, GECmdField::FLAG_AFTER_16, "ufirstopen" }, + { GECmdFormat::SPLINE, GECmdField::FLAG_AFTER_17, "ulastopen" }, + { GECmdFormat::SPLINE, GECmdField::FLAG_AFTER_18, "vfirstopen" }, + { GECmdFormat::SPLINE, GECmdField::FLAG_AFTER_19, "vlastopen" }, { GECmdFormat::SIGNAL, GECmdField::LOW_U16, "data" }, { GECmdFormat::SIGNAL, GECmdField::SIGNAL_TYPE, "type" }, { GECmdFormat::VERTEX_TYPE, GECmdField::VTYPE_TC, "texcoord" }, @@ -306,6 +307,202 @@ static constexpr FieldName fieldNames[] = { { GECmdFormat::ALPHA_PRIM, GECmdField::FLAG_AFTER_23, "dither" }, }; +struct GECmdConstant { + const char *name; + uint32_t value; +}; + +// TODO: It would be nice if these were somehow typed... +static constexpr GECmdConstant constantNames[] = { + { "GE_PRIM_POINTS", GE_PRIM_POINTS }, + { "GE_PRIM_LINES", GE_PRIM_LINES }, + { "GE_PRIM_LINE_STRIP", GE_PRIM_LINE_STRIP }, + { "GE_PRIM_TRIANGLES", GE_PRIM_TRIANGLES }, + { "GE_PRIM_TRIANGLE_STRIP", GE_PRIM_TRIANGLE_STRIP }, + { "GE_PRIM_TRIANGLE_FAN", GE_PRIM_TRIANGLE_FAN }, + { "GE_PRIM_RECTANGLES", GE_PRIM_RECTANGLES }, + { "GE_PRIM_KEEP_PREVIOUS", GE_PRIM_KEEP_PREVIOUS }, + { "POINTS", GE_PRIM_POINTS }, + { "LINES", GE_PRIM_LINES }, + { "LINE_STRIP", GE_PRIM_LINE_STRIP }, + { "TRIANGLES", GE_PRIM_TRIANGLES }, + { "TRIANGLE_STRIP", GE_PRIM_TRIANGLE_STRIP }, + { "TRIANGLE_FAN", GE_PRIM_TRIANGLE_FAN }, + { "RECTANGLES", GE_PRIM_RECTANGLES }, + { "SPRITES", GE_PRIM_RECTANGLES }, + { "KEEP_PREVIOUS", GE_PRIM_KEEP_PREVIOUS }, + { "CONTINUE", GE_PRIM_KEEP_PREVIOUS }, + { "GE_PATCHPRIM_TRIANGLES", GE_PATCHPRIM_TRIANGLES, }, + { "GE_PATCHPRIM_LINES", GE_PATCHPRIM_LINES, }, + { "GE_PATCHPRIM_POINTS", GE_PATCHPRIM_POINTS, }, + { "GE_SIGNAL_NONE", PSP_GE_SIGNAL_NONE }, + { "GE_SIGNAL_HANDLER_SUSPEND", PSP_GE_SIGNAL_HANDLER_SUSPEND }, + { "GE_SIGNAL_HANDLER_CONTINUE", PSP_GE_SIGNAL_HANDLER_CONTINUE }, + { "GE_SIGNAL_HANDLER_PAUSE", PSP_GE_SIGNAL_HANDLER_PAUSE }, + { "GE_SIGNAL_SYNC", PSP_GE_SIGNAL_SYNC }, + { "GE_SIGNAL_JUMP", PSP_GE_SIGNAL_JUMP }, + { "GE_SIGNAL_CALL", PSP_GE_SIGNAL_CALL }, + { "GE_SIGNAL_RET", PSP_GE_SIGNAL_RET }, + { "GE_SIGNAL_RJUMP", PSP_GE_SIGNAL_RJUMP }, + { "GE_SIGNAL_RCALL", PSP_GE_SIGNAL_RCALL }, + { "GE_SIGNAL_OJUMP", PSP_GE_SIGNAL_OJUMP }, + { "GE_SIGNAL_OCALL", PSP_GE_SIGNAL_OCALL }, + { "GE_VTYPE_TC_NONE", GE_VTYPE_TC_NONE >> GE_VTYPE_TC_SHIFT }, + { "GE_VTYPE_TC_8BIT", GE_VTYPE_TC_8BIT >> GE_VTYPE_TC_SHIFT }, + { "GE_VTYPE_TC_16BIT", GE_VTYPE_TC_16BIT >> GE_VTYPE_TC_SHIFT }, + { "GE_VTYPE_TC_FLOAT", GE_VTYPE_TC_FLOAT >> GE_VTYPE_TC_SHIFT }, + { "GE_VTYPE_COL_NONE", GE_VTYPE_COL_NONE >> GE_VTYPE_COL_SHIFT }, + { "GE_VTYPE_COL_565", GE_VTYPE_COL_565 >> GE_VTYPE_COL_SHIFT }, + { "GE_VTYPE_COL_5650", GE_VTYPE_COL_565 >> GE_VTYPE_COL_SHIFT }, + { "GE_VTYPE_COL_5551", GE_VTYPE_COL_5551 >> GE_VTYPE_COL_SHIFT }, + { "GE_VTYPE_COL_4444", GE_VTYPE_COL_4444 >> GE_VTYPE_COL_SHIFT }, + { "GE_VTYPE_COL_8888", GE_VTYPE_COL_8888 >> GE_VTYPE_COL_SHIFT }, + { "GE_VTYPE_NRM_NONE", GE_VTYPE_NRM_NONE >> GE_VTYPE_NRM_SHIFT }, + { "GE_VTYPE_NRM_8BIT", GE_VTYPE_NRM_8BIT >> GE_VTYPE_NRM_SHIFT }, + { "GE_VTYPE_NRM_16BIT", GE_VTYPE_NRM_16BIT >> GE_VTYPE_NRM_SHIFT }, + { "GE_VTYPE_NRM_FLOAT", GE_VTYPE_NRM_FLOAT >> GE_VTYPE_NRM_SHIFT }, + { "GE_VTYPE_POS_8BIT", GE_VTYPE_POS_8BIT >> GE_VTYPE_POS_SHIFT }, + { "GE_VTYPE_POS_16BIT", GE_VTYPE_POS_16BIT >> GE_VTYPE_POS_SHIFT }, + { "GE_VTYPE_POS_FLOAT", GE_VTYPE_POS_FLOAT >> GE_VTYPE_POS_SHIFT }, + { "GE_VTYPE_WEIGHT_NONE", GE_VTYPE_WEIGHT_NONE >> GE_VTYPE_WEIGHT_SHIFT }, + { "GE_VTYPE_WEIGHT_8BIT", GE_VTYPE_WEIGHT_8BIT >> GE_VTYPE_WEIGHT_SHIFT }, + { "GE_VTYPE_WEIGHT_16BIT", GE_VTYPE_WEIGHT_16BIT >> GE_VTYPE_WEIGHT_SHIFT }, + { "GE_VTYPE_WEIGHT_FLOAT", GE_VTYPE_WEIGHT_FLOAT >> GE_VTYPE_WEIGHT_SHIFT }, + { "GE_VTYPE_IDX_NONE", GE_VTYPE_IDX_NONE >> GE_VTYPE_IDX_SHIFT }, + { "GE_VTYPE_IDX_8BIT", GE_VTYPE_IDX_8BIT >> GE_VTYPE_IDX_SHIFT }, + { "GE_VTYPE_IDX_16BIT", GE_VTYPE_IDX_16BIT >> GE_VTYPE_IDX_SHIFT }, + { "GE_VTYPE_IDX_32BIT", GE_VTYPE_IDX_32BIT >> GE_VTYPE_IDX_SHIFT }, + { "GE_LIGHTCOMP_ONLYDIFFUSE", GE_LIGHTCOMP_ONLYDIFFUSE }, + { "GE_LIGHTCOMP_BOTH", GE_LIGHTCOMP_BOTH }, + { "GE_LIGHTCOMP_ONLYPOWDIFFUSE", GE_LIGHTCOMP_ONLYPOWDIFFUSE }, + { "GE_LIGHTTYPE_DIRECTIONAL", GE_LIGHTTYPE_DIRECTIONAL }, + { "GE_LIGHTTYPE_POINT", GE_LIGHTTYPE_POINT }, + { "GE_LIGHTTYPE_SPOT", GE_LIGHTTYPE_SPOT }, + { "GE_TEXMAP_TEXTURE_COORDS", GE_TEXMAP_TEXTURE_COORDS }, + { "GE_TEXMAP_TEXTURE_MATRIX", GE_TEXMAP_TEXTURE_MATRIX }, + { "GE_TEXMAP_ENVIRONMENT_MAP", GE_TEXMAP_ENVIRONMENT_MAP }, + { "GE_PROJMAP_POSITION", GE_PROJMAP_POSITION }, + { "GE_PROJMAP_UV", GE_PROJMAP_UV }, + { "GE_PROJMAP_NORMALIZED_NORMAL", GE_PROJMAP_NORMALIZED_NORMAL }, + { "GE_PROJMAP_NORMAL", GE_PROJMAP_NORMAL }, + { "GE_TFMT_565", GE_TFMT_5650 }, + { "GE_TFMT_5650", GE_TFMT_5650 }, + { "GE_TFMT_5551", GE_TFMT_5551 }, + { "GE_TFMT_4444", GE_TFMT_4444 }, + { "GE_TFMT_8888", GE_TFMT_8888 }, + { "GE_TFMT_CLUT4", GE_TFMT_CLUT4 }, + { "GE_TFMT_CLUT8", GE_TFMT_CLUT8 }, + { "GE_TFMT_CLUT16", GE_TFMT_CLUT16 }, + { "GE_TFMT_CLUT32", GE_TFMT_CLUT32 }, + { "GE_TFMT_DXT1", GE_TFMT_DXT1 }, + { "GE_TFMT_DXT3", GE_TFMT_DXT3 }, + { "GE_TFMT_DXT5", GE_TFMT_DXT5 }, + { "GE_CMODE_16BIT_BGR5650", GE_CMODE_16BIT_BGR5650 }, + { "GE_CMODE_16BIT_ABGR5551", GE_CMODE_16BIT_ABGR5551 }, + { "GE_CMODE_16BIT_ABGR4444", GE_CMODE_16BIT_ABGR4444 }, + { "GE_CMODE_32BIT_ABGR8888", GE_CMODE_32BIT_ABGR8888 }, + { "GE_TFILT_NEAREST", GE_TFILT_NEAREST }, + { "GE_TFILT_LINEAR", GE_TFILT_LINEAR }, + { "GE_TFILT_NEAREST_MIPMAP_NEAREST", GE_TFILT_NEAREST_MIPMAP_NEAREST }, + { "GE_TFILT_LINEAR_MIPMAP_NEAREST", GE_TFILT_LINEAR_MIPMAP_NEAREST }, + { "GE_TFILT_NEAREST_MIPMAP_LINEAR", GE_TFILT_NEAREST_MIPMAP_LINEAR }, + { "GE_TFILT_LINEAR_MIPMAP_LINEAR", GE_TFILT_LINEAR_MIPMAP_LINEAR }, + { "NEAREST", GE_TFILT_NEAREST }, + { "LINEAR", GE_TFILT_LINEAR }, + { "GE_TEXLEVEL_MODE_AUTO", GE_TEXLEVEL_MODE_AUTO }, + { "GE_TEXLEVEL_MODE_CONST", GE_TEXLEVEL_MODE_CONST }, + { "GE_TEXLEVEL_MODE_SLOPE", GE_TEXLEVEL_MODE_SLOPE }, + { "GE_TEXFUNC_MODULATE", GE_TEXFUNC_MODULATE }, + { "GE_TEXFUNC_DECAL", GE_TEXFUNC_DECAL }, + { "GE_TEXFUNC_BLEND", GE_TEXFUNC_BLEND }, + { "GE_TEXFUNC_REPLACE", GE_TEXFUNC_REPLACE }, + { "GE_TEXFUNC_ADD", GE_TEXFUNC_ADD }, + { "GE_COMP_NEVER", GE_COMP_NEVER }, + { "GE_COMP_ALWAYS", GE_COMP_ALWAYS }, + { "GE_COMP_EQUAL", GE_COMP_EQUAL }, + { "GE_COMP_NOTEQUAL", GE_COMP_NOTEQUAL }, + { "GE_COMP_LESS", GE_COMP_LESS }, + { "GE_COMP_LEQUAL", GE_COMP_LEQUAL }, + { "GE_COMP_GREATER", GE_COMP_GREATER }, + { "GE_COMP_GEQUAL", GE_COMP_GEQUAL }, + { "NEVER", GE_COMP_NEVER }, + { "ALWAYS", GE_COMP_ALWAYS }, + { "EQUAL", GE_COMP_EQUAL }, + { "NOTEQUAL", GE_COMP_NOTEQUAL }, + { "LESS", GE_COMP_LESS }, + { "LEQUAL", GE_COMP_LEQUAL }, + { "LESSEQUAL", GE_COMP_LEQUAL }, + { "GREATER", GE_COMP_GREATER }, + { "GEQUAL", GE_COMP_GEQUAL }, + { "GREATEREQUAL", GE_COMP_GEQUAL }, + { "GE_STENCILOP_KEEP", GE_STENCILOP_KEEP }, + { "GE_STENCILOP_ZERO", GE_STENCILOP_ZERO }, + { "GE_STENCILOP_REPLACE", GE_STENCILOP_REPLACE }, + { "GE_STENCILOP_INVERT", GE_STENCILOP_INVERT }, + { "GE_STENCILOP_INCR", GE_STENCILOP_INCR }, + { "GE_STENCILOP_DECR", GE_STENCILOP_DECR }, + { "GE_BLENDMODE_MUL_AND_ADD", GE_BLENDMODE_MUL_AND_ADD }, + { "GE_BLENDMODE_MUL_AND_SUBTRACT", GE_BLENDMODE_MUL_AND_SUBTRACT }, + { "GE_BLENDMODE_MUL_AND_SUBTRACT_REVERSE", GE_BLENDMODE_MUL_AND_SUBTRACT_REVERSE }, + { "GE_BLENDMODE_MIN", GE_BLENDMODE_MIN }, + { "GE_BLENDMODE_MAX", GE_BLENDMODE_MAX }, + { "GE_BLENDMODE_ABSDIFF", GE_BLENDMODE_ABSDIFF }, + { "ADD", GE_BLENDMODE_MUL_AND_ADD }, + { "SUBTRACT", GE_BLENDMODE_MUL_AND_SUBTRACT }, + { "SUBTRACT_REVERSE", GE_BLENDMODE_MUL_AND_SUBTRACT_REVERSE }, + { "MIN", GE_BLENDMODE_MIN }, + { "MAX", GE_BLENDMODE_MAX }, + { "ABSDIFF", GE_BLENDMODE_ABSDIFF }, + { "GE_SRCBLEND_DSTCOLOR", GE_SRCBLEND_DSTCOLOR }, + { "GE_SRCBLEND_INVDSTCOLOR", GE_SRCBLEND_INVDSTCOLOR }, + { "GE_SRCBLEND_SRCALPHA", GE_SRCBLEND_SRCALPHA }, + { "GE_SRCBLEND_INVSRCALPHA", GE_SRCBLEND_INVSRCALPHA }, + { "GE_SRCBLEND_DSTALPHA", GE_SRCBLEND_DSTALPHA }, + { "GE_SRCBLEND_INVDSTALPHA", GE_SRCBLEND_INVDSTALPHA }, + { "GE_SRCBLEND_DOUBLESRCALPHA", GE_SRCBLEND_DOUBLESRCALPHA }, + { "GE_SRCBLEND_DOUBLEINVSRCALPHA", GE_SRCBLEND_DOUBLEINVSRCALPHA }, + { "GE_SRCBLEND_DOUBLEDSTALPHA", GE_SRCBLEND_DOUBLEDSTALPHA }, + { "GE_SRCBLEND_DOUBLEINVDSTALPHA", GE_SRCBLEND_DOUBLEINVDSTALPHA }, + { "GE_SRCBLEND_FIXA", GE_SRCBLEND_FIXA }, + { "GE_DSTBLEND_SRCCOLOR", GE_DSTBLEND_SRCCOLOR }, + { "GE_DSTBLEND_INVSRCCOLOR", GE_DSTBLEND_INVSRCCOLOR }, + { "GE_DSTBLEND_SRCALPHA", GE_DSTBLEND_SRCALPHA }, + { "GE_DSTBLEND_INVSRCALPHA", GE_DSTBLEND_INVSRCALPHA }, + { "GE_DSTBLEND_DSTALPHA", GE_DSTBLEND_DSTALPHA }, + { "GE_DSTBLEND_INVDSTALPHA", GE_DSTBLEND_INVDSTALPHA }, + { "GE_DSTBLEND_DOUBLESRCALPHA", GE_DSTBLEND_DOUBLESRCALPHA }, + { "GE_DSTBLEND_DOUBLEINVSRCALPHA", GE_DSTBLEND_DOUBLEINVSRCALPHA }, + { "GE_DSTBLEND_DOUBLEDSTALPHA", GE_DSTBLEND_DOUBLEDSTALPHA }, + { "GE_DSTBLEND_DOUBLEINVDSTALPHA", GE_DSTBLEND_DOUBLEINVDSTALPHA }, + { "GE_DSTBLEND_FIXB", GE_DSTBLEND_FIXB }, + { "SRCALPHA", GE_SRCBLEND_SRCALPHA }, + { "INVSRCALPHA", GE_SRCBLEND_INVSRCALPHA }, + { "INVERSESRCALPHA", GE_SRCBLEND_INVSRCALPHA }, + { "DSTALPHA", GE_DSTBLEND_DSTALPHA }, + { "INVDSTALPHA", GE_DSTBLEND_INVDSTALPHA }, + { "DOUBLESRCALPHA", GE_DSTBLEND_DOUBLESRCALPHA }, + { "DOUBLEINVSRCALPHA", GE_DSTBLEND_DOUBLEINVSRCALPHA }, + { "DOUBLEDSTALPHA", GE_DSTBLEND_DOUBLEDSTALPHA }, + { "DOUBLEINVDSTALPHA", GE_DSTBLEND_DOUBLEINVDSTALPHA }, + { "FIXED", GE_DSTBLEND_FIXB }, + { "GE_LOGIC_CLEAR", GE_LOGIC_CLEAR }, + { "GE_LOGIC_AND", GE_LOGIC_AND }, + { "GE_LOGIC_AND_REVERSE", GE_LOGIC_AND_REVERSE }, + { "GE_LOGIC_COPY", GE_LOGIC_COPY }, + { "GE_LOGIC_AND_INVERTED", GE_LOGIC_AND_INVERTED }, + { "GE_LOGIC_NOOP", GE_LOGIC_NOOP }, + { "GE_LOGIC_XOR", GE_LOGIC_XOR }, + { "GE_LOGIC_OR", GE_LOGIC_OR }, + { "GE_LOGIC_NOR", GE_LOGIC_NOR }, + { "GE_LOGIC_EQUIV", GE_LOGIC_EQUIV }, + { "GE_LOGIC_INVERTED", GE_LOGIC_INVERTED }, + { "GE_LOGIC_OR_REVERSE", GE_LOGIC_OR_REVERSE }, + { "GE_LOGIC_COPY_INVERTED", GE_LOGIC_COPY_INVERTED }, + { "GE_LOGIC_OR_INVERTED", GE_LOGIC_OR_INVERTED }, + { "GE_LOGIC_NAND", GE_LOGIC_NAND }, + { "GE_LOGIC_SET", GE_LOGIC_SET }, +}; + class GEExpressionFunctions : public IExpressionFunctions { public: GEExpressionFunctions(GPUDebugInterface *gpu) : gpu_(gpu) {} @@ -405,7 +602,15 @@ bool GEExpressionFunctions::parseFieldReference(const char *ref, const char *fie } bool GEExpressionFunctions::parseSymbol(char *str, uint32_t &symbolValue) { - // Mainly useful for checking memory addresses. + // Mainly useful for checking memory addresses and constants. + + for (const auto &entry : constantNames) { + if (strcasecmp(str, entry.name) == 0) { + symbolValue = entry.value; + return true; + } + } + return g_symbolMap->GetLabelValue(str, symbolValue); } @@ -560,6 +765,8 @@ uint32_t GEExpressionFunctions::getFieldValue(GECmdFormat fmt, GECmdField field, return (value >> 11) & 1; case GECmdField::FLAG_AFTER_16: return (value >> 16) & 1; + case GECmdField::FLAG_AFTER_17: + return (value >> 17) & 1; case GECmdField::FLAG_AFTER_18: return (value >> 18) & 1; case GECmdField::FLAG_AFTER_19: @@ -583,10 +790,6 @@ uint32_t GEExpressionFunctions::getFieldValue(GECmdFormat fmt, GECmdField field, case GECmdField::PRIM_TYPE: return (value >> 16) & 7; - case GECmdField::SPLINE_UTYPE: - return (value >> 16) & 3; - case GECmdField::SPLINE_VTYPE: - return (value >> 18) & 3; case GECmdField::SIGNAL_TYPE: return (value >> 16) & 0xFF; case GECmdField::VTYPE_TC: From 41c6c81eadead4c747cee3bd8eb60d250ad8d054 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 14:38:27 -0700 Subject: [PATCH 57/69] README: Move some older releases to history. --- README.md | 218 ---------------------------------------------------- history.md | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 218 insertions(+), 219 deletions(-) diff --git a/README.md b/README.md index fbf49d359a..8a9a7bc744 100644 --- a/README.md +++ b/README.md @@ -166,110 +166,6 @@ Adhoc/Network: * Reduce HLE delays due to multiplayer performance regressions (ie. Ys vs. Sora no Kiseki) ([#14513]) * Fix socket error 10014 on Windows when hosting a game of Vulcanus Seek and Destroy ([#14849]) -What's new in 1.11.3 -==================== -* Fix for graphics glitches in the on-screen keyboard - -What's new in 1.11.2 -==================== -* An additional few crash fixes ([#14129], [#14134], [#14132]) - -What's new in 1.11.1 -==================== -* A few crash fixes ([#14085], [#14089], [#14091], [#14092]), a few adhoc fixes -* Glitchy menu audio on some devices ([#14101]), in-game UI font memory leak ([#14078]) -* Couple of adhoc fixes ([#14106], [#14117]) - -What's new in 1.11.0 -==================== -* Lots of minor bug fixes, crash fixes, and performance fixes and improvements. -* New Browse... button to allow opening SD cards on Android 11 -* Countless AdHoc networking fixes by ANR2ME, for example Dragon Ball Shin Budokai, PowerStone, - Bleach Heat The Soul 7, Kingdom Hearts, GTA: VCS and many more. -* Graphics issue with car reflections fixed in Outrun, Dirt 2 ([#13636], [#13640], [#13760]) -* Cut-off cards in Yu Gi Oh fixed ([#7124]). -* Numerous fixes to the builtin fonts by nassau-tk -* Added exception handler so PPSSPP stays alive if a game crashes ([#11795]/[#13092]) -* Desktop: Support for multiple instance multiplayer ([#13172], ...) -* Workaround for rendering bugs with flat shading in iOS 14 -* Multiple fixes to the IR interpreter ([#13897], ...) -* UI: New fullscreen button on desktop platforms, optional navigation sounds ([#13239]) -* Audio and multiple hangs fixes in UWP version ([#13792], ...) -* Partial microphone support ([#12336], ...) -* Workaround for wacky action mirroring bug in Hitman Reborn Battle Arena 2 ([#13706], [#13526]) -* Hardware texture upscaling for Vulkan, mipmap generation ([#13235], [#13514]) -* Added MMPX Vulkan texture upscaling shader ([#13986]) -* Depth texturing support in Vulkan and D3D11 ([#13262], [#13556], ...) -* Performance fix for Test Drive Unlimited ([#13355], ...) -* Allow rewind on mobile ([#13866]) -* Added option to disable on-screen messages ([#13695]) -* Added "Lower resolution for effects" on libretro ([#13654]) -* Allow chaining multiple post-processing shaders ([#12924]) -* Support for loading game-specific plugins ([#13335]) -* Fixed Assassin's Creed: Bloodlines Save issue on Android ([#12761]) -* Hanayaka Nari Wa ga Ichizoku: mono voices fixed ([#5213]) -* Additional fixed games: - * Namco Museum - Battle Collection, Vol 2 ([#9523], [#13297], [#13298]) - * Dream Club Portable (graphics bugs, GL and Vulkan) ([#6025]) - * Capcom Classic Collection Reloaded (stuck in return game) ([#4671]) - * Xyanide Resurrection (freezing) ([#8526]) - * Dissidia Final Fantasy Chinese (patched game, invalid address) ([#13204]) - * Crazy Taxi ([#13368]) - * Spiderman: Friend or Foe ([#13969]) - * Downstream Panic (US) (New Game crash) ([#13633]) - -What's new in 1.10.3 --------------------- -* Fix for control layout editor ([#13125]) - -What's new in 1.10.2 --------------------- -* More crashfixes ([#13094], [#13093]) -* Improve download performance and cancel behavior ([#13095]) -* Restore the removed I/O on Thread option ([#13096]) - -What's new in 1.10.1 --------------------- -* Fixes for common crashes ([#13077], [#13076], see [#13057]) -* Fix for offset rendering in D3D9 ([#13071]) - -What's new in 1.10.0 --------------------- -* Graphics and compatibility fixes ([#12800], [#12670], [#12635], [#12857], [#12941], [#11898], [#12695], more) -* Assorted minor performance improvements, game load speedup ([#12462], [#12652]) -* Screen inset (notch) support on Android ([#12779]) -* Analog stick support for menu navigation ([#12685]) -* Fixed audio glitches in SDL builds ([#12916], [#12920]) -* Support more languages in in-game dialogs ([#12702]). Croatian language added to PPSSPP. -* Simple multiplayer chat ([#12667]) -* More advanced postprocessing (multipass, parameters) ([#12905], [#12901]) -* Add PPSSPP-specific CWCheat ([#12816], [#12912]) -* Reintroduce Cardboard VR, allow more resolutions ([#12449], [#8714]) -* Fix some crashes ([#12908], [#12876]) -* Ghost in the Shell graphics fixed (JIT inaccuracy with inf * 0) ([#12519]) -* Mac build now supports Vulkan on top of MoltenVK ([#12583]) -* Raspberry Pi 4 EGL crash fixed ([#12474]) -* VSync now supported on all backends, frame duplication option added for 30 Hz games ([#12659], [#12602]) -* Camera supported on Windows, Linux and Mac (still no microphone though) ([#12572], [#12580], [#12607]) -* Darkstalkers fixed and working through software rendering. SW rendering fixed on GLES 2.0 ([#12443], [#12898]) -* Hot Shots Golf slowdown and flicker on Vulkan fixed ([#12873], [#12746]) -* Pangya Golf crashes and hangs fixed ([#12718]) -* Allow rebinding of right touch screen analog ([#12486]) -* Add option to prevent mipmaps from being dumped ([#12818]) -* Tilt control now have a base radius to help with deadzone ([#12756]) -* Mappable auto rotating analog stick to pass some game checks ([#12749]) -* Touch control position can now be snapped to a grid ([#12517]) -* HiDPI retina display support ([#12552]) -* Rapid-fire on touch control ([#12601]) -* Toggle mute button ([#12643]) -* Add option to resize game icons and more ([#12646], [#12637]) -* Frames in-flight now configurable to reduce input lag at the cost of speed ([#12660]) -* Add toggle mode to combo button ([#12623]) -* SDL mouse support, Qt menu upgrades ([#12612], [#12817]) -* Real support for Chinese patched version of Hatsune Miku Project Diva Extend ([#13007]) -* Some minor kernel module support ([#13028], [#12225], [#13026], [#13004], [#13038], [#13023]) -* Fixed fullscreen toggling with Vulkan in SDL builds ([#11974]) - Looking for [older news](history.md)? @@ -287,120 +183,6 @@ Credit goes to: [comment]: # (LINK_LIST_BEGIN_HERE) -[#13125]: https://github.com/hrydgard/ppsspp/issues/13125 "Refactor and fix touch control layout screen for notch" -[#13094]: https://github.com/hrydgard/ppsspp/issues/13094 "Camera initialization crash fix" -[#13093]: https://github.com/hrydgard/ppsspp/issues/13093 "Add a try/catch to Android camera device listing." -[#13095]: https://github.com/hrydgard/ppsspp/issues/13095 "http: Check cancel flag more often" -[#13096]: https://github.com/hrydgard/ppsspp/issues/13096 "Revert \"Remove the I/O on Thread option - treat it as always on.\"" -[#13077]: https://github.com/hrydgard/ppsspp/issues/13077 "SaveState: Make sure to default init net data" -[#13076]: https://github.com/hrydgard/ppsspp/issues/13076 "Add some excessive null checks to GameScreen::render()" -[#13057]: https://github.com/hrydgard/ppsspp/issues/13057 "The 1.10 Android mystery crash thread!" -[#13071]: https://github.com/hrydgard/ppsspp/issues/13071 "D3D9: Fix a sign mistake generating the projection matrix." -[#12800]: https://github.com/hrydgard/ppsspp/issues/12800 "x86jit: Force INF * 0 to +NAN" -[#12670]: https://github.com/hrydgard/ppsspp/issues/12670 "Attempts to replace 0 frame width with valid frame width.(sceMpegAvcCsc)" -[#12635]: https://github.com/hrydgard/ppsspp/issues/12635 "Kernel: Delay better in sceKernelReferThreadStatus" -[#12857]: https://github.com/hrydgard/ppsspp/issues/12857 "Mumbo Jumbo games freeze on loading screen since v1.6" -[#12941]: https://github.com/hrydgard/ppsspp/issues/12941 "Vulkan: Deal with the reformat clear better" -[#11898]: https://github.com/hrydgard/ppsspp/issues/11898 "Strike Witches - Hakugin no Tsubasa missing intro video" -[#12695]: https://github.com/hrydgard/ppsspp/issues/12695 "New heuristic for getting rid of unnecessary \"antialias-lines\"." -[#12462]: https://github.com/hrydgard/ppsspp/issues/12462 "Vulkan: Enable renderpass merging for all games" -[#12652]: https://github.com/hrydgard/ppsspp/issues/12652 "ScanForFunctions: Speed up game loading" -[#12779]: https://github.com/hrydgard/ppsspp/issues/12779 "Support drawing around notches on Android displays. Fixes #12261" -[#12685]: https://github.com/hrydgard/ppsspp/issues/12685 "UI: Simple joystick navigation. Fixes #10996." -[#12916]: https://github.com/hrydgard/ppsspp/issues/12916 "More audio buffering fixes (primarily affects SDL)" -[#12920]: https://github.com/hrydgard/ppsspp/issues/12920 "Remove the Audio Resampling setting (now always on)." -[#12702]: https://github.com/hrydgard/ppsspp/issues/12702 "PPGe: Use TextDrawer for save UI if available" -[#12667]: https://github.com/hrydgard/ppsspp/issues/12667 "Chat feature based on Adenovan's Rechat branch" -[#12905]: https://github.com/hrydgard/ppsspp/issues/12905 "Allow chained post-processing shaders" -[#12901]: https://github.com/hrydgard/ppsspp/issues/12901 "Post shader setting uniform" -[#12816]: https://github.com/hrydgard/ppsspp/issues/12816 "Implement Xinput vibration CWCheat (PPSSPP specific 0xA code type)" -[#12912]: https://github.com/hrydgard/ppsspp/issues/12912 "Add CWCHEAT for postprocessing" -[#12449]: https://github.com/hrydgard/ppsspp/issues/12449 "Reintroduce Cardboard VR" -[#8714]: https://github.com/hrydgard/ppsspp/issues/8714 "Allow > 5x PSP resolution for devices like iPad Pro 12.9" -[#12908]: https://github.com/hrydgard/ppsspp/issues/12908 "Fix \"Improved compatibility of sceGeListEnQueue: verify that stackDepth < 256\"" -[#12876]: https://github.com/hrydgard/ppsspp/issues/12876 "Windows: Add safety checks to WASAPI code" -[#12519]: https://github.com/hrydgard/ppsspp/issues/12519 "Ghost In The Shell - Stand Alone Complex (ULUS10020) - Black Textures and missing screens." -[#12583]: https://github.com/hrydgard/ppsspp/issues/12583 "macOS: Initial support for vulkan on macOS ( MoltenVK )" -[#12474]: https://github.com/hrydgard/ppsspp/issues/12474 "Egl bug on rpi4 with master mesa?" -[#12659]: https://github.com/hrydgard/ppsspp/issues/12659 "Support vsync in all hardware backends, support runtime update" -[#12602]: https://github.com/hrydgard/ppsspp/issues/12602 "Add option to improve frame pacing through duplicate frames if below 60hz." -[#12572]: https://github.com/hrydgard/ppsspp/issues/12572 "Add camera support for windows." -[#12580]: https://github.com/hrydgard/ppsspp/issues/12580 "Add camera support for linux (V4L2)" -[#12607]: https://github.com/hrydgard/ppsspp/issues/12607 "QT API for camera (Linux/macOS)" -[#12443]: https://github.com/hrydgard/ppsspp/issues/12443 "Darkstalkers Chronicle: Add specializations and speedhacks to get it kinda playable" -[#12898]: https://github.com/hrydgard/ppsspp/issues/12898 "[Android] [Mali GPU] [OpenGL] Lastest build blackscreen on buffered rendering mode" -[#12873]: https://github.com/hrydgard/ppsspp/issues/12873 "Vulkan: Framebuffer manager: Use an allocator for \"MakePixelTexture\" images." -[#12746]: https://github.com/hrydgard/ppsspp/issues/12746 "GPU: Assume a scissor of 481x273 is a mistake" -[#12718]: https://github.com/hrydgard/ppsspp/issues/12718 "Vpl: Correct allocation order when splitting block" -[#12486]: https://github.com/hrydgard/ppsspp/issues/12486 "Rebindable touch right analog" -[#12818]: https://github.com/hrydgard/ppsspp/issues/12818 "Add option to prevent Mipmaps from being dumped" -[#12756]: https://github.com/hrydgard/ppsspp/issues/12756 "Skip deadzone option on tilt" -[#12749]: https://github.com/hrydgard/ppsspp/issues/12749 "Auto rotating analog" -[#12517]: https://github.com/hrydgard/ppsspp/issues/12517 "Touch control grid snap" -[#12552]: https://github.com/hrydgard/ppsspp/issues/12552 "Qt/macOS: enable HiDPI ( retina display ) support" -[#12601]: https://github.com/hrydgard/ppsspp/issues/12601 "Add rapid fire to touch control" -[#12643]: https://github.com/hrydgard/ppsspp/issues/12643 "Toggle mute button" -[#12646]: https://github.com/hrydgard/ppsspp/issues/12646 "Resizable game icons" -[#12637]: https://github.com/hrydgard/ppsspp/issues/12637 "Region flag and game ID on game selection screen" -[#12660]: https://github.com/hrydgard/ppsspp/issues/12660 "GPU: Add setting to control inflight frame usage" -[#12623]: https://github.com/hrydgard/ppsspp/issues/12623 "Add toggle flag to combo button" -[#12612]: https://github.com/hrydgard/ppsspp/issues/12612 "SDL analog mouse input" -[#12817]: https://github.com/hrydgard/ppsspp/issues/12817 "Unification of the menu of Linux and Windows versions" -[#13007]: https://github.com/hrydgard/ppsspp/issues/13007 "Real support \"Hatsune Miku Project Diva Extend\" chinese patched version" -[#13028]: https://github.com/hrydgard/ppsspp/issues/13028 "Real support Code Geass: Lost Colors chinese patched version" -[#12225]: https://github.com/hrydgard/ppsspp/issues/12225 "Rebased: Wrap some SysMemForKernel's nids, fixing #7960" -[#13026]: https://github.com/hrydgard/ppsspp/issues/13026 "Add some ThreadManForKernel nids" -[#13004]: https://github.com/hrydgard/ppsspp/issues/13004 "Warp some ThreadManForKernel and sceKernelExitVSHKernel" -[#13038]: https://github.com/hrydgard/ppsspp/issues/13038 "Add sysclib_strncmp,sysclib_memmove" -[#13023]: https://github.com/hrydgard/ppsspp/issues/13023 "Add sysclib_strstr" -[#11974]: https://github.com/hrydgard/ppsspp/issues/11974 "[Linux] [Vulkan] Toggle fullscreen doesn't update display properly" -[#13636]: https://github.com/hrydgard/ppsspp/issues/13636 "Reinterpret framebuffer formats as needed. Outrun reflections partial fix" -[#13640]: https://github.com/hrydgard/ppsspp/issues/13640 "Fix car reflections in Outrun" -[#13760]: https://github.com/hrydgard/ppsspp/issues/13760 "Fix car lighting issues in DiRT 2." -[#7124]: https://github.com/hrydgard/ppsspp/issues/7124 "Yu-Gi-Oh! GX Tag Force Card summoning (card cut-off / cropped)" -[#11795]: https://github.com/hrydgard/ppsspp/issues/11795 "Exception handler - catch bad memory accesses" -[#13092]: https://github.com/hrydgard/ppsspp/issues/13092 "Bad memory access handling improvements" -[#13172]: https://github.com/hrydgard/ppsspp/issues/13172 "Generalized multi-instance" -[#13897]: https://github.com/hrydgard/ppsspp/issues/13897 "LittleBigPlanet - Game Not Loading, Blue Screen (iOS, Unplayable)" -[#13239]: https://github.com/hrydgard/ppsspp/issues/13239 "Add sound effects for PPSSPP interface navigation" -[#13792]: https://github.com/hrydgard/ppsspp/issues/13792 "Fix UWP audio and a hang bug" -[#12336]: https://github.com/hrydgard/ppsspp/issues/12336 "Microphone support" -[#13706]: https://github.com/hrydgard/ppsspp/issues/13706 "Add back the old implementation of vfpu_sin/cos/sincos." -[#13526]: https://github.com/hrydgard/ppsspp/issues/13526 "VFPU: Compute sines and cosines in double precision." -[#13235]: https://github.com/hrydgard/ppsspp/issues/13235 "Vulkan: Allow custom texture upscaling shaders" -[#13514]: https://github.com/hrydgard/ppsspp/issues/13514 "Vulkan: Automatically generate mipmaps for replaced/scaled textures" -[#13986]: https://github.com/hrydgard/ppsspp/issues/13986 "Vulkan: Add MMPX upscaling texture shader" -[#13355]: https://github.com/hrydgard/ppsspp/issues/13355 "Refactor framebuffer attachment. Fixes Test Drive Unlimited performance" -[#13866]: https://github.com/hrydgard/ppsspp/issues/13866 "SaveState: Allow rewind on mobile" -[#13695]: https://github.com/hrydgard/ppsspp/issues/13695 "Add developer setting \"Show on-screen messages\". Uncheck to hide them." -[#13654]: https://github.com/hrydgard/ppsspp/issues/13654 "Expose the \"Lower resolution for effects\" setting in libretro." -[#12924]: https://github.com/hrydgard/ppsspp/issues/12924 "Postprocessing: User chain support" -[#13335]: https://github.com/hrydgard/ppsspp/issues/13335 "Support for loading game-specific plugins" -[#12761]: https://github.com/hrydgard/ppsspp/issues/12761 "[Android][OpenGL&Vulkan][Save issue] Assassin's Creed : Bloodlines (ULJM05571)" -[#5213]: https://github.com/hrydgard/ppsspp/issues/5213 "Hanayaka Nari Wa ga Ichizoku strange MP3 mono voice" -[#9523]: https://github.com/hrydgard/ppsspp/issues/9523 "Namco Museum - Battle Collection - ULUS100035 loading problem" -[#13297]: https://github.com/hrydgard/ppsspp/issues/13297 "Namco Museum Vol. 2 - ULJS00047 infinite loading in some game" -[#13298]: https://github.com/hrydgard/ppsspp/issues/13298 "Fix sceKernelExitThread" -[#6025]: https://github.com/hrydgard/ppsspp/issues/6025 "Dream Club Portable crash after select girl" -[#4671]: https://github.com/hrydgard/ppsspp/issues/4671 "Capcom Classic Collection Reloaded stuck in return game" -[#8526]: https://github.com/hrydgard/ppsspp/issues/8526 "Xyanide Resurrection freezing" -[#13204]: https://github.com/hrydgard/ppsspp/issues/13204 "Dissidia Final Fantasy Chinese patch invalid address" -[#13368]: https://github.com/hrydgard/ppsspp/issues/13368 "Reschedule after resuming thread from suspend." -[#13969]: https://github.com/hrydgard/ppsspp/issues/13969 "Io: Don't allow async close while async busy" -[#13633]: https://github.com/hrydgard/ppsspp/issues/13633 "Downstream Panic (US) New Game crashes" -[#13262]: https://github.com/hrydgard/ppsspp/issues/13262 "Implement texturing from depth buffers (Vulkan only so far)" -[#13556]: https://github.com/hrydgard/ppsspp/issues/13556 "D3D11 depth texture support" -[#14085]: https://github.com/hrydgard/ppsspp/issues/14085 "Handle exec addr errors better - don't let IgnoreBadMemoryAccesses skip dispatcher exceptions" -[#14089]: https://github.com/hrydgard/ppsspp/issues/14089 "GL: Call CreateDeviceObjects *after* updating render_." -[#14091]: https://github.com/hrydgard/ppsspp/issues/14091 "Only allow sceMpegGetAvcAu warmup for God Eater Series" -[#14092]: https://github.com/hrydgard/ppsspp/issues/14092 "SaveState: Prevent crash on bad cookie marker" -[#14101]: https://github.com/hrydgard/ppsspp/issues/14101 "Menu audio glitchfix" -[#14078]: https://github.com/hrydgard/ppsspp/issues/14078 "PPGe: Decimate text images properly" -[#14106]: https://github.com/hrydgard/ppsspp/issues/14106 "[Adhoc] Fix frozen (0 FPS) issue on Kao Challengers and Asterix & Obelix XX" -[#14117]: https://github.com/hrydgard/ppsspp/issues/14117 "[Adhoc] Fix lob" -[#14129]: https://github.com/hrydgard/ppsspp/issues/14129 "GPU: Force reinterpret off without copy image" -[#14134]: https://github.com/hrydgard/ppsspp/issues/14134 "Android: Ensure shutdown waits for render" -[#14132]: https://github.com/hrydgard/ppsspp/issues/14132 "Io: Truncate reads/writes to valid memory" [#11997]: https://github.com/hrydgard/ppsspp/issues/11997 "Android 12 scoped storage hell" [#5099]: https://github.com/hrydgard/ppsspp/issues/5099 "IOS touch controls problems." [#14053]: https://github.com/hrydgard/ppsspp/issues/14053 "Toggle screenshot minor issue." diff --git a/history.md b/history.md index b40eaba158..2191439617 100644 --- a/history.md +++ b/history.md @@ -1,5 +1,109 @@ This is history moved out from README.md, which was getting a bit long. +What's new in 1.11.3 +==================== +* Fix for graphics glitches in the on-screen keyboard + +What's new in 1.11.2 +==================== +* An additional few crash fixes ([#14129], [#14134], [#14132]) + +What's new in 1.11.1 +==================== +* A few crash fixes ([#14085], [#14089], [#14091], [#14092]), a few adhoc fixes +* Glitchy menu audio on some devices ([#14101]), in-game UI font memory leak ([#14078]) +* Couple of adhoc fixes ([#14106], [#14117]) + +What's new in 1.11.0 +==================== +* Lots of minor bug fixes, crash fixes, and performance fixes and improvements. +* New Browse... button to allow opening SD cards on Android 11 +* Countless AdHoc networking fixes by ANR2ME, for example Dragon Ball Shin Budokai, PowerStone, + Bleach Heat The Soul 7, Kingdom Hearts, GTA: VCS and many more. +* Graphics issue with car reflections fixed in Outrun, Dirt 2 ([#13636], [#13640], [#13760]) +* Cut-off cards in Yu Gi Oh fixed ([#7124]). +* Numerous fixes to the builtin fonts by nassau-tk +* Added exception handler so PPSSPP stays alive if a game crashes ([#11795]/[#13092]) +* Desktop: Support for multiple instance multiplayer ([#13172], ...) +* Workaround for rendering bugs with flat shading in iOS 14 +* Multiple fixes to the IR interpreter ([#13897], ...) +* UI: New fullscreen button on desktop platforms, optional navigation sounds ([#13239]) +* Audio and multiple hangs fixes in UWP version ([#13792], ...) +* Partial microphone support ([#12336], ...) +* Workaround for wacky action mirroring bug in Hitman Reborn Battle Arena 2 ([#13706], [#13526]) +* Hardware texture upscaling for Vulkan, mipmap generation ([#13235], [#13514]) +* Added MMPX Vulkan texture upscaling shader ([#13986]) +* Depth texturing support in Vulkan and D3D11 ([#13262], [#13556], ...) +* Performance fix for Test Drive Unlimited ([#13355], ...) +* Allow rewind on mobile ([#13866]) +* Added option to disable on-screen messages ([#13695]) +* Added "Lower resolution for effects" on libretro ([#13654]) +* Allow chaining multiple post-processing shaders ([#12924]) +* Support for loading game-specific plugins ([#13335]) +* Fixed Assassin's Creed: Bloodlines Save issue on Android ([#12761]) +* Hanayaka Nari Wa ga Ichizoku: mono voices fixed ([#5213]) +* Additional fixed games: + * Namco Museum - Battle Collection, Vol 2 ([#9523], [#13297], [#13298]) + * Dream Club Portable (graphics bugs, GL and Vulkan) ([#6025]) + * Capcom Classic Collection Reloaded (stuck in return game) ([#4671]) + * Xyanide Resurrection (freezing) ([#8526]) + * Dissidia Final Fantasy Chinese (patched game, invalid address) ([#13204]) + * Crazy Taxi ([#13368]) + * Spiderman: Friend or Foe ([#13969]) + * Downstream Panic (US) (New Game crash) ([#13633]) + +What's new in 1.10.3 +-------------------- +* Fix for control layout editor ([#13125]) + +What's new in 1.10.2 +-------------------- +* More crashfixes ([#13094], [#13093]) +* Improve download performance and cancel behavior ([#13095]) +* Restore the removed I/O on Thread option ([#13096]) + +What's new in 1.10.1 +-------------------- +* Fixes for common crashes ([#13077], [#13076], see [#13057]) +* Fix for offset rendering in D3D9 ([#13071]) + +What's new in 1.10.0 +-------------------- +* Graphics and compatibility fixes ([#12800], [#12670], [#12635], [#12857], [#12941], [#11898], [#12695], more) +* Assorted minor performance improvements, game load speedup ([#12462], [#12652]) +* Screen inset (notch) support on Android ([#12779]) +* Analog stick support for menu navigation ([#12685]) +* Fixed audio glitches in SDL builds ([#12916], [#12920]) +* Support more languages in in-game dialogs ([#12702]). Croatian language added to PPSSPP. +* Simple multiplayer chat ([#12667]) +* More advanced postprocessing (multipass, parameters) ([#12905], [#12901]) +* Add PPSSPP-specific CWCheat ([#12816], [#12912]) +* Reintroduce Cardboard VR, allow more resolutions ([#12449], [#8714]) +* Fix some crashes ([#12908], [#12876]) +* Ghost in the Shell graphics fixed (JIT inaccuracy with inf * 0) ([#12519]) +* Mac build now supports Vulkan on top of MoltenVK ([#12583]) +* Raspberry Pi 4 EGL crash fixed ([#12474]) +* VSync now supported on all backends, frame duplication option added for 30 Hz games ([#12659], [#12602]) +* Camera supported on Windows, Linux and Mac (still no microphone though) ([#12572], [#12580], [#12607]) +* Darkstalkers fixed and working through software rendering. SW rendering fixed on GLES 2.0 ([#12443], [#12898]) +* Hot Shots Golf slowdown and flicker on Vulkan fixed ([#12873], [#12746]) +* Pangya Golf crashes and hangs fixed ([#12718]) +* Allow rebinding of right touch screen analog ([#12486]) +* Add option to prevent mipmaps from being dumped ([#12818]) +* Tilt control now have a base radius to help with deadzone ([#12756]) +* Mappable auto rotating analog stick to pass some game checks ([#12749]) +* Touch control position can now be snapped to a grid ([#12517]) +* HiDPI retina display support ([#12552]) +* Rapid-fire on touch control ([#12601]) +* Toggle mute button ([#12643]) +* Add option to resize game icons and more ([#12646], [#12637]) +* Frames in-flight now configurable to reduce input lag at the cost of speed ([#12660]) +* Add toggle mode to combo button ([#12623]) +* SDL mouse support, Qt menu upgrades ([#12612], [#12817]) +* Real support for Chinese patched version of Hatsune Miku Project Diva Extend ([#13007]) +* Some minor kernel module support ([#13028], [#12225], [#13026], [#13004], [#13038], [#13023]) +* Fixed fullscreen toggling with Vulkan in SDL builds ([#11974]) + What's new in 1.9.0/1.9.3 ------------------------- * Sizing/touch fixes on Android @@ -565,4 +669,117 @@ go to see there http://forums.ppsspp.org/showthread.php?tid=3595&pid=59241#pid59 [#11307]: https://github.com/hrydgard/ppsspp/issues/11307 "Enable Discord integration for Mac and Linux." [#10909]: https://github.com/hrydgard/ppsspp/issues/10909 "WebSocket based debugger interface" [#11447]: https://github.com/hrydgard/ppsspp/issues/11447 "Avoid calling any GL calls during shutdown on Android. Should help #11063" -[#11350]: https://github.com/hrydgard/ppsspp/issues/11350 "TexCache: Optimize DXT3/DXT5 decode to single pass" \ No newline at end of file +[#11350]: https://github.com/hrydgard/ppsspp/issues/11350 "TexCache: Optimize DXT3/DXT5 decode to single pass" +[#13023]: https://github.com/hrydgard/ppsspp/issues/13023 "Add sysclib_strstr" +[#13038]: https://github.com/hrydgard/ppsspp/issues/13038 "Add sysclib_strncmp,sysclib_memmove" +[#13004]: https://github.com/hrydgard/ppsspp/issues/13004 "Warp some ThreadManForKernel and sceKernelExitVSHKernel" +[#13026]: https://github.com/hrydgard/ppsspp/issues/13026 "Add some ThreadManForKernel nids" +[#12225]: https://github.com/hrydgard/ppsspp/issues/12225 "Rebased: Wrap some SysMemForKernel's nids, fixing #7960" +[#13028]: https://github.com/hrydgard/ppsspp/issues/13028 "Real support Code Geass: Lost Colors chinese patched version" +[#13007]: https://github.com/hrydgard/ppsspp/issues/13007 "Real support \"Hatsune Miku Project Diva Extend\" chinese patched version" +[#12817]: https://github.com/hrydgard/ppsspp/issues/12817 "Unification of the menu of Linux and Windows versions" +[#12612]: https://github.com/hrydgard/ppsspp/issues/12612 "SDL analog mouse input" +[#12623]: https://github.com/hrydgard/ppsspp/issues/12623 "Add toggle flag to combo button" +[#12660]: https://github.com/hrydgard/ppsspp/issues/12660 "GPU: Add setting to control inflight frame usage" +[#12637]: https://github.com/hrydgard/ppsspp/issues/12637 "Region flag and game ID on game selection screen" +[#12646]: https://github.com/hrydgard/ppsspp/issues/12646 "Resizable game icons" +[#12643]: https://github.com/hrydgard/ppsspp/issues/12643 "Toggle mute button" +[#12601]: https://github.com/hrydgard/ppsspp/issues/12601 "Add rapid fire to touch control" +[#12552]: https://github.com/hrydgard/ppsspp/issues/12552 "Qt/macOS: enable HiDPI ( retina display ) support" +[#12517]: https://github.com/hrydgard/ppsspp/issues/12517 "Touch control grid snap" +[#12749]: https://github.com/hrydgard/ppsspp/issues/12749 "Auto rotating analog" +[#12756]: https://github.com/hrydgard/ppsspp/issues/12756 "Skip deadzone option on tilt" +[#12818]: https://github.com/hrydgard/ppsspp/issues/12818 "Add option to prevent Mipmaps from being dumped" +[#12486]: https://github.com/hrydgard/ppsspp/issues/12486 "Rebindable touch right analog" +[#12718]: https://github.com/hrydgard/ppsspp/issues/12718 "Vpl: Correct allocation order when splitting block" +[#12746]: https://github.com/hrydgard/ppsspp/issues/12746 "GPU: Assume a scissor of 481x273 is a mistake" +[#12873]: https://github.com/hrydgard/ppsspp/issues/12873 "Vulkan: Framebuffer manager: Use an allocator for \"MakePixelTexture\" images." +[#12898]: https://github.com/hrydgard/ppsspp/issues/12898 "[Android] [Mali GPU] [OpenGL] Lastest build blackscreen on buffered rendering mode" +[#12443]: https://github.com/hrydgard/ppsspp/issues/12443 "Darkstalkers Chronicle: Add specializations and speedhacks to get it kinda playable" +[#12607]: https://github.com/hrydgard/ppsspp/issues/12607 "QT API for camera (Linux/macOS)" +[#12580]: https://github.com/hrydgard/ppsspp/issues/12580 "Add camera support for linux (V4L2)" +[#12572]: https://github.com/hrydgard/ppsspp/issues/12572 "Add camera support for windows." +[#12602]: https://github.com/hrydgard/ppsspp/issues/12602 "Add option to improve frame pacing through duplicate frames if below 60hz." +[#12659]: https://github.com/hrydgard/ppsspp/issues/12659 "Support vsync in all hardware backends, support runtime update" +[#12474]: https://github.com/hrydgard/ppsspp/issues/12474 "Egl bug on rpi4 with master mesa?" +[#12583]: https://github.com/hrydgard/ppsspp/issues/12583 "macOS: Initial support for vulkan on macOS ( MoltenVK )" +[#12519]: https://github.com/hrydgard/ppsspp/issues/12519 "Ghost In The Shell - Stand Alone Complex (ULUS10020) - Black Textures and missing screens." +[#12876]: https://github.com/hrydgard/ppsspp/issues/12876 "Windows: Add safety checks to WASAPI code" +[#12908]: https://github.com/hrydgard/ppsspp/issues/12908 "Fix \"Improved compatibility of sceGeListEnQueue: verify that stackDepth < 256\"" +[#8714]: https://github.com/hrydgard/ppsspp/issues/8714 "Allow > 5x PSP resolution for devices like iPad Pro 12.9" +[#12449]: https://github.com/hrydgard/ppsspp/issues/12449 "Reintroduce Cardboard VR" +[#12912]: https://github.com/hrydgard/ppsspp/issues/12912 "Add CWCHEAT for postprocessing" +[#12816]: https://github.com/hrydgard/ppsspp/issues/12816 "Implement Xinput vibration CWCheat (PPSSPP specific 0xA code type)" +[#12901]: https://github.com/hrydgard/ppsspp/issues/12901 "Post shader setting uniform" +[#12905]: https://github.com/hrydgard/ppsspp/issues/12905 "Allow chained post-processing shaders" +[#12667]: https://github.com/hrydgard/ppsspp/issues/12667 "Chat feature based on Adenovan's Rechat branch" +[#12702]: https://github.com/hrydgard/ppsspp/issues/12702 "PPGe: Use TextDrawer for save UI if available" +[#12920]: https://github.com/hrydgard/ppsspp/issues/12920 "Remove the Audio Resampling setting (now always on)." +[#12916]: https://github.com/hrydgard/ppsspp/issues/12916 "More audio buffering fixes (primarily affects SDL)" +[#12685]: https://github.com/hrydgard/ppsspp/issues/12685 "UI: Simple joystick navigation. Fixes #10996." +[#12779]: https://github.com/hrydgard/ppsspp/issues/12779 "Support drawing around notches on Android displays. Fixes #12261" +[#12652]: https://github.com/hrydgard/ppsspp/issues/12652 "ScanForFunctions: Speed up game loading" +[#12462]: https://github.com/hrydgard/ppsspp/issues/12462 "Vulkan: Enable renderpass merging for all games" +[#12695]: https://github.com/hrydgard/ppsspp/issues/12695 "New heuristic for getting rid of unnecessary \"antialias-lines\"." +[#11898]: https://github.com/hrydgard/ppsspp/issues/11898 "Strike Witches - Hakugin no Tsubasa missing intro video" +[#12941]: https://github.com/hrydgard/ppsspp/issues/12941 "Vulkan: Deal with the reformat clear better" +[#12857]: https://github.com/hrydgard/ppsspp/issues/12857 "Mumbo Jumbo games freeze on loading screen since v1.6" +[#12635]: https://github.com/hrydgard/ppsspp/issues/12635 "Kernel: Delay better in sceKernelReferThreadStatus" +[#12670]: https://github.com/hrydgard/ppsspp/issues/12670 "Attempts to replace 0 frame width with valid frame width.(sceMpegAvcCsc)" +[#12800]: https://github.com/hrydgard/ppsspp/issues/12800 "x86jit: Force INF * 0 to +NAN" +[#13071]: https://github.com/hrydgard/ppsspp/issues/13071 "D3D9: Fix a sign mistake generating the projection matrix." +[#13076]: https://github.com/hrydgard/ppsspp/issues/13076 "Add some excessive null checks to GameScreen::render()" +[#13057]: https://github.com/hrydgard/ppsspp/issues/13057 "The 1.10 Android mystery crash thread!" +[#13077]: https://github.com/hrydgard/ppsspp/issues/13077 "SaveState: Make sure to default init net data" +[#13096]: https://github.com/hrydgard/ppsspp/issues/13096 "Revert \"Remove the I/O on Thread option - treat it as always on.\"" +[#13095]: https://github.com/hrydgard/ppsspp/issues/13095 "http: Check cancel flag more often" +[#13093]: https://github.com/hrydgard/ppsspp/issues/13093 "Add a try/catch to Android camera device listing." +[#13094]: https://github.com/hrydgard/ppsspp/issues/13094 "Camera initialization crash fix" +[#13125]: https://github.com/hrydgard/ppsspp/issues/13125 "Refactor and fix touch control layout screen for notch" +[#13633]: https://github.com/hrydgard/ppsspp/issues/13633 "Downstream Panic (US) New Game crashes" +[#13969]: https://github.com/hrydgard/ppsspp/issues/13969 "Io: Don't allow async close while async busy" +[#13368]: https://github.com/hrydgard/ppsspp/issues/13368 "Reschedule after resuming thread from suspend." +[#13204]: https://github.com/hrydgard/ppsspp/issues/13204 "Dissidia Final Fantasy Chinese patch invalid address" +[#8526]: https://github.com/hrydgard/ppsspp/issues/8526 "Xyanide Resurrection freezing" +[#4671]: https://github.com/hrydgard/ppsspp/issues/4671 "Capcom Classic Collection Reloaded stuck in return game" +[#6025]: https://github.com/hrydgard/ppsspp/issues/6025 "Dream Club Portable crash after select girl" +[#13298]: https://github.com/hrydgard/ppsspp/issues/13298 "Fix sceKernelExitThread" +[#13297]: https://github.com/hrydgard/ppsspp/issues/13297 "Namco Museum Vol. 2 - ULJS00047 infinite loading in some game" +[#9523]: https://github.com/hrydgard/ppsspp/issues/9523 "Namco Museum - Battle Collection - ULUS100035 loading problem" +[#5213]: https://github.com/hrydgard/ppsspp/issues/5213 "Hanayaka Nari Wa ga Ichizoku strange MP3 mono voice" +[#12761]: https://github.com/hrydgard/ppsspp/issues/12761 "[Android][OpenGL&Vulkan][Save issue] Assassin's Creed : Bloodlines (ULJM05571)" +[#13335]: https://github.com/hrydgard/ppsspp/issues/13335 "Support for loading game-specific plugins" +[#12924]: https://github.com/hrydgard/ppsspp/issues/12924 "Postprocessing: User chain support" +[#13654]: https://github.com/hrydgard/ppsspp/issues/13654 "Expose the \"Lower resolution for effects\" setting in libretro." +[#13695]: https://github.com/hrydgard/ppsspp/issues/13695 "Add developer setting \"Show on-screen messages\". Uncheck to hide them." +[#13866]: https://github.com/hrydgard/ppsspp/issues/13866 "SaveState: Allow rewind on mobile" +[#13355]: https://github.com/hrydgard/ppsspp/issues/13355 "Refactor framebuffer attachment. Fixes Test Drive Unlimited performance" +[#13556]: https://github.com/hrydgard/ppsspp/issues/13556 "D3D11 depth texture support" +[#13262]: https://github.com/hrydgard/ppsspp/issues/13262 "Implement texturing from depth buffers (Vulkan only so far)" +[#13986]: https://github.com/hrydgard/ppsspp/issues/13986 "Vulkan: Add MMPX upscaling texture shader" +[#13514]: https://github.com/hrydgard/ppsspp/issues/13514 "Vulkan: Automatically generate mipmaps for replaced/scaled textures" +[#13235]: https://github.com/hrydgard/ppsspp/issues/13235 "Vulkan: Allow custom texture upscaling shaders" +[#13526]: https://github.com/hrydgard/ppsspp/issues/13526 "VFPU: Compute sines and cosines in double precision." +[#13706]: https://github.com/hrydgard/ppsspp/issues/13706 "Add back the old implementation of vfpu_sin/cos/sincos." +[#12336]: https://github.com/hrydgard/ppsspp/issues/12336 "Microphone support" +[#13792]: https://github.com/hrydgard/ppsspp/issues/13792 "Fix UWP audio and a hang bug" +[#13239]: https://github.com/hrydgard/ppsspp/issues/13239 "Add sound effects for PPSSPP interface navigation" +[#13897]: https://github.com/hrydgard/ppsspp/issues/13897 "LittleBigPlanet - Game Not Loading, Blue Screen (iOS, Unplayable)" +[#13172]: https://github.com/hrydgard/ppsspp/issues/13172 "Generalized multi-instance" +[#13092]: https://github.com/hrydgard/ppsspp/issues/13092 "Bad memory access handling improvements" +[#11795]: https://github.com/hrydgard/ppsspp/issues/11795 "Exception handler - catch bad memory accesses" +[#7124]: https://github.com/hrydgard/ppsspp/issues/7124 "Yu-Gi-Oh! GX Tag Force Card summoning (card cut-off / cropped)" +[#13760]: https://github.com/hrydgard/ppsspp/issues/13760 "Fix car lighting issues in DiRT 2." +[#13640]: https://github.com/hrydgard/ppsspp/issues/13640 "Fix car reflections in Outrun" +[#13636]: https://github.com/hrydgard/ppsspp/issues/13636 "Reinterpret framebuffer formats as needed. Outrun reflections partial fix" +[#14117]: https://github.com/hrydgard/ppsspp/issues/14117 "[Adhoc] Fix lob" +[#14106]: https://github.com/hrydgard/ppsspp/issues/14106 "[Adhoc] Fix frozen (0 FPS) issue on Kao Challengers and Asterix & Obelix XX" +[#14078]: https://github.com/hrydgard/ppsspp/issues/14078 "PPGe: Decimate text images properly" +[#14101]: https://github.com/hrydgard/ppsspp/issues/14101 "Menu audio glitchfix" +[#14092]: https://github.com/hrydgard/ppsspp/issues/14092 "SaveState: Prevent crash on bad cookie marker" +[#14091]: https://github.com/hrydgard/ppsspp/issues/14091 "Only allow sceMpegGetAvcAu warmup for God Eater Series" +[#14089]: https://github.com/hrydgard/ppsspp/issues/14089 "GL: Call CreateDeviceObjects *after* updating render_." +[#14085]: https://github.com/hrydgard/ppsspp/issues/14085 "Handle exec addr errors better - don't let IgnoreBadMemoryAccesses skip dispatcher exceptions" +[#14132]: https://github.com/hrydgard/ppsspp/issues/14132 "Io: Truncate reads/writes to valid memory" +[#14134]: https://github.com/hrydgard/ppsspp/issues/14134 "Android: Ensure shutdown waits for render" +[#14129]: https://github.com/hrydgard/ppsspp/issues/14129 "GPU: Force reinterpret off without copy image" From 5f2e20d8ca63fc60c3cbddebd8a1176cd511f734 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 18:39:14 -0700 Subject: [PATCH 58/69] softgpu: Reduce some minor bin item field sizes. --- GPU/Software/BinManager.cpp | 4 ++-- GPU/Software/BinManager.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/GPU/Software/BinManager.cpp b/GPU/Software/BinManager.cpp index faaf7b03a8..9c1c1ff3ef 100644 --- a/GPU/Software/BinManager.cpp +++ b/GPU/Software/BinManager.cpp @@ -166,7 +166,7 @@ void BinManager::UpdateState(bool throughMode) { if (HasDirty(SoftDirty::PIXEL_ALL | SoftDirty::SAMPLER_ALL | SoftDirty::RAST_ALL)) { if (states_.Full()) Flush("states"); - stateIndex_ = (int)states_.Push(RasterizerState()); + stateIndex_ = (uint16_t)states_.Push(RasterizerState()); ComputeRasterizerState(&states_[stateIndex_], throughMode); states_[stateIndex_].samplerID.cached.clut = cluts_[clutIndex_].readable; @@ -312,7 +312,7 @@ void BinManager::UpdateClut(const void *src) { PROFILE_THIS_SCOPE("bin_clut"); if (cluts_.Full()) Flush("cluts"); - clutIndex_ = (int)cluts_.Push(BinClut()); + clutIndex_ = (uint16_t)cluts_.Push(BinClut()); memcpy(cluts_[clutIndex_].readable, src, sizeof(BinClut)); } diff --git a/GPU/Software/BinManager.h b/GPU/Software/BinManager.h index 1d628aa8e4..79146eae1d 100644 --- a/GPU/Software/BinManager.h +++ b/GPU/Software/BinManager.h @@ -24,7 +24,7 @@ struct BinWaitable; class DrawBinItemsTask; -enum class BinItemType { +enum class BinItemType : uint8_t { TRIANGLE, CLEAR_RECT, RECT, @@ -48,7 +48,7 @@ struct BinCoords { struct BinItem { BinItemType type; - int stateIndex; + uint16_t stateIndex; BinCoords range; VertexData v0; VertexData v1; @@ -237,9 +237,9 @@ protected: private: BinStateQueue states_; - int stateIndex_; BinClutQueue cluts_; - int clutIndex_; + uint16_t stateIndex_; + uint16_t clutIndex_; BinCoords scissor_; BinItemQueue queue_; BinCoords queueRange_; From 8a2115be463cacedace4d63c07a5f35c73a0a123 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 18:39:39 -0700 Subject: [PATCH 59/69] softgpu: Enable early Z tests a bit more often. This helps in cases where sfail doesn't matter. --- GPU/Software/FuncId.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/GPU/Software/FuncId.cpp b/GPU/Software/FuncId.cpp index 0471114caa..f66064f0cf 100644 --- a/GPU/Software/FuncId.cpp +++ b/GPU/Software/FuncId.cpp @@ -93,13 +93,6 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) { if (gstate.FrameBufFormat() != GE_FORMAT_565 && gstate.getStencilOpZPass() <= GE_STENCILOP_DECR) id->zPass = gstate.getStencilOpZPass(); - // Always treat zPass/zFail the same if there's no depth test. - if (!gstate.isDepthTestEnabled() || gstate.getDepthTestFunction() == GE_COMP_ALWAYS) - id->zFail = id->zPass; - // And same for sFail if there's no stencil test. - if (id->StencilTestFunc() == GE_COMP_ALWAYS) - id->sFail = id->zPass; - // Normalize REPLACE 00 to ZERO, especially if using a mask. if (gstate.getStencilTestRef() == 0) { if (id->SFail() == GE_STENCILOP_REPLACE) @@ -120,6 +113,13 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) { id->zPass = GE_STENCILOP_ZERO; } + // Always treat zPass/zFail the same if there's no depth test. + if (!gstate.isDepthTestEnabled() || gstate.getDepthTestFunction() == GE_COMP_ALWAYS) + id->zFail = id->zPass; + // And same for sFail if there's no stencil test. Prefer KEEP, though. + if (id->StencilTestFunc() == GE_COMP_ALWAYS) + id->sFail = id->ZFail() == GE_STENCILOP_KEEP ? GE_STENCILOP_KEEP : id->zPass; + // Turn off stencil testing if it's doing nothing. if (id->SFail() == GE_STENCILOP_KEEP && id->ZFail() == GE_STENCILOP_KEEP && id->ZPass() == GE_STENCILOP_KEEP) { if (id->StencilTestFunc() == GE_COMP_ALWAYS) From 8a6e8066bfe3ef2b961bdd2fc1174bc75e5df48d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 18:41:06 -0700 Subject: [PATCH 60/69] softgpu: Store vertex colors as packed RGBA8. No need to keep it expanded at 4x the space for both colors. --- GPU/Software/Lighting.cpp | 8 +++--- GPU/Software/Rasterizer.cpp | 42 ++++++++++++++++++---------- GPU/Software/RasterizerRectangle.cpp | 17 +++++------ GPU/Software/TransformUnit.cpp | 18 ++---------- GPU/Software/TransformUnit.h | 10 +++---- 5 files changed, 48 insertions(+), 47 deletions(-) diff --git a/GPU/Software/Lighting.cpp b/GPU/Software/Lighting.cpp index 262811318f..32596989fe 100644 --- a/GPU/Software/Lighting.cpp +++ b/GPU/Software/Lighting.cpp @@ -276,12 +276,12 @@ void Process(VertexData &vertex, const WorldCoords &worldpos, const WorldCoords } if (state.setColor1) { - vertex.color0 = final_color.Clamp(0, 255); - vertex.color1 = specular_color.Clamp(0, 255).rgb(); + vertex.color0 = final_color.Clamp(0, 255).ToRGBA(); + vertex.color1 = specular_color.Clamp(0, 255).rgb().ToRGB(); } else if (state.addColor1) { - vertex.color0 = (final_color + specular_color).Clamp(0, 255); + vertex.color0 = (final_color + specular_color).Clamp(0, 255).ToRGBA(); } else { - vertex.color0 = final_color.Clamp(0, 255); + vertex.color0 = final_color.Clamp(0, 255).ToRGBA(); } } diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index 0348f6d57a..a47ed9b0da 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -721,6 +721,13 @@ void DrawTriangleSlice( std::string ztag = StringFromFormat("DisplayListTZ_%08x", state.listPC); #endif + const Vec4 v0_c0 = Vec4::FromRGBA(v0.color0); + const Vec4 v1_c0 = Vec4::FromRGBA(v1.color0); + const Vec4 v2_c0 = Vec4::FromRGBA(v2.color0); + const Vec3 v0_c1 = Vec3::FromRGB(v0.color1); + const Vec3 v1_c1 = Vec3::FromRGB(v1.color1); + const Vec3 v2_c1 = Vec3::FromRGB(v2.color1); + for (int64_t curY = minY; curY <= maxY; curY += SCREEN_SCALE_FACTOR * 2, w0_base = e0.StepY(w0_base), w1_base = e1.StepY(w1_base), @@ -790,22 +797,22 @@ void DrawTriangleSlice( if (!flatColor0) { for (int i = 0; i < 4; ++i) { if (mask[i] >= 0) - prim_color[i] = Interpolate(v0.color0, v1.color0, v2.color0, w0[i], w1[i], w2[i], wsum_recip[i]); + prim_color[i] = Interpolate(v0_c0, v1_c0, v2_c0, w0[i], w1[i], w2[i], wsum_recip[i]); } } else { for (int i = 0; i < 4; ++i) { - prim_color[i] = v2.color0; + prim_color[i] = v2_c0; } } Vec3 sec_color[4]; if (!flatColor1) { for (int i = 0; i < 4; ++i) { if (mask[i] >= 0) - sec_color[i] = Interpolate(v0.color1, v1.color1, v2.color1, w0[i], w1[i], w2[i], wsum_recip[i]); + sec_color[i] = Interpolate(v0_c1, v1_c1, v2_c1, w0[i], w1[i], w2[i], wsum_recip[i]); } } else { for (int i = 0; i < 4; ++i) { - sec_color[i] = v2.color1; + sec_color[i] = v2_c1; } } @@ -965,9 +972,10 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords & const Vec4f tto4(0.0f, 0.5f * stx.t(), 0.5f * sty.t(), 0.5f * stx.t() + 0.5f * sty.t()); ScreenCoords pprime(minX, minY, 0); - Vec4 fog = Vec4::AssignToAll(ClampFogDepth(v1.fogdepth)); - Vec4 z = Vec4::AssignToAll(v1.screenpos.z); - Vec3 sec_color = v1.color1; + const Vec4 fog = Vec4::AssignToAll(ClampFogDepth(v1.fogdepth)); + const Vec4 z = Vec4::AssignToAll(v1.screenpos.z); + const Vec4 c0 = Vec4::FromRGBA(v1.color0); + const Vec3 sec_color = Vec3::FromRGB(v1.color1); if (state.pixelID.applyDepthRange) { // We can bail early since the Z is flat. @@ -997,7 +1005,7 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords & Vec4 prim_color[4]; for (int i = 0; i < 4; ++i) { - prim_color[i] = v1.color0; + prim_color[i] = c0; } if (state.pixelID.earlyZChecks) { @@ -1073,8 +1081,8 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords & void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerState &state) { ScreenCoords pos = v0.screenpos; - Vec4 prim_color = v0.color0; - Vec3 sec_color = v0.color1; + Vec4 prim_color = Vec4::FromRGBA(v0.color0); + Vec3 sec_color = Vec3::FromRGB(v0.color1); auto &pixelID = state.pixelID; auto &samplerID = state.samplerID; @@ -1218,7 +1226,7 @@ void ClearRectangle(const VertexData &v0, const VertexData &v1, const BinCoords keepOldMask |= pixelID.cached.colorWriteMask; } - const u32 new_color = v1.color0.ToRGBA(); + const u32 new_color = v1.color0; u16 new_color16; switch (pixelID.FBFormat()) { case GE_FORMAT_565: @@ -1343,6 +1351,10 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range auto &samplerID = state.samplerID; const bool interpolateColor = !state.shadeGouraud || (v0.color0 == v1.color0 && v0.color1 == v1.color1); + const Vec4 v0_c0 = Vec4::FromRGBA(v0.color0); + const Vec4 v1_c0 = Vec4::FromRGBA(v1.color0); + const Vec3 v0_c1 = Vec3::FromRGB(v0.color1); + const Vec3 v1_c1 = Vec3::FromRGB(v1.color1); #if defined(SOFTGPU_MEMORY_TAGGING_DETAILED) || defined(SOFTGPU_MEMORY_TAGGING_BASIC) std::string tag = StringFromFormat("DisplayListL_%08x", state.listPC); @@ -1375,11 +1387,11 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range Vec4 prim_color; Vec3 sec_color; if (interpolateColor) { - prim_color = (v0.color0 * (steps - i) + v1.color0 * i) / steps1; - sec_color = (v0.color1 * (steps - i) + v1.color1 * i) / steps1; + prim_color = (v0_c0 * (steps - i) + v1_c0 * i) / steps1; + sec_color = (v0_c1 * (steps - i) + v1_c1 * i) / steps1; } else { - prim_color = v1.color0; - sec_color = v1.color1; + prim_color = v1_c0; + sec_color = v1_c1; } u8 fog = 255; diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index c94e23beb6..6d3d490ae4 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -119,7 +119,7 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran int z = v1.screenpos.z; int fog = 255; - bool isWhite = v1.color0 == Vec4(255, 255, 255, 255); + bool isWhite = v1.color0 == 0xFFFFFFFF; if (state.enableTextures) { // 1:1 (but with mirror support) texture mapping! @@ -176,11 +176,12 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran } } else { int t = t_start; + const Vec4 c0 = Vec4::FromRGBA(v1.color0); for (int y = pos0.y; y < pos1.y; y++) { int s = s_start; u16 *pixel = fb.Get16Ptr(pos0.x, y, pixelID.cached.framebufStride); for (int x = pos0.x; x < pos1.x; x++) { - Vec4 prim_color = v1.color0; + Vec4 prim_color = c0; Vec4 tex_color = fetchFunc(s, t, texptr, texbufw, 0, state.samplerID); prim_color = Vec4(ModulateRGBA(ToVec4IntArg(prim_color), ToVec4IntArg(tex_color), state.samplerID)); if (prim_color.a() > 0) { @@ -202,11 +203,12 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran float tf_start = t_start * (1.0f / (float)(1 << state.samplerID.height0Shift)); float t = tf_start; + const Vec4 c0 = Vec4::FromRGBA(v1.color0); for (int y = pos0.y; y < pos1.y; y++) { float s = sf_start; // Not really that fast but faster than triangle. for (int x = pos0.x; x < pos1.x; x++) { - Vec4 prim_color = state.nearest(s, t, xoff, yoff, ToVec4IntArg(v1.color0), &texptr, &texbufw, 0, 0, state.samplerID); + Vec4 prim_color = state.nearest(s, t, xoff, yoff, ToVec4IntArg(c0), &texptr, &texbufw, 0, 0, state.samplerID); state.drawPixel(x, y, z, 255, ToVec4IntArg(prim_color), pixelID); s += dsf; } @@ -227,21 +229,20 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran AlphaTestIsNeedless(pixelID) && !pixelID.applyColorWriteMask && pixelID.FBFormat() == GE_FORMAT_5551) { - if (v1.color0.a() == 0) + if (Vec4::FromRGBA(v1.color0).a() == 0) return; for (int y = pos0.y; y < pos1.y; y++) { u16 *pixel = fb.Get16Ptr(pos0.x, y, pixelID.cached.framebufStride); for (int x = pos0.x; x < pos1.x; x++) { - Vec4 prim_color = v1.color0; - DrawSinglePixel5551(pixel, prim_color.ToRGBA(), pixelID); + DrawSinglePixel5551(pixel, v1.color0, pixelID); pixel++; } } } else { + const Vec4 prim_color = Vec4::FromRGBA(v1.color0); for (int y = pos0.y; y < pos1.y; y++) { for (int x = pos0.x; x < pos1.x; x++) { - Vec4 prim_color = v1.color0; state.drawPixel(x, y, z, fog, ToVec4IntArg(prim_color), pixelID); } } @@ -311,7 +312,7 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &b // Afterwards, we also need to clear the actual destination. Can do a fast rectfill. gstate.textureMapEnable &= ~1; VertexData newV1 = v1; - newV1.color0 = Vec4(0, 0, 0, 255); + newV1.color0 = 0xFF000000; binner.AddSprite(v0, newV1); gstate.textureMapEnable |= 1; } diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 28a91a7a8c..2c9a96221d 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -317,24 +317,12 @@ VertexData TransformUnit::ReadVertex(VertexReader &vreader, const TransformState } if (vreader.hasColor0()) { -#ifdef _M_SSE - vreader.ReadColor0_8888((u8 *)vertex.color0.AsArray()); - vertex.color0.ivec = _mm_unpacklo_epi8(vertex.color0.ivec, _mm_setzero_si128()); - vertex.color0.ivec = _mm_unpacklo_epi16(vertex.color0.ivec, _mm_setzero_si128()); -#else - float col[4]; - vreader.ReadColor0(col); - vertex.color0 = Vec4(col[0]*255, col[1]*255, col[2]*255, col[3]*255); -#endif + vreader.ReadColor0_8888((u8 *)&vertex.color0); } else { - vertex.color0 = Vec4::FromRGBA(gstate.getMaterialAmbientRGBA()); + vertex.color0 = gstate.getMaterialAmbientRGBA(); } -#ifdef _M_SSE - vertex.color1 = _mm_setzero_si128(); -#else - vertex.color1 = Vec3(0, 0, 0); -#endif + vertex.color1 = 0; if (state.enableTransform) { WorldCoords worldpos; diff --git a/GPU/Software/TransformUnit.h b/GPU/Software/TransformUnit.h index faa761639c..283273b2c2 100644 --- a/GPU/Software/TransformUnit.h +++ b/GPU/Software/TransformUnit.h @@ -79,15 +79,15 @@ struct VertexData { texturecoords = ::Lerp(a.texturecoords, b.texturecoords, t); fogdepth = ::Lerp(a.fogdepth, b.fogdepth, t); - u16 t_int = (u16)(t*256); - color0 = LerpInt,256>(a.color0, b.color0, t_int); - color1 = LerpInt,256>(a.color1, b.color1, t_int); + u16 t_int = (u16)(t * 256); + color0 = LerpInt, 256>(Vec4::FromRGBA(a.color0), Vec4::FromRGBA(b.color0), t_int).ToRGBA(); + color1 = LerpInt, 256>(Vec3::FromRGB(a.color1), Vec3::FromRGB(b.color1), t_int).ToRGB(); } ClipCoords clippos; Vec2 texturecoords; - Vec4 color0; - Vec3 color1; + uint32_t color0; + uint32_t color1; ScreenCoords screenpos; // TODO: Shouldn't store this ? float fogdepth; }; From ce4fee737352f2d23122d5f269d306bf7d4a4a09 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 21:14:47 -0700 Subject: [PATCH 61/69] softgpu: Refactor triangle cull processing. --- GPU/Software/TransformUnit.cpp | 54 ++++++++++++---------------------- GPU/Software/TransformUnit.h | 7 +++++ 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 28a91a7a8c..aa31e3edf6 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -447,12 +447,6 @@ SoftDirty TransformUnit::GetDirty() { return binner_->GetDirty(); } -enum class CullType { - CW, - CCW, - OFF, -}; - void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, GEPrimitiveType prim_type, int vertex_count, u32 vertex_type, int *bytesRead, SoftwareDrawEngine *drawEngine) { VertexDecoder &vdecoder = *drawEngine->FindVertexDecoder(vertex_type); @@ -541,17 +535,8 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G switch (prim_type) { case GE_PRIM_TRIANGLES: - { - if (cullType == CullType::OFF) { - Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[2], *binner_); - Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[2], *binner_); - } else if (cullType == CullType::CW) { - Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[2], *binner_); - } else { - Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[2], *binner_); - } + SendTriangle(cullType, &data_[0]); break; - } case GE_PRIM_LINES: Clipper::ProcessLine(data_[0], data_[1], *binner_); @@ -688,16 +673,9 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G continue; } - if (cullType == CullType::OFF) { - Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); - Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); - } else if ((!(int)cullType) ^ ((data_index_ - 1) % 2)) { - // We need to reverse the vertex order for each second primitive, - // but we additionally need to do that for every primitive if CCW cullmode is used. - Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); - } else { - Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); - } + int wind = (data_index_ - 1) % 2; + CullType altCullType = cullType == CullType::OFF ? cullType : CullType((int)cullType ^ wind); + SendTriangle(altCullType, &data_[0], provoking_index); } break; } @@ -764,16 +742,9 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G continue; } - if (cullType == CullType::OFF) { - Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); - Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); - } else if ((!(int)cullType) ^ ((data_index_ - 1) % 2)) { - // We need to reverse the vertex order for each second primitive, - // but we additionally need to do that for every primitive if CCW cullmode is used. - Clipper::ProcessTriangle(data_[2], data_[1], data_[0], data_[provoking_index], *binner_); - } else { - Clipper::ProcessTriangle(data_[0], data_[1], data_[2], data_[provoking_index], *binner_); - } + int wind = (data_index_ - 1) % 2; + CullType altCullType = cullType == CullType::OFF ? cullType : CullType((int)cullType ^ wind); + SendTriangle(altCullType, &data_[0], provoking_index); } break; } @@ -784,6 +755,17 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G } } +void TransformUnit::SendTriangle(CullType cullType, const VertexData *verts, int provoking) { + if (cullType == CullType::OFF) { + Clipper::ProcessTriangle(verts[0], verts[1], verts[2], verts[provoking], *binner_); + Clipper::ProcessTriangle(verts[2], verts[1], verts[0], verts[provoking], *binner_); + } else if (cullType == CullType::CW) { + Clipper::ProcessTriangle(verts[2], verts[1], verts[0], verts[provoking], *binner_); + } else { + Clipper::ProcessTriangle(verts[0], verts[1], verts[2], verts[provoking], *binner_); + } +} + void TransformUnit::Flush(const char *reason) { binner_->Flush(reason); GPUDebug::NotifyDraw(); diff --git a/GPU/Software/TransformUnit.h b/GPU/Software/TransformUnit.h index faa761639c..ec5883e8e2 100644 --- a/GPU/Software/TransformUnit.h +++ b/GPU/Software/TransformUnit.h @@ -37,6 +37,12 @@ typedef Vec4 ClipCoords; // Range: -w <= x/y/z <= w class BinManager; struct TransformState; +enum class CullType { + CW = 0, + CCW = 1, + OFF = 2, +}; + struct ScreenCoords { ScreenCoords() {} @@ -133,6 +139,7 @@ public: private: VertexData ReadVertex(VertexReader &vreader, const TransformState &lstate, bool &outside_range_flag); + void SendTriangle(CullType cullType, const VertexData *verts, int provoking = 2); u8 *decoded_ = nullptr; BinManager *binner_ = nullptr; From 288d18447d1b16698db4c6c016956ad162d877e2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 21:15:21 -0700 Subject: [PATCH 62/69] softgpu: Detect full triangles as rectangles. Seen in a dump from Infected, improves FPS ~25% there. --- GPU/Software/RasterizerRectangle.cpp | 47 +++++++++++++++++++++++ GPU/Software/RasterizerRectangle.h | 1 + GPU/Software/TransformUnit.cpp | 57 ++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index c94e23beb6..92f167cdda 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -447,6 +447,53 @@ bool DetectRectangleFromFan(const RasterizerState &state, const VertexData *data return false; } +bool DetectRectangleFromPair(const RasterizerState &state, const VertexData data[6], int *tlIndex, int *brIndex) { + // Color and Z must be flat. Also find the TL and BR meanwhile. + int tl = 0, br = 0; + for (int i = 1; i < 6; ++i) { + if (!AreCoordsRectangleCompatible(state, data[i], data[0])) + return false; + + if (data[i].screenpos.x <= data[tl].screenpos.x && data[i].screenpos.y <= data[tl].screenpos.y) + tl = i; + if (data[i].screenpos.x >= data[br].screenpos.x && data[i].screenpos.y >= data[br].screenpos.y) + br = i; + } + + *tlIndex = tl; + *brIndex = br; + + auto xat = [&](int i) { return data[i].screenpos.x; }; + auto yat = [&](int i) { return data[i].screenpos.y; }; + auto uat = [&](int i) { return data[i].texturecoords.x; }; + auto vat = [&](int i) { return data[i].texturecoords.y; }; + + // A likely order would be: TL, TR, BR, TL, BR, BL. We'd have the last index of each. + // TODO: Make more generic. + if (tl == 3 && br == 4) { + bool x1_match = xat(0) == xat(3) && xat(0) == xat(5); + bool x2_match = xat(1) == xat(2) && xat(1) == xat(4); + bool y1_match = yat(0) == yat(1) && yat(0) == yat(3); + bool y2_match = yat(2) == yat(4) && yat(2) == yat(5); + if (x1_match && y1_match && x2_match && y2_match) { + // Do we need to think about rotation or UVs? + if (!state.enableTextures) + return true; + + x1_match = uat(0) == uat(3) && uat(0) == uat(5); + x2_match = uat(1) == uat(2) && uat(1) == uat(4); + y1_match = vat(0) == vat(1) && vat(0) == vat(3); + y2_match = vat(2) == vat(4) && vat(2) == vat(5); + if (x1_match && y1_match && x2_match && y2_match) { + // Double check rotation direction. + return vat(tl) < vat(br) && yat(tl) < yat(br) && uat(tl) < uat(br) && xat(tl) < xat(br); + } + } + } + + return false; +} + bool DetectRectangleThroughModeSlices(const RasterizerState &state, const VertexData data[4]) { // Color and Z must be flat. for (int i = 1; i < 4; ++i) { diff --git a/GPU/Software/RasterizerRectangle.h b/GPU/Software/RasterizerRectangle.h index 4407b10a01..6842215338 100644 --- a/GPU/Software/RasterizerRectangle.h +++ b/GPU/Software/RasterizerRectangle.h @@ -22,5 +22,6 @@ namespace Rasterizer { bool DetectRectangleFromStrip(const RasterizerState &state, const VertexData data[4], int *tlIndex, int *brIndex); bool DetectRectangleFromFan(const RasterizerState &state, const VertexData *data, int c, int *tlIndex, int *brIndex); + bool DetectRectangleFromPair(const RasterizerState &state, const VertexData data[6], int *tlIndex, int *brIndex); bool DetectRectangleThroughModeSlices(const RasterizerState &state, const VertexData data[4]); } diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index aa31e3edf6..f19459606f 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -507,6 +507,63 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G const CullType cullType = skipCull ? CullType::OFF : (gstate.getCullMode() ? CullType::CCW : CullType::CW); bool outside_range_flag = false; + + if (vreader.isThrough() && cullType == CullType::OFF && prim_type == GE_PRIM_TRIANGLES && data_index_ + vertex_count >= 6 && ((data_index_ + vertex_count) % 6) == 0) { + // Some games send rectangles as a series of regular triangles. + // We look for this, but only in throughmode. + VertexData buf[6]; + int buf_index = data_index_; + for (int i = 0; i < data_index_; ++i) { + buf[i] = data_[i]; + } + + for (int vtx = 0; vtx < vertex_count; ++vtx) { + if (indices) { + vreader.Goto(ConvertIndex(vtx) - index_lower_bound); + } else { + vreader.Goto(vtx); + } + + buf[buf_index++] = ReadVertex(vreader, transformState, outside_range_flag); + if (buf_index >= 3 && outside_range_flag) { + // Cull, just pretend it didn't happen. + buf_index -= 3; + outside_range_flag = false; + continue; + } + + if (buf_index < 6) + continue; + + int tl = -1, br = -1; + if (Rasterizer::DetectRectangleFromPair(binner_->State(), buf, &tl, &br)) { + Clipper::ProcessRect(buf[tl], buf[br], *binner_); + } else { + SendTriangle(cullType, &buf[0]); + SendTriangle(cullType, &buf[3]); + } + + buf_index = 0; + } + + if (buf_index >= 3) { + SendTriangle(cullType, &buf[0]); + data_index_ = 0; + for (int i = 3; i < buf_index; ++i) { + data_[data_index_++] = buf[i]; + } + } else if (buf_index > 0) { + for (int i = 0; i < buf_index; ++i) { + data_[i] = buf[i]; + } + data_index_ = buf_index; + } else { + data_index_ = 0; + } + + return; + } + switch (prim_type) { case GE_PRIM_POINTS: case GE_PRIM_LINES: From 151727ee01a80c8cd07b2915ebe65b64e7b79f65 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 21:49:37 -0700 Subject: [PATCH 63/69] softgpu: Detect longer strips of rectangles. Could maybe even combine these into one large rectangle, but the main benefit is avoiding triangles. --- GPU/Software/TransformUnit.cpp | 44 ++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index f19459606f..158cccf3b8 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -686,30 +686,44 @@ void TransformUnit::SubmitPrimitive(const void* vertices, const void* indices, G { // Don't draw a triangle when loading the first two vertices. int skip_count = data_index_ >= 2 ? 0 : 2 - data_index_; + int start_vtx = 0; // If index count == 4, check if we can convert to a rectangle. // This is for Darkstalkers (and should speed up many 2D games). - if (data_index_ == 0 && vertex_count == 4 && cullType == CullType::OFF) { - for (int vtx = 0; vtx < 4; ++vtx) { - if (indices) { - vreader.Goto(ConvertIndex(vtx) - index_lower_bound); + if (data_index_ == 0 && vertex_count >= 4 && (vertex_count & 1) == 0 && cullType == CullType::OFF) { + for (int base = 0; base < vertex_count - 2; base += 2) { + for (int vtx = base == 0 ? 0 : 2; vtx < 4; ++vtx) { + if (indices) { + vreader.Goto(ConvertIndex(base + vtx) - index_lower_bound); + } else { + vreader.Goto(base + vtx); + } + data_[vtx] = ReadVertex(vreader, transformState, outside_range_flag); } - else { - vreader.Goto(vtx); - } - data_[vtx] = ReadVertex(vreader, transformState, outside_range_flag); - } - // If a strip is effectively a rectangle, draw it as such! - int tl = -1, br = -1; - if (!outside_range_flag && Rasterizer::DetectRectangleFromStrip(binner_->State(), data_, &tl, &br)) { - Clipper::ProcessRect(data_[tl], data_[br], *binner_); - break; + // If a strip is effectively a rectangle, draw it as such! + int tl = -1, br = -1; + if (!outside_range_flag && Rasterizer::DetectRectangleFromStrip(binner_->State(), data_, &tl, &br)) { + Clipper::ProcessRect(data_[tl], data_[br], *binner_); + start_vtx += 2; + if (base + 4 >= vertex_count) { + start_vtx = vertex_count; + break; + } + + // Just copy the first two so we can detect easier. + // TODO: Maybe should give detection two halves? + data_[0] = data_[2]; + data_[1] = data_[3]; + } else { + // Go into triangle mode. Unfortunately, we re-read the verts. + break; + } } } outside_range_flag = false; - for (int vtx = 0; vtx < vertex_count; ++vtx) { + for (int vtx = start_vtx; vtx < vertex_count; ++vtx) { if (indices) { vreader.Goto(ConvertIndex(vtx) - index_lower_bound); } else { From 1f6870798b66f05f663d01180d3b0508c7dd517d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 21:57:22 -0700 Subject: [PATCH 64/69] softgpu: Include early Z in func description. --- GPU/Software/FuncId.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GPU/Software/FuncId.cpp b/GPU/Software/FuncId.cpp index 0471114caa..fe0b62be43 100644 --- a/GPU/Software/FuncId.cpp +++ b/GPU/Software/FuncId.cpp @@ -279,6 +279,8 @@ std::string DescribePixelFuncID(const PixelFuncID &id) { desc = "INVALID:" + desc; } + if (id.earlyZChecks) + desc += "ZEarly:"; if (id.DepthTestFunc() != GE_COMP_ALWAYS) { if (id.clearMode) desc = "INVALID:" + desc; From 3c9372fb751eb354e7414638757cdc88789353e8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 11 Sep 2022 22:11:15 -0700 Subject: [PATCH 65/69] softgpu: Ignore stencil test mask in ALWAYS mode. Small codegen improvement since we can directly use ref and avoid loading the unmasked reference. --- GPU/Software/FuncId.cpp | 53 ++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/GPU/Software/FuncId.cpp b/GPU/Software/FuncId.cpp index f66064f0cf..d0979bf631 100644 --- a/GPU/Software/FuncId.cpp +++ b/GPU/Software/FuncId.cpp @@ -79,6 +79,7 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) { id->stencilTest = gstate.isStencilTestEnabled(); } id->depthWrite = gstate.isDepthTestEnabled() && gstate.isDepthWriteEnabled(); + id->depthTestFunc = gstate.isDepthTestEnabled() ? gstate.getDepthTestFunction() : GE_COMP_ALWAYS; if (id->stencilTest) { id->stencilTestRef = gstate.getStencilTestRef() & gstate.getStencilTestMask(); @@ -113,21 +114,27 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) { id->zPass = GE_STENCILOP_ZERO; } - // Always treat zPass/zFail the same if there's no depth test. - if (!gstate.isDepthTestEnabled() || gstate.getDepthTestFunction() == GE_COMP_ALWAYS) - id->zFail = id->zPass; // And same for sFail if there's no stencil test. Prefer KEEP, though. - if (id->StencilTestFunc() == GE_COMP_ALWAYS) - id->sFail = id->ZFail() == GE_STENCILOP_KEEP ? GE_STENCILOP_KEEP : id->zPass; + if (id->StencilTestFunc() == GE_COMP_ALWAYS) { + if (id->DepthTestFunc() == GE_COMP_ALWAYS) + id->zFail = GE_STENCILOP_KEEP; + id->sFail = GE_STENCILOP_KEEP; + // Always doesn't need a mask. + id->stencilTestRef = gstate.getStencilTestRef(); + id->hasStencilTestMask = false; - // Turn off stencil testing if it's doing nothing. - if (id->SFail() == GE_STENCILOP_KEEP && id->ZFail() == GE_STENCILOP_KEEP && id->ZPass() == GE_STENCILOP_KEEP) { - if (id->StencilTestFunc() == GE_COMP_ALWAYS) + // Turn off stencil testing if it's doing nothing. + if (id->SFail() == GE_STENCILOP_KEEP && id->ZFail() == GE_STENCILOP_KEEP && id->ZPass() == GE_STENCILOP_KEEP) { id->stencilTest = false; + id->stencilTestFunc = 0; + id->stencilTestRef = 0; + } + } else if (id->DepthTestFunc() == GE_COMP_ALWAYS) { + // Always treat zPass/zFail the same if there's no depth test. + id->zFail = id->zPass; } } - id->depthTestFunc = gstate.isDepthTestEnabled() ? gstate.getDepthTestFunction() : GE_COMP_ALWAYS; id->alphaTestFunc = gstate.isAlphaTestEnabled() ? gstate.getAlphaTestFunction() : GE_COMP_ALWAYS; if (id->AlphaTestFunc() != GE_COMP_ALWAYS) { id->alphaTestRef = gstate.getAlphaTestRef() & gstate.getAlphaTestMask(); @@ -312,7 +319,8 @@ std::string DescribePixelFuncID(const PixelFuncID &id) { } if (id.hasStencilTestMask) desc += "Msk"; - desc += StringFromFormat("%02X:", id.stencilTestRef); + if (id.StencilTestFunc() != GE_COMP_ALWAYS || id.DepthTestFunc() != GE_COMP_ALWAYS) + desc += StringFromFormat("%02X:", id.stencilTestRef); } else if (id.hasStencilTestMask || id.stencilTestRef != 0 || id.stencilTestFunc != 0) { desc = "INVALID:" + desc; } @@ -333,13 +341,24 @@ std::string DescribePixelFuncID(const PixelFuncID &id) { case GE_STENCILOP_INCR: desc += "ZTstFInc:"; break; case GE_STENCILOP_DECR: desc += "ZTstFDec:"; break; } - switch (id.ZPass()) { - case GE_STENCILOP_KEEP: break; - case GE_STENCILOP_ZERO: desc += "ZTstT0:"; break; - case GE_STENCILOP_REPLACE: desc += "ZTstTRpl:"; break; - case GE_STENCILOP_INVERT: desc += "ZTstTXor:"; break; - case GE_STENCILOP_INCR: desc += "ZTstTInc:"; break; - case GE_STENCILOP_DECR: desc += "ZTstTDec:"; break; + if (id.StencilTestFunc() == GE_COMP_ALWAYS && id.DepthTestFunc() == GE_COMP_ALWAYS) { + switch (id.ZPass()) { + case GE_STENCILOP_KEEP: break; + case GE_STENCILOP_ZERO: desc += "Zero:"; break; + case GE_STENCILOP_REPLACE: desc += StringFromFormat("Rpl%02X:", id.stencilTestRef); break; + case GE_STENCILOP_INVERT: desc += "Xor:"; break; + case GE_STENCILOP_INCR: desc += "Inc:"; break; + case GE_STENCILOP_DECR: desc += "Dec:"; break; + } + } else { + switch (id.ZPass()) { + case GE_STENCILOP_KEEP: break; + case GE_STENCILOP_ZERO: desc += "ZTstT0:"; break; + case GE_STENCILOP_REPLACE: desc += "ZTstTRpl:"; break; + case GE_STENCILOP_INVERT: desc += "ZTstTXor:"; break; + case GE_STENCILOP_INCR: desc += "ZTstTInc:"; break; + case GE_STENCILOP_DECR: desc += "ZTstTDec:"; break; + } } if (!id.stencilTest || id.clearMode) { if (id.sFail != 0 || id.zFail != 0 || id.zPass != 0) From a2eaad544559a52f5bf5075217010576e7fa178e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 12 Sep 2022 11:59:08 +0200 Subject: [PATCH 66/69] Debug-name shader modules with their shader desc strings --- GPU/Vulkan/ShaderManagerVulkan.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index 9cb91e00c6..bcbc6356fe 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -44,7 +44,7 @@ // Most drivers treat vkCreateShaderModule as pretty much a memcpy. What actually // takes time here, and makes this worthy of parallelization, is GLSLtoSPV. -Promise *CompileShaderModuleAsync(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code) { +static Promise *CompileShaderModuleAsync(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, const char *tag) { auto compile = [=] { PROFILE_THIS_SCOPE("shadercomp"); @@ -75,6 +75,9 @@ Promise *CompileShaderModuleAsync(VulkanContext *vulkan, VkShade #ifdef SHADERLOG OutputDebugStringA("OK"); #endif + if (tag) { + vulkan->SetDebugName(shaderModule, VK_OBJECT_TYPE_SHADER_MODULE, tag); + } } return shaderModule; @@ -92,7 +95,7 @@ Promise *CompileShaderModuleAsync(VulkanContext *vulkan, VkShade VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id, FragmentShaderFlags flags, const char *code) : vulkan_(vulkan), id_(id), flags_(flags) { source_ = code; - module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_FRAGMENT_BIT, source_.c_str()); + module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_FRAGMENT_BIT, source_.c_str(), FragmentShaderDesc(id).c_str()); if (!module_) { failed_ = true; } else { @@ -122,7 +125,7 @@ std::string VulkanFragmentShader::GetShaderString(DebugShaderStringType type) co VulkanVertexShader::VulkanVertexShader(VulkanContext *vulkan, VShaderID id, const char *code, bool useHWTransform) : vulkan_(vulkan), useHWTransform_(useHWTransform), id_(id) { source_ = code; - module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_VERTEX_BIT, source_.c_str()); + module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_VERTEX_BIT, source_.c_str(), VertexShaderDesc(id).c_str()); if (!module_) { failed_ = true; } else { From d9989ffc16ab0b4f6c0ddda4abd14e6e5f432310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 12 Sep 2022 12:17:32 +0200 Subject: [PATCH 67/69] Don't start blending in the shader just because there's bitmasks, if blend is disabled. --- GPU/Common/GPUStateUtils.cpp | 4 +++- GPU/Common/GPUStateUtils.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index 9efde97ae6..f801524b43 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -1058,8 +1058,10 @@ static void ConvertBlendState(GenericBlendState &blendState, bool forceReplaceBl ReplaceBlendType replaceBlend = ReplaceBlendWithShader(gstate_c.framebufFormat); if (forceReplaceBlend) { - replaceBlend = REPLACE_BLEND_READ_FRAMEBUFFER; + // Enforce blend replacement if enabled. If not, shouldn't do anything of course. + replaceBlend = blendState.blendEnabled ? REPLACE_BLEND_READ_FRAMEBUFFER : REPLACE_BLEND_NO; } + blendState.replaceBlend = replaceBlend; blendState.simulateLogicOpType = SimulateLogicOpShaderTypeIfNeeded(); diff --git a/GPU/Common/GPUStateUtils.h b/GPU/Common/GPUStateUtils.h index 2055da4657..bc0c9ae7b1 100644 --- a/GPU/Common/GPUStateUtils.h +++ b/GPU/Common/GPUStateUtils.h @@ -245,7 +245,9 @@ struct ComputedPipelineState { void Convert(bool shaderBitOpsSupported); bool FramebufferRead() const { - return blendState.applyFramebufferRead; + // If blending is off, its applyFramebufferRead can be false even after state propagation. + // So it's not enough to check just that one. + return blendState.applyFramebufferRead || maskState.applyFramebufferRead || logicState.applyFramebufferRead; } }; From 4ad345d78da066136058ac8d17a2772e8fa8c8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 12 Sep 2022 14:02:15 +0200 Subject: [PATCH 68/69] Better shader compile logging --- GPU/Vulkan/ShaderManagerVulkan.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index bcbc6356fe..f0028cbac6 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -59,12 +59,13 @@ static Promise *CompileShaderModuleAsync(VulkanContext *vulkan, } else { ERROR_LOG(G3D, "Error in shader compilation!"); } + std::string numberedSource = LineNumberString(code); ERROR_LOG(G3D, "Messages: %s", errorMessage.c_str()); - ERROR_LOG(G3D, "Shader source:\n%s", code); -#ifdef SHADERLOG - OutputDebugStringA(LineNumberString(code).c_str()); + ERROR_LOG(G3D, "Shader source:\n%s", numberedSource.c_str()); +#if PPSSPP_PLATFORM(WINDOWS) OutputDebugStringA("Error messages:\n"); OutputDebugStringA(errorMessage.c_str()); + OutputDebugStringA(numberedSource.c_str()); #endif Reporting::ReportMessage("Vulkan error in shader compilation: info: %s / code: %s", errorMessage.c_str(), code); } From b86648b352125d66ea128df4301f4a5ddd2ddcbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 12 Sep 2022 16:30:08 +0200 Subject: [PATCH 69/69] Address feedback --- GPU/Common/GPUStateUtils.cpp | 2 +- GPU/Vulkan/ShaderManagerVulkan.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index f801524b43..7690156d9d 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -1059,7 +1059,7 @@ static void ConvertBlendState(GenericBlendState &blendState, bool forceReplaceBl ReplaceBlendType replaceBlend = ReplaceBlendWithShader(gstate_c.framebufFormat); if (forceReplaceBlend) { // Enforce blend replacement if enabled. If not, shouldn't do anything of course. - replaceBlend = blendState.blendEnabled ? REPLACE_BLEND_READ_FRAMEBUFFER : REPLACE_BLEND_NO; + replaceBlend = gstate.isAlphaBlendEnabled() ? REPLACE_BLEND_READ_FRAMEBUFFER : REPLACE_BLEND_NO; } blendState.replaceBlend = replaceBlend; diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index f0028cbac6..132b4fba20 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -44,7 +44,8 @@ // Most drivers treat vkCreateShaderModule as pretty much a memcpy. What actually // takes time here, and makes this worthy of parallelization, is GLSLtoSPV. -static Promise *CompileShaderModuleAsync(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, const char *tag) { +// Takes ownership over tag. +static Promise *CompileShaderModuleAsync(VulkanContext *vulkan, VkShaderStageFlagBits stage, const char *code, std::string *tag) { auto compile = [=] { PROFILE_THIS_SCOPE("shadercomp"); @@ -77,7 +78,8 @@ static Promise *CompileShaderModuleAsync(VulkanContext *vulkan, OutputDebugStringA("OK"); #endif if (tag) { - vulkan->SetDebugName(shaderModule, VK_OBJECT_TYPE_SHADER_MODULE, tag); + vulkan->SetDebugName(shaderModule, VK_OBJECT_TYPE_SHADER_MODULE, tag->c_str()); + delete tag; } } @@ -96,7 +98,7 @@ static Promise *CompileShaderModuleAsync(VulkanContext *vulkan, VulkanFragmentShader::VulkanFragmentShader(VulkanContext *vulkan, FShaderID id, FragmentShaderFlags flags, const char *code) : vulkan_(vulkan), id_(id), flags_(flags) { source_ = code; - module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_FRAGMENT_BIT, source_.c_str(), FragmentShaderDesc(id).c_str()); + module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_FRAGMENT_BIT, source_.c_str(), new std::string(FragmentShaderDesc(id))); if (!module_) { failed_ = true; } else { @@ -126,7 +128,7 @@ std::string VulkanFragmentShader::GetShaderString(DebugShaderStringType type) co VulkanVertexShader::VulkanVertexShader(VulkanContext *vulkan, VShaderID id, const char *code, bool useHWTransform) : vulkan_(vulkan), useHWTransform_(useHWTransform), id_(id) { source_ = code; - module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_VERTEX_BIT, source_.c_str(), VertexShaderDesc(id).c_str()); + module_ = CompileShaderModuleAsync(vulkan, VK_SHADER_STAGE_VERTEX_BIT, source_.c_str(), new std::string(VertexShaderDesc(id).c_str())); if (!module_) { failed_ = true; } else {