Merge pull request #18487 from hrydgard/misc-cleanup

Misc code cleanup
This commit is contained in:
Henrik Rydgård 2023-12-07 18:05:17 +01:00 committed by GitHub
commit 89c320fe2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 46 additions and 38 deletions

View file

@ -69,7 +69,8 @@ public:
void clear() { size_ = 0; } void clear() { size_ = 0; }
bool empty() const { return size_ == 0; } bool empty() const { return size_ == 0; }
const T *data() { return data_; } const T *data() const { return data_; }
T *begin() { return data_; } T *begin() { return data_; }
T *end() { return data_ + size_; } T *end() { return data_ + size_; }
const T *begin() const { return data_; } const T *begin() const { return data_; }

View file

@ -2,6 +2,8 @@
#include <vector> #include <vector>
#include "Common/Log.h"
// Insert-only small-set implementation. Performs no allocation unless MaxFastSize is exceeded. // Insert-only small-set implementation. Performs no allocation unless MaxFastSize is exceeded.
// Can also be used as a small vector, then use push_back (or push_in_place) instead of insert. // Can also be used as a small vector, then use push_back (or push_in_place) instead of insert.
// Duplicates are thus allowed if you use that, but not if you exclusively use insert. // Duplicates are thus allowed if you use that, but not if you exclusively use insert.
@ -32,16 +34,18 @@ struct TinySet {
} }
slowLookup_->push_back(t); slowLookup_->push_back(t);
} }
inline T *add_back() { inline T &push_uninitialized() {
if (fastCount_ < MaxFastSize) { if (fastCount_ < MaxFastSize) {
return &fastLookup_[fastCount_++]; return fastLookup_[fastCount_++];
} }
if (!slowLookup_) { if (!slowLookup_) {
slowLookup_ = new std::vector<T>(); slowLookup_ = new std::vector<T>();
} }
// The slow lookup is also slow at adding.
T t; T t;
slowLookup_->push_back(t); slowLookup_->push_back(t);
return slowLookup_->back(); return *slowLookup_->back();
} }
void append(const TinySet<T, MaxFastSize> &other) { void append(const TinySet<T, MaxFastSize> &other) {
size_t otherSize = other.size(); size_t otherSize = other.size();
@ -136,8 +140,8 @@ private:
}; };
template <class T, int MaxSize> template <class T, int MaxSize>
struct FixedTinyVec { struct FixedVec {
~FixedTinyVec() {} ~FixedVec() {}
// WARNING: Can fail if you exceed MaxSize! // WARNING: Can fail if you exceed MaxSize!
inline bool push_back(const T &t) { inline bool push_back(const T &t) {
if (count_ < MaxSize) { if (count_ < MaxSize) {
@ -147,13 +151,16 @@ struct FixedTinyVec {
return false; return false;
} }
} }
// WARNING: Can fail if you exceed MaxSize! // WARNING: Can fail if you exceed MaxSize!
inline T *add_back() { inline T &push_uninitialized() {
if (count_ < MaxSize) { if (count_ < MaxSize) {
return &data_[count_++]; return &data_[count_++];
} }
return nullptr; _dbg_assert_(false);
return *data_[MaxSize - 1]; // BAD
} }
// Invalid if empty(). // Invalid if empty().
void pop_back() { count_--; } void pop_back() { count_--; }
@ -184,7 +191,7 @@ struct FixedTinyVec {
const T &back() const { return (*this)[size() - 1]; } const T &back() const { return (*this)[size() - 1]; }
const T &front() const { return (*this)[0]; } const T &front() const { return (*this)[0]; }
bool operator == (const FixedTinyVec<T, MaxSize> &other) const { bool operator == (const FixedVec<T, MaxSize> &other) const {
if (count_ != other.count_) if (count_ != other.count_)
return false; return false;
for (int i = 0; i < count_; i++) { for (int i = 0; i < count_; i++) {

View file

@ -5,6 +5,7 @@
#include "Common/Log.h" #include "Common/Log.h"
#include "Common/GPU/Vulkan/VulkanLoader.h" #include "Common/GPU/Vulkan/VulkanLoader.h"
#include "Common/Data/Collections/FastVec.h"
class VulkanContext; class VulkanContext;
@ -13,6 +14,8 @@ class VulkanContext;
// However, not thread safe in any way! // However, not thread safe in any way!
class VulkanBarrier { class VulkanBarrier {
public: public:
VulkanBarrier() : imageBarriers_(4) {}
void TransitionImage( void TransitionImage(
VkImage image, int baseMip, int numMipLevels, int numLayers, VkImageAspectFlags aspectMask, VkImage image, int baseMip, int numMipLevels, int numLayers, VkImageAspectFlags aspectMask,
VkImageLayout oldImageLayout, VkImageLayout newImageLayout, VkImageLayout oldImageLayout, VkImageLayout newImageLayout,
@ -25,7 +28,7 @@ public:
dstStageMask_ |= dstStageMask; dstStageMask_ |= dstStageMask;
dependencyFlags_ |= VK_DEPENDENCY_BY_REGION_BIT; dependencyFlags_ |= VK_DEPENDENCY_BY_REGION_BIT;
VkImageMemoryBarrier imageBarrier; VkImageMemoryBarrier &imageBarrier = imageBarriers_.push_uninitialized();
imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imageBarrier.pNext = nullptr; imageBarrier.pNext = nullptr;
imageBarrier.srcAccessMask = srcAccessMask; imageBarrier.srcAccessMask = srcAccessMask;
@ -40,7 +43,6 @@ public:
imageBarrier.subresourceRange.baseArrayLayer = 0; imageBarrier.subresourceRange.baseArrayLayer = 0;
imageBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; imageBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; imageBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarriers_.push_back(imageBarrier);
} }
// Automatically determines access and stage masks from layouts. // Automatically determines access and stage masks from layouts.
@ -93,7 +95,7 @@ public:
break; break;
} }
VkImageMemoryBarrier imageBarrier; VkImageMemoryBarrier &imageBarrier = imageBarriers_.push_uninitialized();
imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imageBarrier.pNext = nullptr; imageBarrier.pNext = nullptr;
imageBarrier.srcAccessMask = srcAccessMask; imageBarrier.srcAccessMask = srcAccessMask;
@ -108,7 +110,6 @@ public:
imageBarrier.subresourceRange.baseArrayLayer = 0; imageBarrier.subresourceRange.baseArrayLayer = 0;
imageBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; imageBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; imageBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imageBarriers_.push_back(imageBarrier);
} }
void Flush(VkCommandBuffer cmd); void Flush(VkCommandBuffer cmd);
@ -116,6 +117,6 @@ public:
private: private:
VkPipelineStageFlags srcStageMask_ = 0; VkPipelineStageFlags srcStageMask_ = 0;
VkPipelineStageFlags dstStageMask_ = 0; VkPipelineStageFlags dstStageMask_ = 0;
std::vector<VkImageMemoryBarrier> imageBarriers_; FastVec<VkImageMemoryBarrier> imageBarriers_;
VkDependencyFlags dependencyFlags_ = 0; VkDependencyFlags dependencyFlags_ = 0;
}; };

View file

@ -188,6 +188,8 @@ enum SystemProperty {
SYSPROP_SKIP_UI, SYSPROP_SKIP_UI,
SYSPROP_USER_DOCUMENTS_DIR, SYSPROP_USER_DOCUMENTS_DIR,
SYSPROP_OK_BUTTON_LEFT,
}; };
enum class SystemNotification { enum class SystemNotification {

View file

@ -1,6 +1,9 @@
#include <algorithm> #include <algorithm>
#include "Common/Log.h"
#include "Common/System/Display.h" #include "Common/System/Display.h"
#include "Common/System/System.h" #include "Common/System/System.h"
#include "Common/System/Request.h"
#include "Common/Input/InputState.h" #include "Common/Input/InputState.h"
#include "Common/Input/KeyCodes.h" #include "Common/Input/KeyCodes.h"
#include "Common/Math/curves.h" #include "Common/Math/curves.h"
@ -10,8 +13,6 @@
#include "Common/UI/Root.h" #include "Common/UI/Root.h"
#include "Common/Data/Text/I18n.h" #include "Common/Data/Text/I18n.h"
#include "Common/Render/DrawBuffer.h" #include "Common/Render/DrawBuffer.h"
#include "Common/Log.h"
#include <Common/System/Request.h>
static const bool ClickDebug = false; static const bool ClickDebug = false;
@ -393,10 +394,8 @@ void PopupScreen::TriggerFinish(DialogResult result) {
OnCompleted(result); OnCompleted(result);
} }
#if PPSSPP_PLATFORM(UWP)
// Inform UI that popup close to hide OSK (if visible) // Inform UI that popup close to hide OSK (if visible)
System_NotifyUIState("popup_closed"); System_NotifyUIState("popup_closed");
#endif
} }
void PopupScreen::CreateViews() { void PopupScreen::CreateViews() {
@ -433,17 +432,17 @@ void PopupScreen::CreateViews() {
Margins buttonMargins(5, 5); Margins buttonMargins(5, 5);
// Adjust button order to the platform default. // Adjust button order to the platform default.
#if defined(_WIN32) if (System_GetPropertyBool(SYSPROP_OK_BUTTON_LEFT)) {
defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f, buttonMargins))); defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f, buttonMargins)));
defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK); defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
if (!button2_.empty()) if (!button2_.empty())
buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f, buttonMargins)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel); buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f, buttonMargins)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel);
#else } else {
if (!button2_.empty()) if (!button2_.empty())
buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel); buttonRow->Add(new Button(button2_, new LinearLayoutParams(1.0f)))->OnClick.Handle<UIScreen>(this, &UIScreen::OnCancel);
defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f))); defaultButton_ = buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f)));
defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK); defaultButton_->OnClick.Handle<UIScreen>(this, &UIScreen::OnOK);
#endif }
box_->Add(buttonRow); box_->Add(buttonRow);
} }

View file

@ -184,7 +184,7 @@ static bool DefaultVSync() {
} }
static bool DefaultEnableStateUndo() { static bool DefaultEnableStateUndo() {
#ifdef MOBILE_DEVICE #ifdef PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
// Off on mobile to save disk space. // Off on mobile to save disk space.
return false; return false;
#endif #endif

View file

@ -1405,10 +1405,6 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load
if (!module->isFake) { if (!module->isFake) {
bool scan = true; bool scan = true;
#if defined(MOBILE_DEVICE)
scan = g_Config.bFuncReplacements;
#endif
// If the ELF has debug symbols, don't add entries to the symbol table. // If the ELF has debug symbols, don't add entries to the symbol table.
bool insertSymbols = scan && !reader.LoadSymbols(); bool insertSymbols = scan && !reader.LoadSymbols();
std::vector<SectionID> codeSections = reader.GetCodeSections(); std::vector<SectionID> codeSections = reader.GetCodeSections();

View file

@ -408,8 +408,8 @@ const KeyMap_IntStrPair psp_button_names[] = {
{VIRTKEY_SPEED_CUSTOM2, "Alt speed 2"}, {VIRTKEY_SPEED_CUSTOM2, "Alt speed 2"},
{VIRTKEY_SPEED_ANALOG, "Analog speed"}, {VIRTKEY_SPEED_ANALOG, "Analog speed"},
{VIRTKEY_PAUSE, "Pause"}, {VIRTKEY_PAUSE, "Pause"},
#ifndef MOBILE_DEVICE
{VIRTKEY_FRAME_ADVANCE, "Frame Advance"}, {VIRTKEY_FRAME_ADVANCE, "Frame Advance"},
#if !defined(MOBILE_DEVICE)
{VIRTKEY_RECORD, "Audio/Video Recording" }, {VIRTKEY_RECORD, "Audio/Video Recording" },
#endif #endif
{VIRTKEY_REWIND, "Rewind"}, {VIRTKEY_REWIND, "Rewind"},

View file

@ -148,7 +148,7 @@ namespace KeyMap {
return false; return false;
} }
FixedTinyVec<InputMapping, 3> mappings; FixedVec<InputMapping, 3> mappings;
}; };
typedef std::map<int, std::vector<MultiInputMapping>> KeyMapping; typedef std::map<int, std::vector<MultiInputMapping>> KeyMapping;

View file

@ -566,11 +566,9 @@ void PSP_Shutdown() {
if (coreState == CORE_RUNNING) if (coreState == CORE_RUNNING)
Core_Stop(); Core_Stop();
#ifndef MOBILE_DEVICE
if (g_Config.bFuncHashMap) { if (g_Config.bFuncHashMap) {
MIPSAnalyst::StoreHashMap(); MIPSAnalyst::StoreHashMap();
} }
#endif
if (pspIsIniting) if (pspIsIniting)
Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE); Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE);

View file

@ -435,6 +435,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
} }
case SYSPROP_DEBUGGER_PRESENT: case SYSPROP_DEBUGGER_PRESENT:
return IsDebuggerPresent(); return IsDebuggerPresent();
case SYSPROP_OK_BUTTON_LEFT:
return true;
default: default:
return false; return false;
} }

View file

@ -383,6 +383,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
return !g_Config.bDisableHTTPS; return !g_Config.bDisableHTTPS;
case SYSPROP_DEBUGGER_PRESENT: case SYSPROP_DEBUGGER_PRESENT:
return IsDebuggerPresent(); return IsDebuggerPresent();
case SYSPROP_OK_BUTTON_LEFT:
return true;
default: default:
return false; return false;
} }