diff --git a/Common/Data/Encoding/Utf8.cpp b/Common/Data/Encoding/Utf8.cpp index 00e2b70578..8f839b8882 100644 --- a/Common/Data/Encoding/Utf8.cpp +++ b/Common/Data/Encoding/Utf8.cpp @@ -37,27 +37,21 @@ inline bool isutf(char c) { } static const uint32_t offsetsFromUTF8[6] = { - 0x00000000UL, 0x00003080UL, 0x000E2080UL, - 0x03C82080UL, 0xFA082080UL, 0x82082080UL + 0x00000000UL, 0x00003080UL, 0x000E2080UL, + 0x03C82080UL, 0xFA082080UL, 0x82082080UL }; static const uint8_t trailingBytesForUTF8[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5, }; -/* returns length of next utf-8 sequence */ -int u8_seqlen(const char *s) -{ - return trailingBytesForUTF8[(unsigned int)(unsigned char)s[0]] + 1; -} - /* conversions without error checking only works for valid UTF-8, i.e. no 5- or 6-byte sequences srcsz = source size in bytes, or -1 if 0-terminated @@ -68,7 +62,7 @@ int u8_seqlen(const char *s) for all the characters. if sz = srcsz+1 (i.e. 4*srcsz+4 bytes), there will always be enough space. */ -int u8_toucs(uint32_t *dest, int sz, const char *src, int srcsz) +int u8_toucs(uint32_t *dest, int sz, const char *src, int srcsz) { uint32_t ch; const char *src_end = src + srcsz; @@ -519,6 +513,69 @@ std::string CodepointToUTF8(uint32_t codePoint) { return std::string(temp); } +// Helper function to encode a Unicode code point into UTF-8, but doesn't support 4-byte output. +size_t encode_utf8_modified(uint32_t code_point, unsigned char* output) { + if (code_point <= 0x7F) { + output[0] = (unsigned char)code_point; + return 1; + } else if (code_point <= 0x7FF) { + output[0] = (unsigned char)(0xC0 | (code_point >> 6)); + output[1] = (unsigned char)(0x80 | (code_point & 0x3F)); + return 2; + } else if (code_point <= 0xFFFF) { + output[0] = (unsigned char)(0xE0 | (code_point >> 12)); + output[1] = (unsigned char)(0x80 | ((code_point >> 6) & 0x3F)); + output[2] = (unsigned char)(0x80 | (code_point & 0x3F)); + return 3; + } + return 0; +} + +// A function to convert regular UTF-8 to Java Modified UTF-8. Only used on Android. +// Written by ChatGPT and corrected and modified. +void ConvertUTF8ToJavaModifiedUTF8(std::string *output, std::string_view input) { + output->resize(input.size() * 6); // worst case: every character is encoded as 6 bytes + size_t out_idx = 0; + for (size_t i = 0; i < input.length(); ) { + unsigned char c = input[i]; + if (c == 0) { + // Encode null character as 0xC0 0x80. TODO: We probably don't need to support this? + output[out_idx++] = (char)0xC0; + output[out_idx++] = (char)0x80; + i++; + } else if ((c & 0xF0) == 0xF0) { // 4-byte sequence (U+10000 to U+10FFFF) + // Decode the Unicode code point from the UTF-8 sequence + uint32_t code_point = ((input[i] & 0x07) << 18) | + ((input[i + 1] & 0x3F) << 12) | + ((input[i + 2] & 0x3F) << 6) | + (input[i + 3] & 0x3F); + + // Convert to surrogate pair + uint16_t high_surrogate = ((code_point - 0x10000) / 0x400) + 0xD800; + uint16_t low_surrogate = ((code_point - 0x10000) % 0x400) + 0xDC00; + + // Encode the surrogates in UTF-8 + out_idx += encode_utf8_modified(high_surrogate, (unsigned char *)(output->data() + out_idx)); + out_idx += encode_utf8_modified(low_surrogate, (unsigned char *)(output->data() + out_idx)); + + i += 4; + } else { + // Copy the other UTF-8 sequences (1-3 bytes) + size_t utf8_len = 1; + if ((c & 0xE0) == 0xC0) { + utf8_len = 2; // 2-byte sequence + } else if ((c & 0xF0) == 0xE0) { + utf8_len = 3; // 3-byte sequence + } + memcpy(output->data() + out_idx, input.data() + i, utf8_len); + out_idx += utf8_len; + i += utf8_len; + } + } + output->resize(out_idx); + _dbg_assert_(output->size() >= input.size()); +} + #ifndef _WIN32 // Replacements for the Win32 wstring functions. Not to be used from emulation code! diff --git a/Common/Data/Encoding/Utf8.h b/Common/Data/Encoding/Utf8.h index 7a397d2c5c..dc9696f2b3 100644 --- a/Common/Data/Encoding/Utf8.h +++ b/Common/Data/Encoding/Utf8.h @@ -126,3 +126,7 @@ std::string ConvertUCS2ToUTF8(const std::u16string &wstr); // Dest size in units, not bytes. void ConvertUTF8ToUCS2(char16_t *dest, size_t destSize, std::string_view source); std::u16string ConvertUTF8ToUCS2(std::string_view source); + +// Java needs 4-byte UTF-8 to be converted to surrogate pairs, each component of which get +// encoded into 3-byte UTF-8. +void ConvertUTF8ToJavaModifiedUTF8(std::string *output, std::string_view input); diff --git a/Common/GPU/OpenGL/thin3d_gl.cpp b/Common/GPU/OpenGL/thin3d_gl.cpp index cfdc883d0c..591f2eeffd 100644 --- a/Common/GPU/OpenGL/thin3d_gl.cpp +++ b/Common/GPU/OpenGL/thin3d_gl.cpp @@ -895,6 +895,7 @@ private: OpenGLTexture::OpenGLTexture(GLRenderManager *render, const TextureDesc &desc) : render_(render) { _dbg_assert_(desc.format != Draw::DataFormat::UNDEFINED); + _dbg_assert_msg_(desc.width > 0 && desc.height > 0 && desc.depth > 0, "w: %d h: %d d: %d fmt: %s", desc.width, desc.height, desc.depth, DataFormatToString(desc.format)); _dbg_assert_(desc.width > 0 && desc.height > 0 && desc.depth > 0); _dbg_assert_(desc.type != Draw::TextureType::UNKNOWN); diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.cpp b/Common/GPU/Vulkan/VulkanQueueRunner.cpp index 69ee85220e..867dccacf9 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.cpp +++ b/Common/GPU/Vulkan/VulkanQueueRunner.cpp @@ -1061,17 +1061,21 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c "expected %d sample count, got %d", fbSampleCount, graphicsPipeline->SampleCount()); } - if (!graphicsPipeline->pipeline[(size_t)rpType]) { - // NOTE: If render steps got merged, it can happen that, as they ended during recording, - // they didn't know their final render pass type so they created the wrong pipelines in EndCurRenderStep(). - // Unfortunately I don't know if we can fix it in any more sensible place than here. - // Maybe a middle pass. But let's try to just block and compile here for now, this doesn't - // happen all that much. - graphicsPipeline->pipeline[(size_t)rpType] = Promise::CreateEmpty(); - graphicsPipeline->Create(vulkan_, renderPass->Get(vulkan_, rpType, fbSampleCount), rpType, fbSampleCount, time_now_d(), -1); - } + VkPipeline pipeline; - VkPipeline pipeline = graphicsPipeline->pipeline[(size_t)rpType]->BlockUntilReady(); + { + std::lock_guard lock(graphicsPipeline->mutex_); + if (!graphicsPipeline->pipeline[(size_t)rpType]) { + // NOTE: If render steps got merged, it can happen that, as they ended during recording, + // they didn't know their final render pass type so they created the wrong pipelines in EndCurRenderStep(). + // Unfortunately I don't know if we can fix it in any more sensible place than here. + // Maybe a middle pass. But let's try to just block and compile here for now, this doesn't + // happen all that much. + graphicsPipeline->pipeline[(size_t)rpType] = Promise::CreateEmpty(); + graphicsPipeline->Create(vulkan_, renderPass->Get(vulkan_, rpType, fbSampleCount), rpType, fbSampleCount, time_now_d(), -1); + } + pipeline = graphicsPipeline->pipeline[(size_t)rpType]->BlockUntilReady(); + } if (pipeline != VK_NULL_HANDLE) { vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 5c6a6ac58c..b774d4123d 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -349,7 +349,7 @@ bool VulkanRenderManager::CreateBackbuffers() { void VulkanRenderManager::StartThreads() { { - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); _assert_(compileQueue_.empty()); } @@ -370,6 +370,8 @@ void VulkanRenderManager::StartThreads() { // Called from main thread. void VulkanRenderManager::StopThreads() { + // Make sure we don't have an open render pass. + EndCurRenderStep(); // Not sure this is a sensible check - should be ok even if not. // _dbg_assert_(steps_.empty()); @@ -395,7 +397,7 @@ void VulkanRenderManager::StopThreads() { } { - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); runCompileThread_ = false; // Compiler and present thread both look at this bool. _assert_(compileThread_.joinable()); compileCond_.notify_one(); @@ -410,7 +412,7 @@ void VulkanRenderManager::StopThreads() { CreateMultiPipelinesTask::WaitForAll(); { - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); _assert_(compileQueue_.empty()); } } @@ -425,7 +427,7 @@ void VulkanRenderManager::DestroyBackbuffers() { void VulkanRenderManager::CheckNothingPending() { _assert_(pipelinesToCheck_.empty()); { - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); _assert_(compileQueue_.empty()); } } @@ -434,7 +436,7 @@ VulkanRenderManager::~VulkanRenderManager() { INFO_LOG(Log::G3D, "VulkanRenderManager destructor"); { - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); _assert_(compileQueue_.empty()); } @@ -462,7 +464,7 @@ void VulkanRenderManager::CompileThreadFunc() { bool exitAfterCompile = false; std::vector toCompile; { - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); while (compileQueue_.empty() && runCompileThread_) { compileCond_.wait(lock); } @@ -521,7 +523,7 @@ void VulkanRenderManager::CompileThreadFunc() { sleep_ms(1); } - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); _assert_(compileQueue_.empty()); } @@ -794,7 +796,7 @@ VKRGraphicsPipeline *VulkanRenderManager::CreateGraphicsPipeline(VKRGraphicsPipe VKRRenderPassStoreAction::STORE, VKRRenderPassStoreAction::DONT_CARE, VKRRenderPassStoreAction::DONT_CARE, }; VKRRenderPass *compatibleRenderPass = queueRunner_.GetRenderPass(key); - std::unique_lock lock(compileMutex_); + std::unique_lock lock(compileQueueMutex_); bool needsCompile = false; for (size_t i = 0; i < (size_t)RenderPassType::TYPE_COUNT; i++) { if (!(variantBitmask & (1 << i))) @@ -865,13 +867,14 @@ void VulkanRenderManager::EndCurRenderStep() { VkSampleCountFlagBits sampleCount = curRenderStep_->render.framebuffer ? curRenderStep_->render.framebuffer->sampleCount : VK_SAMPLE_COUNT_1_BIT; - compileMutex_.lock(); + compileQueueMutex_.lock(); bool needsCompile = false; for (VKRGraphicsPipeline *pipeline : pipelinesToCheck_) { if (!pipeline) { // Not good, but let's try not to crash. continue; } + std::lock_guard lock(pipeline->mutex_); if (!pipeline->pipeline[(size_t)rpType]) { pipeline->pipeline[(size_t)rpType] = Promise::CreateEmpty(); _assert_(renderPass); @@ -881,7 +884,7 @@ void VulkanRenderManager::EndCurRenderStep() { } if (needsCompile) compileCond_.notify_one(); - compileMutex_.unlock(); + compileQueueMutex_.unlock(); pipelinesToCheck_.clear(); // We don't do this optimization for very small targets, probably not worth it. diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index 1f7dad7f53..e68f521faf 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -137,11 +137,11 @@ struct VKRGraphicsPipeline { VKRGraphicsPipelineDesc *desc = nullptr; Promise *pipeline[(size_t)RenderPassType::TYPE_COUNT]{}; + std::mutex mutex_; // protects the pipeline array VkSampleCountFlagBits SampleCount() const { return sampleCount_; } const char *Tag() const { return tag_.c_str(); } - private: void DestroyVariantsInstant(VkDevice device); @@ -285,9 +285,9 @@ public: void ReportBadStateForDraw(); void NudgeCompilerThread() { - compileMutex_.lock(); + compileQueueMutex_.lock(); compileCond_.notify_one(); - compileMutex_.unlock(); + compileQueueMutex_.unlock(); } void AssertInRenderPass() const { @@ -615,7 +615,7 @@ private: std::thread compileThread_; // Sync std::condition_variable compileCond_; - std::mutex compileMutex_; + std::mutex compileQueueMutex_; std::vector compileQueue_; // Thread for measuring presentation delay. diff --git a/Common/Math/CrossSIMD.h b/Common/Math/CrossSIMD.h index 4e7f8ab909..3d171bb1a8 100644 --- a/Common/Math/CrossSIMD.h +++ b/Common/Math/CrossSIMD.h @@ -40,7 +40,7 @@ // Compatibility wrappers making ARM64 NEON code run on ARM32 // With optimization on, these should compile down to the optimal code. -inline float32x4_t vmulq_laneq_f32(float32x4_t a, float32x4_t b, int lane) { +static inline float32x4_t vmulq_laneq_f32(float32x4_t a, float32x4_t b, int lane) { switch (lane & 3) { case 0: return vmulq_lane_f32(a, vget_low_f32(b), 0); case 1: return vmulq_lane_f32(a, vget_low_f32(b), 1); @@ -49,7 +49,7 @@ inline float32x4_t vmulq_laneq_f32(float32x4_t a, float32x4_t b, int lane) { } } -inline float32x4_t vmlaq_laneq_f32(float32x4_t a, float32x4_t b, float32x4_t c, int lane) { +static inline float32x4_t vmlaq_laneq_f32(float32x4_t a, float32x4_t b, float32x4_t c, int lane) { switch (lane & 3) { case 0: return vmlaq_lane_f32(a, b, vget_low_f32(c), 0); case 1: return vmlaq_lane_f32(a, b, vget_low_f32(c), 1); @@ -58,7 +58,7 @@ inline float32x4_t vmlaq_laneq_f32(float32x4_t a, float32x4_t b, float32x4_t c, } } -inline uint32x4_t vcgezq_f32(float32x4_t v) { +static inline uint32x4_t vcgezq_f32(float32x4_t v) { return vcgeq_f32(v, vdupq_n_f32(0.0f)); } diff --git a/Common/Render/Text/draw_text.cpp b/Common/Render/Text/draw_text.cpp index 6c0c9af93f..1fa2a070b6 100644 --- a/Common/Render/Text/draw_text.cpp +++ b/Common/Render/Text/draw_text.cpp @@ -123,8 +123,8 @@ void TextDrawer::DrawString(DrawBuffer &target, std::string_view str, float x, f void TextDrawer::MeasureString(std::string_view str, float *w, float *h) { if (str.empty()) { - *w = 0.0; - *h = 0.0; + *w = 0.0f; + *h = 0.0f; return; } diff --git a/Common/Render/Text/draw_text_android.cpp b/Common/Render/Text/draw_text_android.cpp index 351d4b6d10..5c8f8765bb 100644 --- a/Common/Render/Text/draw_text_android.cpp +++ b/Common/Render/Text/draw_text_android.cpp @@ -83,15 +83,18 @@ void TextDrawerAndroid::MeasureStringInternal(std::string_view str, float *w, fl } else { ERROR_LOG(Log::G3D, "Missing font"); } - std::string text(str); + std::string text; + ConvertUTF8ToJavaModifiedUTF8(&text, str); + auto env = getEnv(); - // Unfortunate that we can't create a jstr from a std::string_view directly. jstring jstr = env->NewStringUTF(text.c_str()); uint32_t size = env->CallStaticIntMethod(cls_textRenderer, method_measureText, jstr, scaledSize); env->DeleteLocalRef(jstr); - *w = (size >> 16); - *h = (size & 0xFFFF); + *w = (float)(size >> 16); + *h = (float)(size & 0xFFFF); + + WARN_LOG(Log::G3D, "Measure Modified: '%.*s' size: %fx%f", (int)text.length(), text.data(), *w, *h); } bool TextDrawerAndroid::DrawStringBitmap(std::vector &bitmapData, TextStringEntry &entry, Draw::DataFormat texFormat, std::string_view str, int align, bool fullColor) { @@ -100,7 +103,7 @@ bool TextDrawerAndroid::DrawStringBitmap(std::vector &bitmapData, TextS return false; } - double size = 0.0; + float size = 0.0f; auto iter = fontMap_.find(fontHash_); if (iter != fontMap_.end()) { size = iter->second.size; @@ -109,7 +112,11 @@ bool TextDrawerAndroid::DrawStringBitmap(std::vector &bitmapData, TextS } auto env = getEnv(); - jstring jstr = env->NewStringUTF(std::string(str).c_str()); + + std::string text; + ConvertUTF8ToJavaModifiedUTF8(&text, str); + jstring jstr = env->NewStringUTF(text.c_str()); + uint32_t textSize = env->CallStaticIntMethod(cls_textRenderer, method_measureText, jstr, size); int imageWidth = (short)(textSize >> 16); int imageHeight = (short)(textSize & 0xFFFF); @@ -117,6 +124,7 @@ bool TextDrawerAndroid::DrawStringBitmap(std::vector &bitmapData, TextS imageWidth = 1; if (imageHeight <= 0) imageHeight = 1; + WARN_LOG(Log::G3D, "Text: '%.*s' (%02x)", (int)str.length(), str.data(), str[0]); jintArray imageData = (jintArray)env->CallStaticObjectMethod(cls_textRenderer, method_renderText, jstr, size); env->DeleteLocalRef(jstr); diff --git a/Common/Render/Text/draw_text_android.h b/Common/Render/Text/draw_text_android.h index 3d14e31f9f..24360b23f1 100644 --- a/Common/Render/Text/draw_text_android.h +++ b/Common/Render/Text/draw_text_android.h @@ -10,7 +10,7 @@ #include struct AndroidFontEntry { - double size; + float size; }; class TextDrawerAndroid : public TextDrawer { diff --git a/Common/Render/Text/draw_text_win.cpp b/Common/Render/Text/draw_text_win.cpp index b49f4fd039..28a8aeb4f0 100644 --- a/Common/Render/Text/draw_text_win.cpp +++ b/Common/Render/Text/draw_text_win.cpp @@ -151,7 +151,6 @@ bool TextDrawerWin32::DrawStringBitmap(std::vector &bitmapData, TextStr bitmapData.clear(); return false; } - std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(str, "\n", "\r\n")); auto iter = fontMap_.find(fontHash_); diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 2c90f615c8..5bb12deea6 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -100,6 +100,16 @@ bool containsNoCase(std::string_view haystack, std::string_view needle) { return found != haystack.end(); } +int countChar(std::string_view haystack, char needle) { + int count = 0; + for (int i = 0; i < haystack.size(); i++) { + if (haystack[i] == needle) { + count++; + } + } + return count; +} + bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args) { int writtenCount = vsnprintf(out, outsize, format, args); diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 0543466a8e..7f5ffaff31 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -85,6 +85,8 @@ std::string_view StripQuotes(std::string_view s); std::string_view StripPrefix(std::string_view prefix, std::string_view s); +int countChar(std::string_view haystack, char needle); + // NOTE: str must live at least as long as all uses of output. void SplitString(std::string_view str, const char delim, std::vector &output); // Try to avoid this when possible, in favor of the string_view version. diff --git a/Core/Config.cpp b/Core/Config.cpp index 918f1e26a5..7bca357f3e 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -714,7 +714,7 @@ static const ConfigSetting soundSettings[] = { ConfigSetting("AutoAudioDevice", &g_Config.bAutoAudioDevice, true, CfgFlag::DEFAULT), ConfigSetting("AudioMixWithOthers", &g_Config.bAudioMixWithOthers, true, CfgFlag::DEFAULT), ConfigSetting("AudioRespectSilentMode", &g_Config.bAudioRespectSilentMode, false, CfgFlag::DEFAULT), - ConfigSetting("UseNewAtrac", &g_Config.bUseNewAtrac, false, CfgFlag::DEFAULT), + ConfigSetting("UseExperimentalAtrac", &g_Config.bUseExperimentalAtrac, false, CfgFlag::DONT_SAVE), }; static bool DefaultShowTouchControls() { diff --git a/Core/Config.h b/Core/Config.h index 6767eb3725..50eef87096 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -280,7 +280,7 @@ public: bool bExtraAudioBuffering; // For bluetooth std::string sAudioDevice; bool bAutoAudioDevice; - bool bUseNewAtrac; + bool bUseExperimentalAtrac; // iOS only for now bool bAudioMixWithOthers; diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 12a2eec522..82a7fa532e 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -209,12 +209,9 @@ void SaveFileInfo::DoState(PointerWrap &p) SavedataParam::SavedataParam() { } -void SavedataParam::Init() -{ - if (!pspFileSystem.GetFileInfo(savePath).exists) - { - pspFileSystem.MkDir(savePath); - } +void SavedataParam::Init() { + // If the folder already exists, this is a no-op. + pspFileSystem.MkDir(savePath); // Create a nomedia file to hide save icons form Android image viewer #if PPSSPP_PLATFORM(ANDROID) int handle = pspFileSystem.OpenFile(savePath + ".nomedia", (FileAccess)(FILEACCESS_CREATE | FILEACCESS_WRITE), 0); @@ -459,7 +456,7 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD } } - u8* cryptedData = 0; + u8* cryptedData = nullptr; int cryptedSize = 0; u8 cryptedHash[0x10]{}; // Encrypt save. diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 7ac530bc5b..9f74b329a9 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -138,7 +138,7 @@ void __AtracDoState(PointerWrap &p) { } static AtracBase *allocAtrac(bool forceOld = false) { - if (g_Config.bUseNewAtrac && !forceOld) { + if (g_Config.bUseExperimentalAtrac && !forceOld) { return new Atrac2(); } else { return new Atrac(); diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index e6526fa089..d0b0b8d035 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -657,6 +657,13 @@ void SoftGPU::CopyDisplayToOutput(bool reallyDirty) { MarkDirty(displayFramebuf_, displayStride_, 272, displayFormat_, SoftGPUVRAMDirty::CLEAR); } +void SoftGPU::BeginHostFrame() { + GPUCommon::BeginHostFrame(); + if (presentation_) { + presentation_->BeginFrame(); + } +} + bool SoftGPU::PresentedThisFrame() const { return presentation_->PresentedThisFrame(); } diff --git a/GPU/Software/SoftGpu.h b/GPU/Software/SoftGpu.h index 870aa95810..5ecd94db4e 100644 --- a/GPU/Software/SoftGpu.h +++ b/GPU/Software/SoftGpu.h @@ -209,6 +209,7 @@ public: typedef void (SoftGPU::*CmdFunc)(u32 op, u32 diff); + void BeginHostFrame() override; bool PresentedThisFrame() const override; protected: diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index c92091ec21..acd1abcffe 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -343,7 +343,7 @@ UI::EventReturn ControlMappingScreen::OnAutoConfigure(UI::EventParams ¶ms) { } void ControlMappingScreen::dialogFinished(const Screen *dialog, DialogResult result) { - if (result == DR_OK && std::string(dialog->tag()) == "listpopup") { + if (result == DR_OK && !strcmp(dialog->tag(), "listpopup")) { UI::ListPopupScreen *popup = (UI::ListPopupScreen *)dialog; KeyMap::AutoConfForPad(popup->GetChoiceString()); } diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 607c5cd80a..ea8612c5de 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -384,6 +384,8 @@ LogLevelScreen::LogLevelScreen(std::string_view title) : ListPopupScreen(title) list.push_back(logLevelList[i]); } adaptor_ = UI::StringVectorListAdaptor(list, -1); + + // CreateViews takes care of, well, that. } void LogLevelScreen::OnCompleted(DialogResult result) { diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index d91f97c04b..ccdd67a737 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1281,14 +1281,16 @@ bool EmuScreen::checkPowerDown() { } if (coreState == CORE_POWERDOWN && !PSP_IsIniting() && !PSP_IsRebooting()) { + bool shutdown = false; if (PSP_IsInited()) { PSP_Shutdown(); + shutdown = true; } INFO_LOG(Log::System, "SELF-POWERDOWN!"); screenManager()->switchScreen(new MainScreen()); bootPending_ = false; invalid_ = true; - return true; + return shutdown; } return false; } @@ -1513,12 +1515,13 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, clearColor }, "EmuScreen_NoFrame"); draw->SetViewport(viewport); draw->SetScissorRect(0, 0, g_display.pixel_xres, g_display.pixel_yres); + framebufferBound = true; } Draw::BackendState state = draw->GetCurrentBackendState(); // We allow if !state.valid, that means it's not the Vulkan backend. - _assert_msg_(!state.valid || state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, mode, (int)g_Config.iGPUBackend); + _assert_msg_(!state.valid || state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend); screenManager()->getUIContext()->BeginFrame(); @@ -1533,7 +1536,9 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { } // NOTE: We don't check for powerdown if we're not the top screen. - checkPowerDown(); + if (checkPowerDown()) { + draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, clearColor }, "EmuScreen_PowerDown"); + } if (hasVisibleUI()) { draw->SetViewport(viewport); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 60e56c5ca0..e1629f5479 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1842,7 +1842,7 @@ void DeveloperToolsScreen::CreateViews() { cpuTests->SetEnabled(TestsAvailable()); #endif - list->Add(new CheckBox(&g_Config.bUseNewAtrac, dev->T("Use experimental sceAtrac"))); + // list->Add(new CheckBox(&g_Config.bUseExperimentalAtrac, dev->T("Use experimental sceAtrac"))); AddOverlayList(list, screenManager()); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 0ad6eb28ed..d5e9c30c6f 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -1251,8 +1251,19 @@ void MainScreen::CreateViews() { rightColumnItems->SetSpacing(0.0f); rightColumn->Add(rightColumnItems); - char versionString[256]; - snprintf(versionString, sizeof(versionString), "%s", PPSSPP_GIT_VERSION); + std::string versionString = PPSSPP_GIT_VERSION; + // Strip the 'v' from the displayed version, and shorten the commit hash. + if (versionString.size() > 2) { + if (versionString[0] == 'v' && isdigit(versionString[1])) { + versionString = versionString.substr(1); + } + if (countChar(versionString, '-') == 2) { + // Shorten the commit hash. + size_t cutPos = versionString.find_last_of('-') + 8; + versionString = versionString.substr(0, std::min(cutPos, versionString.size())); + } + } + rightColumnItems->SetSpacing(0.0f); AnchorLayout *logos = new AnchorLayout(new AnchorLayoutParams(FILL_PARENT, 60.0f, false)); if (System_GetPropertyBool(SYSPROP_APP_GOLD)) { diff --git a/Windows/CaptureDevice.cpp b/Windows/CaptureDevice.cpp index 93376078c8..c002fce593 100644 --- a/Windows/CaptureDevice.cpp +++ b/Windows/CaptureDevice.cpp @@ -202,9 +202,9 @@ HRESULT ReaderCallback::OnReadSample( // Mirror the image in-place if needed. if (g_Config.bCameraMirrorHorizontal) { - for (int y = 0; y < dstH; y++) { + for (int y = 0; y < (int)dstH; y++) { uint8_t *line = device->imageRGB + y * device->imgRGBLineSizes[0]; - for (int x = 0; x < dstW / 2; x++) { + for (int x = 0; x < (int)dstW / 2; x++) { const int invX = dstW - 1 - x; const uint8_t r = line[x * 3 + 0]; const uint8_t g = line[x * 3 + 1]; diff --git a/assets/compat.ini b/assets/compat.ini index beabb9aa6b..c86e513f86 100644 --- a/assets/compat.ini +++ b/assets/compat.ini @@ -473,6 +473,9 @@ ULES00703 = true ULJM05940 = true NPJH50794 = true +# Cave Story (homebrew) +CAVE00992 = true + # TODO: There are many more. [RequireBlockTransfer] diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 20a3359790..f2ee68aafa 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -501,7 +501,7 @@ int main(int argc, const char* argv[]) g_Config.iGlobalVolume = VOLUME_FULL; g_Config.iReverbVolume = VOLUME_FULL; g_Config.internalDataDirectory.clear(); - g_Config.bUseNewAtrac = newAtrac; + g_Config.bUseExperimentalAtrac = newAtrac; Path exePath = File::GetExeDirectory(); g_Config.flash0Directory = exePath / "assets/flash0";