From 0d542c6b5ad0c20c7cb1ec976a433aafd26dcfe6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 31 Jul 2022 07:48:46 -0700 Subject: [PATCH 01/11] Debugger: Fix crash on bad request. --- Common/Net/HTTPHeaders.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/Net/HTTPHeaders.cpp b/Common/Net/HTTPHeaders.cpp index 16dc16c8e7..18450030eb 100644 --- a/Common/Net/HTTPHeaders.cpp +++ b/Common/Net/HTTPHeaders.cpp @@ -154,7 +154,7 @@ void RequestHeader::ParseHeaders(net::InputSink *sink) { } VERBOSE_LOG(IO, "finished parsing request."); - ok = line_count > 1; + ok = line_count > 1 && resource != nullptr; } } // namespace http From c74d69bc2d4bce82f9abf6d06093150748ac1656 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 11 Aug 2022 20:25:01 -0700 Subject: [PATCH 02/11] Debugger: Correct GE frame dump VRAM dirty flag. Was just wrong before, causing incorrect ignoring in some cases. --- GPU/Debugger/Record.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/GPU/Debugger/Record.cpp b/GPU/Debugger/Record.cpp index 1d39f6a214..100e0dd3c4 100644 --- a/GPU/Debugger/Record.cpp +++ b/GPU/Debugger/Record.cpp @@ -108,7 +108,7 @@ static void DirtyAllVRAM(DirtyVRAMFlag flag) { static void DirtyVRAM(u32 start, u32 sz, DirtyVRAMFlag flag) { u32 count = (sz + DIRTY_VRAM_ROUND) >> DIRTY_VRAM_SHIFT; - u32 first = (start >> 10) & DIRTY_VRAM_MASK; + u32 first = (start >> DIRTY_VRAM_SHIFT) & DIRTY_VRAM_MASK; if (first + count > DIRTY_VRAM_SIZE) { DirtyAllVRAM(flag); return; @@ -329,10 +329,15 @@ static void EmitTextureData(int level, u32 texaddr) { bool isDirtyVRAM = false; bool isDrawnVRAM = false; + uint32_t start = (texaddr >> DIRTY_VRAM_SHIFT) & DIRTY_VRAM_MASK; for (uint32_t i = 0; i < (sizeInRAM + DIRTY_VRAM_ROUND) >> DIRTY_VRAM_SHIFT; ++i) { - DirtyVRAMFlag flag = dirtyVRAM[(texaddr >> DIRTY_VRAM_SHIFT) + i]; + DirtyVRAMFlag flag = dirtyVRAM[start + i]; isDirtyVRAM = isDirtyVRAM || flag != DirtyVRAMFlag::CLEAN; isDrawnVRAM = isDrawnVRAM || flag == DirtyVRAMFlag::DRAWN; + + // Mark the VRAM clean now that it's been copied to VRAM. + if (flag == DirtyVRAMFlag::DIRTY) + dirtyVRAM[start + i] = DirtyVRAMFlag::CLEAN; } // The isTarget flag is mostly used for replay of dumps on a PSP. From 4467b7830f32eb8150a4ec12dee1d09e0320e545 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 11 Aug 2022 20:28:56 -0700 Subject: [PATCH 03/11] Debugger: Bump GE dump version to ignore bad flag. --- GPU/Debugger/Playback.cpp | 12 ++++++++---- GPU/Debugger/RecordFormat.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/GPU/Debugger/Playback.cpp b/GPU/Debugger/Playback.cpp index a05bac1624..8fa93e7d7c 100644 --- a/GPU/Debugger/Playback.cpp +++ b/GPU/Debugger/Playback.cpp @@ -282,8 +282,8 @@ int BufMapping::slabGeneration_ = 0; class DumpExecute { public: - DumpExecute(const std::vector &pushbuf, const std::vector &commands) - : pushbuf_(pushbuf), commands_(commands), mapping_(pushbuf) { + DumpExecute(const std::vector &pushbuf, const std::vector &commands, uint32_t version) + : pushbuf_(pushbuf), commands_(commands), mapping_(pushbuf), version_(version) { } ~DumpExecute(); @@ -320,6 +320,7 @@ private: const std::vector &pushbuf_; const std::vector &commands_; BufMapping mapping_; + uint32_t version_ = 0; }; void DumpExecute::SyncStall() { @@ -564,7 +565,7 @@ void DumpExecute::Framebuf(int level, u32 ptr, u32 sz) { u32 headerSize = (u32)sizeof(FramebufData); u32 pspSize = sz - headerSize; const bool isTarget = (framebuf->flags & 1) != 0; - const bool unchangedVRAM = (framebuf->flags & 2) != 0; + const bool unchangedVRAM = version_ >= 6 && (framebuf->flags & 2) != 0; // TODO: Could use drawnVRAM flag, but it can be wrong. // Could potentially always skip if !isTarget, but playing it safe for offset texture behavior. if (Memory::IsValidRange(framebuf->addr, pspSize) && !unchangedVRAM && (!isTarget || !g_Config.bSoftwareRendering)) { @@ -708,11 +709,14 @@ bool RunMountedReplay(const std::string &filename) { std::lock_guard guard(executeLock); Core_ListenStopRequest(&ReplayStop); + + uint32_t version = 0; if (lastExecFilename != filename) { PROFILE_THIS_SCOPE("ReplayLoad"); u32 fp = pspFileSystem.OpenFile(filename, FILEACCESS_READ); Header header; pspFileSystem.ReadFile(fp, (u8 *)&header, sizeof(header)); + version = header.version; if (memcmp(header.magic, HEADER_MAGIC, sizeof(header.magic)) != 0 || header.version > VERSION || header.version < MIN_VERSION) { ERROR_LOG(SYSTEM, "Invalid GE dump or unsupported version"); @@ -751,7 +755,7 @@ bool RunMountedReplay(const std::string &filename) { lastExecFilename = filename; } - DumpExecute executor(lastExecPushbuf, lastExecCommands); + DumpExecute executor(lastExecPushbuf, lastExecCommands, version); return executor.Run(); } diff --git a/GPU/Debugger/RecordFormat.h b/GPU/Debugger/RecordFormat.h index 22395e1594..8079136d0c 100644 --- a/GPU/Debugger/RecordFormat.h +++ b/GPU/Debugger/RecordFormat.h @@ -34,7 +34,8 @@ static const char *HEADER_MAGIC = "PPSSPPGE"; // Version 3: Adds FRAMEBUF0-FRAMEBUF9 // Version 4: Expanded header with game ID // Version 5: Uses zstd -static const int VERSION = 5; +// Version 6: Corrects dirty VRAM flag +static const int VERSION = 6; static const int MIN_VERSION = 2; enum class CommandType : u8 { From ade8b88766d64369b26deda7c5ba524425d1ab0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 12 Aug 2022 21:31:55 +0200 Subject: [PATCH 04/11] Try to fix shader compilation error on Adreno reported by Lubos --- GPU/Common/FragmentShaderGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index e13007a365..ad3f22af8c 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -607,7 +607,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu } else { WRITE(p, " vec2 uv = %s.xy;\n vec2 uv_round;\n", texcoord); } - WRITE(p, " vec2 tsize = textureSize(tex, 0).xy;\n"); + WRITE(p, " vec2 tsize = vec2(textureSize(tex, 0).xy);\n"); WRITE(p, " vec2 fraction;\n"); WRITE(p, " bool bilinear = (u_depal_mask_shift_off_fmt >> 31) != 0U;\n"); WRITE(p, " if (bilinear) {\n"); From 9bda04a0d268057478fedd25a970662d401905b4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 12 Aug 2022 22:30:15 -0700 Subject: [PATCH 05/11] Core: Correct shutdown on late init failure. Otherwise we leak and can't start again. This happened when shutdown completed quickly after thread start. --- Core/System.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/System.cpp b/Core/System.cpp index 867000ede0..dc0764f86e 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -447,7 +447,9 @@ bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string) { bool success = !g_CoreParameter.fileToStart.empty(); if (!success) { Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE); - pspIsIniting = false; + // In this case, we must call shutdown since the caller won't know to. + // It must've partially started since CPU_Init returned true. + PSP_Shutdown(); } return success; } From dedb63532bd708298a9bada148e04eb9091ae018 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 12 Aug 2022 22:41:30 -0700 Subject: [PATCH 06/11] Headless: Correct bad pointer without gfx context. --- headless/SDLHeadlessHost.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/headless/SDLHeadlessHost.cpp b/headless/SDLHeadlessHost.cpp index 4e7b76d135..af6fc4a994 100644 --- a/headless/SDLHeadlessHost.cpp +++ b/headless/SDLHeadlessHost.cpp @@ -80,8 +80,10 @@ public: } void StopThread() override { - renderManager_->WaitUntilQueueIdle(); - renderManager_->StopThread(); + if (renderManager_) { + renderManager_->WaitUntilQueueIdle(); + renderManager_->StopThread(); + } } void Shutdown() override {} @@ -90,7 +92,7 @@ public: void SwapBuffers() override {} private: - Draw::DrawContext *draw_; + Draw::DrawContext *draw_ = nullptr; GLRenderManager *renderManager_ = nullptr; SDL_Window *screen_; SDL_GLContext glContext_; @@ -201,7 +203,7 @@ bool SDLHeadlessHost::InitGraphics(std::string *error_message, GraphicsContext * void SDLHeadlessHost::ShutdownGraphics() { gfx_->StopThread(); - while (threadState_ != RenderThreadState::STOPPED) + while (threadState_ != RenderThreadState::STOPPED && threadState_ != RenderThreadState::START_FAILED) sleep_ms(1); gfx_->Shutdown(); From df2634d4e74027afcf521e063e2be7a4c69d6a41 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 12 Aug 2022 23:10:38 -0700 Subject: [PATCH 07/11] x86jit: Avoid an instruction form Valgrind hates. --- Common/x64Emitter.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Common/x64Emitter.cpp b/Common/x64Emitter.cpp index e6fa36e1bb..1d98544e68 100644 --- a/Common/x64Emitter.cpp +++ b/Common/x64Emitter.cpp @@ -1608,8 +1608,20 @@ void XEmitter::MOVDQU(OpArg arg, X64Reg regOp) {WriteSSEOp(0xF3, sseMOVDQtoRM, void XEmitter::MOVSS(X64Reg regOp, OpArg arg) {WriteSSEOp(0xF3, sseMOVUPfromRM, regOp, arg);} void XEmitter::MOVSD(X64Reg regOp, OpArg arg) {WriteSSEOp(0xF2, sseMOVUPfromRM, regOp, arg);} -void XEmitter::MOVSS(OpArg arg, X64Reg regOp) {WriteSSEOp(0xF3, sseMOVUPtoRM, regOp, arg);} -void XEmitter::MOVSD(OpArg arg, X64Reg regOp) {WriteSSEOp(0xF2, sseMOVUPtoRM, regOp, arg);} +void XEmitter::MOVSS(OpArg arg, X64Reg regOp) { + // Make Valgrind happy. + if (arg.IsSimpleReg()) + MOVSS(arg.GetSimpleReg(), R(regOp)); + else + WriteSSEOp(0xF3, sseMOVUPtoRM, regOp, arg); +} +void XEmitter::MOVSD(OpArg arg, X64Reg regOp) { + // Make Valgrind happy. + if (arg.IsSimpleReg()) + MOVSD(arg.GetSimpleReg(), R(regOp)); + else + WriteSSEOp(0xF2, sseMOVUPtoRM, regOp, arg); +} void XEmitter::MOVLPS(X64Reg regOp, OpArg arg) { WriteSSEOp(0x00, sseMOVLPfromRM, regOp, arg); } void XEmitter::MOVLPD(X64Reg regOp, OpArg arg) { WriteSSEOp(0x66, sseMOVLPfromRM, regOp, arg); } From 49b98de97ad3fd1eabb83a26745c358159ba626d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 12 Aug 2022 23:48:25 -0700 Subject: [PATCH 08/11] 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 482dbb66eacf10eb52d8986cba8d685e452f543b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 12 Aug 2022 23:58:57 -0700 Subject: [PATCH 09/11] softgpu: Ensure TCs are initialized. Even if they're not read, we want consistent behavior. --- GPU/Software/TransformUnit.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 3719277141..3c22dc9f5b 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -281,6 +281,8 @@ VertexData TransformUnit::ReadVertex(VertexReader &vreader, const TransformState if (state.readUV) { vreader.ReadUV(vertex.texturecoords.AsArray()); + } else { + vertex.texturecoords.SetZero(); } Vec3 normal; From 8b3526b8c238506aedb93710af737d86a4a04ae9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 00:16:08 -0700 Subject: [PATCH 10/11] 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 f44ba65fe1..a75e0e16c4 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -401,7 +401,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 3554e2ee72500465318a72e5e7739f86c98560c3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 00:16:26 -0700 Subject: [PATCH 11/11] Build: Correct ccache keys. It seems to use id*, so clang was matching other builds sometimes. --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 767d88a18b..cc776d30a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,12 +120,12 @@ jobs: cc: clang cxx: clang++ args: ./b.sh --headless --unittest - id: clang + id: clang-normal - os: ubuntu-latest cc: gcc cxx: g++ args: ./b.sh --headless --unittest - id: gcc + id: gcc-normal - os: ubuntu-latest extra: android