From ca4a0a848a1fc2896236a49f3e8f046eef73cff1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 12:02:28 -0700 Subject: [PATCH 1/5] Font: Fix bad memory read on invalid font data. --- Core/Font/PGF.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 20315f4c01..a01b47225c 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -679,6 +679,10 @@ void PGF::SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, in } static const u8 fontPixelSizeInBytes[] = { 0, 0, 1, 3, 4 }; // 0 means 2 pixels per byte + if (pixelformat < 0 || pixelformat > PSP_FONT_PIXELFORMAT_32) { + ERROR_LOG_REPORT_ONCE(pfgbadformat, SCEFONT, "Invalid image format in image: %d", (int)pixelformat); + return; + } int pixelBytes = fontPixelSizeInBytes[pixelformat]; int bufMaxWidth = (pixelBytes == 0 ? bpl * 2 : bpl / pixelBytes); if (x >= bufMaxWidth) { From cf030c3bce20519bec0814e1967fa6e74798c04f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 12:23:20 -0700 Subject: [PATCH 2/5] Global: Cleanup some unreferenced warnings. --- Common/GPU/Vulkan/VulkanMemory.h | 4 ++++ Common/Render/TextureAtlas.cpp | 6 ++++++ GPU/Common/TextureDecoder.cpp | 16 +--------------- GPU/Common/TextureScalerCommon.cpp | 2 +- GPU/GLES/TextureCacheGLES.h | 1 - GPU/Vulkan/VulkanUtil.h | 2 +- UI/ComboKeyMappingScreen.h | 1 - 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanMemory.h b/Common/GPU/Vulkan/VulkanMemory.h index 079996b8a6..82ef924390 100644 --- a/Common/GPU/Vulkan/VulkanMemory.h +++ b/Common/GPU/Vulkan/VulkanMemory.h @@ -101,6 +101,10 @@ public: return offset_; } + const char *Name() const { + return name_; + } + // "Zero-copy" variant - you can write the data directly as you compute it. // Recommended. void *Push(size_t size, uint32_t *bindOffset, VkBuffer *vkbuf) { diff --git a/Common/Render/TextureAtlas.cpp b/Common/Render/TextureAtlas.cpp index c23cb33646..f41cbc1402 100644 --- a/Common/Render/TextureAtlas.cpp +++ b/Common/Render/TextureAtlas.cpp @@ -2,6 +2,7 @@ #include #include +#include "Common/Log.h" #include "Common/Render/TextureAtlas.h" class ByteReader { @@ -10,6 +11,7 @@ public: template T Read() { + _dbg_assert_(offset_ + sizeof(T) <= size_); T x; memcpy(&x, data_ + offset_, sizeof(T)); offset_ += sizeof(T); @@ -18,6 +20,7 @@ public: template void ReadInto(T *t) { + _dbg_assert_(offset_ + sizeof(T) <= size_); memcpy(t, data_ + offset_, sizeof(T)); offset_ += sizeof(T); } @@ -26,13 +29,16 @@ public: T *ReadMultipleAlloc(size_t count, bool compressed) { T *t = new T[count]; if (!compressed) { + _dbg_assert_(offset_ + sizeof(T) * count <= size_); memcpy(t, data_ + offset_, sizeof(T) * count); offset_ += sizeof(T) * count; } else { + _dbg_assert_(offset_ + sizeof(uint32_t) <= size_); uint32_t compressed_size = 0; memcpy(&compressed_size, data_ + offset_, sizeof(uint32_t)); offset_ += sizeof(uint32_t); + _dbg_assert_(offset_ + compressed_size <= size_); ZSTD_decompress(t, sizeof(T) * count, data_ + offset_, compressed_size); offset_ += compressed_size; } diff --git a/GPU/Common/TextureDecoder.cpp b/GPU/Common/TextureDecoder.cpp index c18c96e0fa..d7788077a6 100644 --- a/GPU/Common/TextureDecoder.cpp +++ b/GPU/Common/TextureDecoder.cpp @@ -217,7 +217,7 @@ u32 GetTextureBufw(int level, u32 texaddr, GETextureFormat format) { return bufw; } -// Is this compatible with QuickTexHashNEON/SSE? +// Matches QuickTexHashNEON/SSE, see #7029. static u32 QuickTexHashNonSSE(const void *checkp, u32 size) { u32 check = 0; @@ -269,20 +269,6 @@ static u32 QuickTexHashNonSSE(const void *checkp, u32 size) { return check; } -static u32 QuickTexHashBasic(const void *checkp, u32 size) { - u32 check = 0; - const u32 size_u32 = size / 4; - const u32 *p = (const u32 *)checkp; - for (u32 i = 0; i < size_u32; i += 4) { - check += p[i + 0]; - check ^= p[i + 1]; - check += p[i + 2]; - check ^= p[i + 3]; - } - - return check; -} - u32 StableQuickTexHash(const void *checkp, u32 size) { #if defined(_M_SSE) return QuickTexHashSSE2(checkp, size); diff --git a/GPU/Common/TextureScalerCommon.cpp b/GPU/Common/TextureScalerCommon.cpp index f7dbbeae71..3c6e946c2f 100644 --- a/GPU/Common/TextureScalerCommon.cpp +++ b/GPU/Common/TextureScalerCommon.cpp @@ -209,7 +209,7 @@ static void load_sample(ptrdiff_t w, ptrdiff_t h, ptrdiff_t s, const u8 *pixels, // Check if the sample is inside. NOTE: for b>=0 // the expression (UNSIGNED)a<(UNSIGNED)b is // equivalent to a>=0&&a= (size_t)w||(size_t)y >= (size_t)h) { switch(wrap_mode) { diff --git a/GPU/GLES/TextureCacheGLES.h b/GPU/GLES/TextureCacheGLES.h index 90108d2639..ac5313c3cb 100644 --- a/GPU/GLES/TextureCacheGLES.h +++ b/GPU/GLES/TextureCacheGLES.h @@ -79,7 +79,6 @@ private: GLRTexture *lastBoundTexture = nullptr; FramebufferManagerGLES *framebufferManagerGL_; - ShaderManagerGLES *shaderManagerGL_; DrawEngineGLES *drawEngine_; enum { INVALID_TEX = -1 }; diff --git a/GPU/Vulkan/VulkanUtil.h b/GPU/Vulkan/VulkanUtil.h index 4a82b9e851..2753fd79eb 100644 --- a/GPU/Vulkan/VulkanUtil.h +++ b/GPU/Vulkan/VulkanUtil.h @@ -72,7 +72,7 @@ private: struct FrameData { FrameData() : descPool("VulkanComputeShaderManager", true) { - descPool.Setup([this] { }); + descPool.Setup([] { }); } VulkanDescSetPool descPool; diff --git a/UI/ComboKeyMappingScreen.h b/UI/ComboKeyMappingScreen.h index cf82e703e8..6eb271211d 100644 --- a/UI/ComboKeyMappingScreen.h +++ b/UI/ComboKeyMappingScreen.h @@ -39,7 +39,6 @@ private: bool array[ARRAY_SIZE(CustomKey::comboKeyList)]; int id_; - UI::ChoiceStrip *comboselect; UI::ScrollView *rightScroll_; class ChoiceEventHandler{ public: From 09b7a626660a8a8a4c6b100518a21a17d0170e83 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 12:31:03 -0700 Subject: [PATCH 3/5] libpng: Correct func pointer type warning. --- ext/libpng17/arm/filter_neon_intrinsics.c | 21 ++++++++++++++------- ext/libpng17/arm/neon.h | 14 +++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ext/libpng17/arm/filter_neon_intrinsics.c b/ext/libpng17/arm/filter_neon_intrinsics.c index 2788dd3391..5d8b5fb083 100644 --- a/ext/libpng17/arm/filter_neon_intrinsics.c +++ b/ext/libpng17/arm/filter_neon_intrinsics.c @@ -46,7 +46,7 @@ void png_read_filter_row_up_neon(png_alloc_size_t rowbytes, unsigned int bpp, - png_bytep row, png_const_bytep prev_row) + png_bytep row, png_const_bytep prev_row, png_const_bytep prev_pixels) { png_bytep rp = row; png_bytep rp_stop = row + rowbytes; @@ -63,10 +63,11 @@ png_read_filter_row_up_neon(png_alloc_size_t rowbytes, unsigned int bpp, } PNG_UNUSED(bpp) + PNG_UNUSED(prev_pixels) } void -png_read_filter_row_sub3_neon(png_alloc_size_t rowbytes, unsigned int bpp, png_bytep row, png_const_bytep prev_row) +png_read_filter_row_sub3_neon(png_alloc_size_t rowbytes, unsigned int bpp, png_bytep row, png_const_bytep prev_row, png_const_bytep prev_pixels) { png_bytep rp = row; png_bytep rp_stop = row + rowbytes; @@ -108,11 +109,12 @@ png_read_filter_row_sub3_neon(png_alloc_size_t rowbytes, unsigned int bpp, png_b PNG_UNUSED(bpp) PNG_UNUSED(prev_row) + PNG_UNUSED(prev_pixels) } void png_read_filter_row_sub4_neon(png_alloc_size_t rowbytes, unsigned int bpp, - png_bytep row, png_const_bytep prev_row) + png_bytep row, png_const_bytep prev_row, png_const_bytep prev_pixels) { png_bytep rp = row; png_bytep rp_stop = row + rowbytes; @@ -136,11 +138,12 @@ png_read_filter_row_sub4_neon(png_alloc_size_t rowbytes, unsigned int bpp, PNG_UNUSED(bpp) PNG_UNUSED(prev_row) + PNG_UNUSED(prev_pixels) } void png_read_filter_row_avg3_neon(png_alloc_size_t rowbytes, unsigned int bpp, - png_bytep row, png_const_bytep prev_row) + png_bytep row, png_const_bytep prev_row, png_const_bytep prev_pixels) { png_bytep rp = row; png_const_bytep pp = prev_row; @@ -204,11 +207,12 @@ png_read_filter_row_avg3_neon(png_alloc_size_t rowbytes, unsigned int bpp, } PNG_UNUSED(bpp) + PNG_UNUSED(prev_pixels) } void png_read_filter_row_avg4_neon(png_alloc_size_t rowbytes, unsigned int bpp, - png_bytep row, png_const_bytep prev_row) + png_bytep row, png_const_bytep prev_row, png_const_bytep prev_pixels) { png_bytep rp = row; png_bytep rp_stop = row + rowbytes; @@ -244,6 +248,7 @@ png_read_filter_row_avg4_neon(png_alloc_size_t rowbytes, unsigned int bpp, } PNG_UNUSED(bpp) + PNG_UNUSED(prev_pixels) } static uint8x8_t @@ -275,7 +280,7 @@ paeth(uint8x8_t a, uint8x8_t b, uint8x8_t c) void png_read_filter_row_paeth3_neon(png_alloc_size_t rowbytes, unsigned int bpp, - png_bytep row, png_const_bytep prev_row) + png_bytep row, png_const_bytep prev_row, png_const_bytep prev_pixels) { png_bytep rp = row; png_const_bytep pp = prev_row; @@ -339,11 +344,12 @@ png_read_filter_row_paeth3_neon(png_alloc_size_t rowbytes, unsigned int bpp, } PNG_UNUSED(bpp) + PNG_UNUSED(prev_pixels) } void png_read_filter_row_paeth4_neon(png_alloc_size_t rowbytes, unsigned int bpp, - png_bytep row, png_const_bytep prev_row) + png_bytep row, png_const_bytep prev_row, png_const_bytep prev_pixels) { png_bytep rp = row; png_bytep rp_stop = row + rowbytes; @@ -382,6 +388,7 @@ png_read_filter_row_paeth4_neon(png_alloc_size_t rowbytes, unsigned int bpp, } PNG_UNUSED(bpp) + PNG_UNUSED(prev_pixels) } #endif /* PNG_ARM_NEON_OPT > 0 */ #endif /* PNG_ARM_NEON_IMPLEMENTATION == 1 (intrinsics) */ diff --git a/ext/libpng17/arm/neon.h b/ext/libpng17/arm/neon.h index 2485cd9bf1..0132b945af 100644 --- a/ext/libpng17/arm/neon.h +++ b/ext/libpng17/arm/neon.h @@ -102,23 +102,23 @@ #if PNG_ARM_NEON_OPT > 0 PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon, (png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row, - png_const_bytep prev_row),PNG_EMPTY); + png_const_bytep prev_row, png_const_bytep prev_pixels),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon, (png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row, - png_const_bytep prev_row),PNG_EMPTY); + png_const_bytep prev_row, png_const_bytep prev_pixels),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon, (png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row, - png_const_bytep prev_row),PNG_EMPTY); + png_const_bytep prev_row, png_const_bytep prev_pixels),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon, (png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row, - png_const_bytep prev_row),PNG_EMPTY); + png_const_bytep prev_row, png_const_bytep prev_pixels),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon, (png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row, - png_const_bytep prev_row),PNG_EMPTY); + png_const_bytep prev_row, png_const_bytep prev_pixels),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon, (png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row, - png_const_bytep prev_row),PNG_EMPTY); + png_const_bytep prev_row, png_const_bytep prev_pixels),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon, (png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row, - png_const_bytep prev_row),PNG_EMPTY); + png_const_bytep prev_row, png_const_bytep prev_pixels),PNG_EMPTY); #endif From a6804c96bdb123ebc878e1292bca7ca9f86a4af6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 12:37:06 -0700 Subject: [PATCH 4/5] GLES: Correct some variable shadowing. Potentially fixes an issue with 3D textures? --- Common/GPU/OpenGL/GLRenderManager.cpp | 2 +- Common/GPU/Vulkan/VulkanQueueRunner.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index 172511333f..afff7a7b40 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -34,7 +34,7 @@ GLRTexture::GLRTexture(const Draw::DeviceCaps &caps, int width, int height, int } w = width; h = height; - depth = depth; + d = depth; this->numMips = numMips; } diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.cpp b/Common/GPU/Vulkan/VulkanQueueRunner.cpp index 2373fd0311..7c9f3eb072 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.cpp +++ b/Common/GPU/Vulkan/VulkanQueueRunner.cpp @@ -1602,16 +1602,16 @@ void VulkanQueueRunner::SetupTransitionToTransferSrc(VKRImage &img, VkImageAspec if (img.format == VK_FORMAT_D16_UNORM_S8_UINT || img.format == VK_FORMAT_D24_UNORM_S8_UINT || img.format == VK_FORMAT_D32_SFLOAT_S8_UINT) { // Barrier must specify both for combined depth/stencil buffers. - aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + imageAspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; } else { - aspect = aspect; + imageAspect = aspect; } recordBarrier->TransitionImage( img.image, 0, 1, - aspect, + imageAspect, img.layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, srcAccessMask, From bdb410701482a840a380ed7951812a9ae8921497 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Aug 2022 12:41:51 -0700 Subject: [PATCH 5/5] Net: Cleanup initialization syntax. --- Core/HLE/sceNp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/HLE/sceNp.cpp b/Core/HLE/sceNp.cpp index ac0e29a8cf..50bb3f317b 100644 --- a/Core/HLE/sceNp.cpp +++ b/Core/HLE/sceNp.cpp @@ -102,7 +102,7 @@ int writeTicketU64Param(u8* buffer, const u16_be type, const u64_be data) { void notifyNpAuthHandlers(u32 id, u32 result, u32 argAddr) { std::lock_guard npAuthGuard(npAuthEvtMtx); - npAuthEvents.push_back({ id, result, argAddr }); + npAuthEvents.push_back({ { id, result, argAddr } }); } static int sceNpInit()