From 2ba4eaf3dd8ac86ba44affea6902fd0fd7dbf89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 17 Sep 2024 15:13:13 +0200 Subject: [PATCH 1/2] First part of the const changes etc --- Common/Arm64Emitter.cpp | 2 +- Common/ArmEmitter.h | 2 +- Common/Buffer.h | 2 +- Common/Crypto/md5.cpp | 2 +- Common/Crypto/sha1.cpp | 2 +- Common/File/PathBrowser.cpp | 4 ---- Common/File/PathBrowser.h | 4 +++- Common/GPU/OpenGL/GLMemory.h | 2 -- Common/GPU/OpenGL/GLRenderManager.h | 8 -------- Common/GPU/OpenGL/thin3d_gl.cpp | 4 ++-- GPU/GLES/DrawEngineGLES.cpp | 8 ++++---- 11 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Common/Arm64Emitter.cpp b/Common/Arm64Emitter.cpp index 462ddc7346..56ebb11baf 100644 --- a/Common/Arm64Emitter.cpp +++ b/Common/Arm64Emitter.cpp @@ -1934,7 +1934,7 @@ inline int64_t abs64(int64_t x) { return x >= 0 ? x : -x; } -int Count(bool part[4]) { +static int Count(const bool part[4]) { int cnt = 0; for (int i = 0; i < 4; i++) { if (part[i]) diff --git a/Common/ArmEmitter.h b/Common/ArmEmitter.h index f1cf4dd224..7570e44479 100644 --- a/Common/ArmEmitter.h +++ b/Common/ArmEmitter.h @@ -456,7 +456,7 @@ public: void AddNewLit(u32 val); bool TrySetValue_TwoOp(ARMReg reg, u32 val); - CCFlags GetCC() { return CCFlags(condition >> 28); } + CCFlags GetCC() const { return CCFlags(condition >> 28); } void SetCC(CCFlags cond = CC_AL); // Special purpose instructions diff --git a/Common/Buffer.h b/Common/Buffer.h index 4d63a8e5ad..aec1727383 100644 --- a/Common/Buffer.h +++ b/Common/Buffer.h @@ -74,7 +74,7 @@ public: size_t size() const { return data_.size(); } bool empty() const { return size() == 0; } void clear() { data_.resize(0); } - bool IsVoid() { return void_; } + bool IsVoid() const { return void_; } protected: // TODO: Find a better internal representation, like a cord. diff --git a/Common/Crypto/md5.cpp b/Common/Crypto/md5.cpp index cce49809dc..595db5e5c6 100644 --- a/Common/Crypto/md5.cpp +++ b/Common/Crypto/md5.cpp @@ -73,7 +73,7 @@ void ppsspp_md5_starts( md5_context *ctx ) ctx->state[3] = 0x10325476; } -static void ppsspp_md5_process( md5_context *ctx, unsigned char data[64] ) +static void ppsspp_md5_process( md5_context *ctx, const unsigned char data[64] ) { unsigned long X[16], A, B, C, D; diff --git a/Common/Crypto/sha1.cpp b/Common/Crypto/sha1.cpp index 05deccc97f..e7011aebd4 100644 --- a/Common/Crypto/sha1.cpp +++ b/Common/Crypto/sha1.cpp @@ -74,7 +74,7 @@ void sha1_starts( sha1_context *ctx ) ctx->state[4] = 0xC3D2E1F0; } -static void sha1_process( sha1_context *ctx, unsigned char data[64] ) +static void sha1_process( sha1_context *ctx, const unsigned char data[64] ) { unsigned long temp, W[16], A, B, C, D, E; diff --git a/Common/File/PathBrowser.cpp b/Common/File/PathBrowser.cpp index ea5bb92e88..202b3cd25d 100644 --- a/Common/File/PathBrowser.cpp +++ b/Common/File/PathBrowser.cpp @@ -204,10 +204,6 @@ void PathBrowser::ResetPending() { pendingPath_.clear(); } -bool PathBrowser::IsListingReady() { - return ready_; -} - std::string PathBrowser::GetFriendlyPath() const { // Show relative to memstick root if there. if (path_.StartsWith(aliasMatch_)) { diff --git a/Common/File/PathBrowser.h b/Common/File/PathBrowser.h index 38733c6cae..ca98c6b4a8 100644 --- a/Common/File/PathBrowser.h +++ b/Common/File/PathBrowser.h @@ -23,7 +23,9 @@ public: void Refresh() { HandlePath(); } - bool IsListingReady(); + bool IsListingReady() const { + return ready_; + } bool GetListing(std::vector &fileInfo, const char *filter = nullptr, bool *cancel = nullptr); bool CanNavigateUp(); diff --git a/Common/GPU/OpenGL/GLMemory.h b/Common/GPU/OpenGL/GLMemory.h index c6892f6017..fb1b27508f 100644 --- a/Common/GPU/OpenGL/GLMemory.h +++ b/Common/GPU/OpenGL/GLMemory.h @@ -86,7 +86,6 @@ public: // Utility for users of this class, not used internally. enum { INVALID_OFFSET = 0xFFFFFFFF }; -private: // Needs context in case of defragment. void Begin() { buf_ = 0; @@ -105,7 +104,6 @@ private: Unmap(); } -public: void Map(); void Unmap(); diff --git a/Common/GPU/OpenGL/GLRenderManager.h b/Common/GPU/OpenGL/GLRenderManager.h index f6e0132032..0627a854cb 100644 --- a/Common/GPU/OpenGL/GLRenderManager.h +++ b/Common/GPU/OpenGL/GLRenderManager.h @@ -376,14 +376,6 @@ public: deleter_.pushBuffers.push_back(pushbuffer); } - void BeginPushBuffer(GLPushBuffer *pushbuffer) { - pushbuffer->Begin(); - } - - void EndPushBuffer(GLPushBuffer *pushbuffer) { - pushbuffer->End(); - } - bool IsInRenderPass() const { return curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER; } diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index 6a0237a012..9eb9d402fd 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -799,12 +799,12 @@ OpenGLContext::~OpenGLContext() { void OpenGLContext::BeginFrame(DebugFlags debugFlags) { renderManager_.BeginFrame(debugFlags & DebugFlags::PROFILE_TIMESTAMPS); FrameData &frameData = frameData_[renderManager_.GetCurFrame()]; - renderManager_.BeginPushBuffer(frameData.push); + frameData.push->Begin(); } void OpenGLContext::EndFrame() { FrameData &frameData = frameData_[renderManager_.GetCurFrame()]; - renderManager_.EndPushBuffer(frameData.push); // upload the data! + frameData.push->End(); // upload the data! renderManager_.Finish(); Invalidate(InvalidationFlags::CACHED_RENDER_STATE); } diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index e2161572d3..8fc2f75d77 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -150,16 +150,16 @@ void DrawEngineGLES::ClearInputLayoutMap() { void DrawEngineGLES::BeginFrame() { FrameData &frameData = frameData_[render_->GetCurFrame()]; - render_->BeginPushBuffer(frameData.pushIndex); - render_->BeginPushBuffer(frameData.pushVertex); + frameData.pushIndex->Begin(); + frameData.pushVertex->Begin(); lastRenderStepId_ = -1; } void DrawEngineGLES::EndFrame() { FrameData &frameData = frameData_[render_->GetCurFrame()]; - render_->EndPushBuffer(frameData.pushIndex); - render_->EndPushBuffer(frameData.pushVertex); + frameData.pushIndex->End(); + frameData.pushVertex->End(); tessDataTransferGLES->EndFrame(); } From eccd7f376763bf61f87fb5692b2c2587f7a13799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 17 Sep 2024 15:22:37 +0200 Subject: [PATCH 2/2] More const/static-ification --- Common/GPU/Vulkan/VulkanQueueRunner.h | 6 +++--- Common/GPU/thin3d.h | 6 +++--- Common/Input/InputState.h | 2 +- Common/MipsEmitter.cpp | 2 +- Common/MipsEmitter.h | 2 +- Common/Net/HTTPRequest.h | 2 +- Common/Render/Text/draw_text.cpp | 2 +- Common/Render/Text/draw_text.h | 2 +- Common/Render/TextureAtlas.h | 2 +- Common/VR/VRMath.cpp | 4 ++-- Common/VR/VRMath.h | 2 +- Core/Dialog/PSPDialog.cpp | 3 +-- Core/Dialog/PSPDialog.h | 2 +- Core/Dialog/PSPOskDialog.h | 4 ++-- 14 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.h b/Common/GPU/Vulkan/VulkanQueueRunner.h index da40ad300b..bef9ec7ec3 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.h +++ b/Common/GPU/Vulkan/VulkanQueueRunner.h @@ -286,9 +286,9 @@ private: void ResizeReadbackBuffer(CachedReadback *readback, VkDeviceSize requiredSize); - void ApplyMGSHack(std::vector &steps); - void ApplySonicHack(std::vector &steps); - void ApplyRenderPassMerge(std::vector &steps); + static void ApplyMGSHack(std::vector &steps); + static void ApplySonicHack(std::vector &steps); + static void ApplyRenderPassMerge(std::vector &steps); static void SetupTransferDstWriteAfterWrite(VKRImage &img, VkImageAspectFlags aspect, VulkanBarrierBatch *recordBarrier); diff --git a/Common/GPU/thin3d.h b/Common/GPU/thin3d.h index b1a9f94487..0c7898cbd0 100644 --- a/Common/GPU/thin3d.h +++ b/Common/GPU/thin3d.h @@ -450,9 +450,9 @@ public: class Framebuffer : public RefCountedObject { public: Framebuffer() : RefCountedObject("Framebuffer") {} - int Width() { return width_; } - int Height() { return height_; } - int Layers() { return layers_; } + int Width() const { return width_; } + int Height() const { return height_; } + int Layers() const { return layers_; } int MultiSampleLevel() { return multiSampleLevel_; } virtual void UpdateTag(const char *tag) {} diff --git a/Common/Input/InputState.h b/Common/Input/InputState.h index 2e74836de9..b4e0d8e074 100644 --- a/Common/Input/InputState.h +++ b/Common/Input/InputState.h @@ -66,7 +66,7 @@ inline int TranslateKeyCodeToAxis(int keyCode, int *direction) { class InputMapping { private: - inline int TranslateKeyCodeFromAxis(int axisId, int direction) { + static inline int TranslateKeyCodeFromAxis(int axisId, int direction) { return AXIS_BIND_NKCODE_START + axisId * 2 + (direction < 0 ? 1 : 0); } public: diff --git a/Common/MipsEmitter.cpp b/Common/MipsEmitter.cpp index 54c22bbebf..5d34e2ac8f 100644 --- a/Common/MipsEmitter.cpp +++ b/Common/MipsEmitter.cpp @@ -253,7 +253,7 @@ void MIPSEmitter::QuickCallFunction(MIPSReg scratchreg, const void *func) { } } -FixupBranch MIPSEmitter::MakeFixupBranch(FixupBranchType type) { +FixupBranch MIPSEmitter::MakeFixupBranch(FixupBranchType type) const { FixupBranch b; b.ptr = code_; b.type = type; diff --git a/Common/MipsEmitter.h b/Common/MipsEmitter.h index 77ffd5f41e..b178918707 100644 --- a/Common/MipsEmitter.h +++ b/Common/MipsEmitter.h @@ -258,7 +258,7 @@ protected: static void SetJumpTarget(const FixupBranch &branch, const void *dst); static bool BInRange(const void *src, const void *dst); static bool JInRange(const void *src, const void *dst); - FixupBranch MakeFixupBranch(FixupBranchType type); + FixupBranch MakeFixupBranch(FixupBranchType type) const; void ApplyDelaySlot(std::function delaySlot); private: diff --git a/Common/Net/HTTPRequest.h b/Common/Net/HTTPRequest.h index b6bfda2701..77b718a966 100644 --- a/Common/Net/HTTPRequest.h +++ b/Common/Net/HTTPRequest.h @@ -114,7 +114,7 @@ public: } private: - bool IsHttpsUrl(const std::string &url); + static bool IsHttpsUrl(const std::string &url); std::vector> downloads_; // These get copied to downloads_ in Update(). It's so that callbacks can add new downloads diff --git a/Common/Render/Text/draw_text.cpp b/Common/Render/Text/draw_text.cpp index 020d777d47..e70d4d6a81 100644 --- a/Common/Render/Text/draw_text.cpp +++ b/Common/Render/Text/draw_text.cpp @@ -37,7 +37,7 @@ void TextDrawer::SetFontScale(float xscale, float yscale) { fontScaleY_ = yscale; } -float TextDrawer::CalculateDPIScale() { +float TextDrawer::CalculateDPIScale() const { if (ignoreGlobalDpi_) return dpiScale_; float scale = g_display.dpi_scale_y; diff --git a/Common/Render/Text/draw_text.h b/Common/Render/Text/draw_text.h index 9f8f7c08e6..3392c92e53 100644 --- a/Common/Render/Text/draw_text.h +++ b/Common/Render/Text/draw_text.h @@ -58,7 +58,7 @@ public: // Use for housekeeping like throwing out old strings. void OncePerFrame(); - float CalculateDPIScale(); + float CalculateDPIScale() const; void SetForcedDPIScale(float dpi) { dpiScale_ = dpi; ignoreGlobalDpi_ = true; diff --git a/Common/Render/TextureAtlas.h b/Common/Render/TextureAtlas.h index 4c73e0a120..fe2a851e36 100644 --- a/Common/Render/TextureAtlas.h +++ b/Common/Render/TextureAtlas.h @@ -129,7 +129,7 @@ struct AtlasHeader { struct Atlas { ~Atlas(); bool Load(const uint8_t *data, size_t data_size); - bool IsMetadataLoaded() { + bool IsMetadataLoaded() const { return images != nullptr; } diff --git a/Common/VR/VRMath.cpp b/Common/VR/VRMath.cpp index d65f13a1a7..5fd187b53b 100644 --- a/Common/VR/VRMath.cpp +++ b/Common/VR/VRMath.cpp @@ -13,10 +13,10 @@ float ToRadians(float deg) { return (float)(deg * M_PI / 180.0f); } -bool IsMatrixIdentity(float* matrix) { +bool IsMatrixIdentity(const float *matrix4x4) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - float value = matrix[i * 4 + j]; + float value = matrix4x4[i * 4 + j]; // Other number than zero on non-diagonale if ((i != j) && (fabs(value) > EPSILON)) return false; diff --git a/Common/VR/VRMath.h b/Common/VR/VRMath.h index 5321ca8cc6..9ce83997a0 100644 --- a/Common/VR/VRMath.h +++ b/Common/VR/VRMath.h @@ -9,7 +9,7 @@ float ToDegrees(float rad); float ToRadians(float deg); -bool IsMatrixIdentity(float* matrix); +bool IsMatrixIdentity(const float *matrix4x4); // XrPosef XrPosef XrPosef_Identity(); diff --git a/Core/Dialog/PSPDialog.cpp b/Core/Dialog/PSPDialog.cpp index 8697e71b13..28e656d966 100644 --- a/Core/Dialog/PSPDialog.cpp +++ b/Core/Dialog/PSPDialog.cpp @@ -205,8 +205,7 @@ void PSPDialog::FinishFadeOut() { ChangeStatus(SCE_UTILITY_STATUS_FINISHED, 0); } -u32 PSPDialog::CalcFadedColor(u32 inColor) -{ +u32 PSPDialog::CalcFadedColor(u32 inColor) const { u32 alpha = inColor >> 24; alpha = alpha * fadeValue / 255; return (inColor & 0x00FFFFFF) | (alpha << 24); diff --git a/Core/Dialog/PSPDialog.h b/Core/Dialog/PSPDialog.h index 8e254f401f..86107b5385 100644 --- a/Core/Dialog/PSPDialog.h +++ b/Core/Dialog/PSPDialog.h @@ -114,7 +114,7 @@ protected: void StartFade(bool fadeIn_); void UpdateFade(int animSpeed); virtual void FinishFadeOut(); - u32 CalcFadedColor(u32 inColor); + u32 CalcFadedColor(u32 inColor) const; DialogStatus pendingStatus = SCE_UTILITY_STATUS_NONE; u64 pendingStatusTicks = 0; diff --git a/Core/Dialog/PSPOskDialog.h b/Core/Dialog/PSPOskDialog.h index 2f491e4d4b..0639c6226a 100644 --- a/Core/Dialog/PSPOskDialog.h +++ b/Core/Dialog/PSPOskDialog.h @@ -227,8 +227,8 @@ protected: } private: - void ConvertUCS2ToUTF8(std::string& _string, const PSPPointer& em_address); - void ConvertUCS2ToUTF8(std::string& _string, const char16_t *input); + static void ConvertUCS2ToUTF8(std::string& _string, const PSPPointer& em_address); + static void ConvertUCS2ToUTF8(std::string& _string, const char16_t *input); void RenderKeyboard(); int NativeKeyboard();