Skip to content

Commit

Permalink
GameInfo: Try to reduce the locking a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 18, 2024
1 parent e5339bd commit 74f5be0
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 26 deletions.
4 changes: 4 additions & 0 deletions Common/GPU/Vulkan/VulkanDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ VKAPI_ATTR VkBool32 VKAPI_CALL VulkanDebugUtilsCallback(
// Clear value but no LOAD_OP_CLEAR. Not worth fixing right now.
return false;

case 1544472022:
// MSAA depth resolve write-after-write??
return false;

default:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions Common/GPU/Vulkan/VulkanDescSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class VulkanDescSetPool {
return !descPool_;
}

void SetTag(const char *tag) {
tag_ = tag;
}

private:
VkResult Recreate(bool grow);

Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/VulkanRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ void VulkanRenderManager::ResetStats() {

VKRPipelineLayout *VulkanRenderManager::CreatePipelineLayout(BindingType *bindingTypes, size_t bindingTypesCount, bool geoShadersEnabled, const char *tag) {
VKRPipelineLayout *layout = new VKRPipelineLayout();
layout->tag = tag;
layout->SetTag(tag);
layout->bindingTypesCount = (uint32_t)bindingTypesCount;

_dbg_assert_(bindingTypesCount <= ARRAY_SIZE(layout->bindingTypes));
Expand Down
12 changes: 10 additions & 2 deletions Common/GPU/Vulkan/VulkanRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ struct PackedDescriptor {
};

// Note that we only support a single descriptor set due to compatibility with some ancient devices.
// We should probably eventually give that up.
// We should probably eventually give that up eventually.
struct VKRPipelineLayout {
~VKRPipelineLayout();

enum { MAX_DESC_SET_BINDINGS = 10 };
BindingType bindingTypes[MAX_DESC_SET_BINDINGS];

Expand All @@ -205,7 +206,8 @@ struct VKRPipelineLayout {
const char *tag = nullptr;

struct FrameData {
FrameData() : pool("GameDescPool", true) {}
FrameData() : pool("N/A", true) {}

VulkanDescSetPool pool;
FastVec<PackedDescriptor> descData_;
FastVec<PendingDescSet> descSets_;
Expand All @@ -217,6 +219,12 @@ struct VKRPipelineLayout {
FrameData frameData[VulkanContext::MAX_INFLIGHT_FRAMES];

void FlushDescSets(VulkanContext *vulkan, int frame, QueueProfileContext *profile);
void SetTag(const char *tag) {
this->tag = tag;
for (int i = 0; i < ARRAY_SIZE(frameData); i++) {
frameData[i].pool.SetTag(tag);
}
}
};

class VulkanRenderManager {
Expand Down
3 changes: 3 additions & 0 deletions Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ class VKContext : public DrawContext {
~VKContext();

void DebugAnnotate(const char *annotation) override;
void Wait() override {
vkDeviceWaitIdle(vulkan_->GetDevice());
}

const DeviceCaps &GetDeviceCaps() const override {
return caps_;
Expand Down
2 changes: 2 additions & 0 deletions Common/GPU/thin3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ class DrawContext {

Bugs GetBugs() const { return bugs_; }

virtual void Wait() {}

virtual const DeviceCaps &GetDeviceCaps() const = 0;
virtual uint32_t GetDataFormatSupport(DataFormat fmt) const = 0;
virtual std::vector<std::string> GetFeatureList() const { return std::vector<std::string>(); }
Expand Down
4 changes: 2 additions & 2 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ void TextureCacheVulkan::DeviceLost() {

nextTexture_ = nullptr;
draw_ = nullptr;
Unbind();
}

void TextureCacheVulkan::DeviceRestore(Draw::DrawContext *draw) {
Expand Down Expand Up @@ -372,8 +373,7 @@ void TextureCacheVulkan::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutB

void TextureCacheVulkan::BindTexture(TexCacheEntry *entry) {
if (!entry || !entry->vkTex) {
imageView_ = VK_NULL_HANDLE;
curSampler_ = VK_NULL_HANDLE;
Unbind();
return;
}

Expand Down
53 changes: 32 additions & 21 deletions UI/GameInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,25 @@ u64 GameInfo::GetInstallDataSizeInBytes() {
}

bool GameInfo::LoadFromPath(const Path &gamePath) {
std::lock_guard<std::mutex> guard(lock);
// No need to rebuild if we already have it loaded.
if (filePath_ != gamePath) {
{
std::lock_guard<std::mutex> guard(loaderLock);
fileLoader.reset(ConstructFileLoader(gamePath));
if (!fileLoader)
return false;
{
std::lock_guard<std::mutex> guard(lock);
// No need to rebuild if we already have it loaded.
if (filePath_ == gamePath) {
return true;
}
filePath_ = gamePath;
}

// This is a fallback title, while we're loading / if unable to load.
title = filePath_.GetFilename();
{
std::lock_guard<std::mutex> guard(loaderLock);
fileLoader.reset(ConstructFileLoader(gamePath));
if (!fileLoader)
return false;
}

std::lock_guard<std::mutex> guard(lock);
filePath_ = gamePath;
// This is a fallback title, while we're loading / if unable to load.
title = filePath_.GetFilename();
return true;
}

Expand Down Expand Up @@ -476,20 +480,26 @@ class GameInfoWorkItem : public Task {

if (info_->wantFlags & GAMEINFO_WANTBG) {
if (pbp.GetSubFileSize(PBP_PIC0_PNG) > 0) {
std::string data;
pbp.GetSubFileAsString(PBP_PIC0_PNG, &data);
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_PIC0_PNG, &info_->pic0.data);
info_->pic0.data = std::move(data);
info_->pic0.dataLoaded = true;
}
if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) {
std::string data;
pbp.GetSubFileAsString(PBP_PIC1_PNG, &data);
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1.data);
info_->pic1.data = std::move(data);
info_->pic1.dataLoaded = true;
}
}
if (info_->wantFlags & GAMEINFO_WANTSND) {
if (pbp.GetSubFileSize(PBP_SND0_AT3) > 0) {
std::string data;
pbp.GetSubFileAsString(PBP_SND0_AT3, &data);
std::lock_guard<std::mutex> lock(info_->lock);
pbp.GetSubFileAsString(PBP_SND0_AT3, &info_->sndFileData);
info_->sndFileData = std::move(data);
info_->sndDataLoaded = true;
}
}
Expand Down Expand Up @@ -628,16 +638,17 @@ class GameInfoWorkItem : public Task {
// Alright, let's fetch the PARAM.SFO.
std::string paramSFOcontents;
if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", &paramSFOcontents, nullptr)) {
std::lock_guard<std::mutex> lock(info_->lock);
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
info_->ParseParamSFO();

{
std::lock_guard<std::mutex> lock(info_->lock);
info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
info_->ParseParamSFO();
}
if (info_->wantFlags & GAMEINFO_WANTBG) {
info_->pic0.dataLoaded = ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0.data, nullptr);
info_->pic1.dataLoaded = ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1.data, nullptr);
info_->pic0.dataLoaded = ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0.data, &info_->lock);
info_->pic1.dataLoaded = ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1.data, &info_->lock);
}
if (info_->wantFlags & GAMEINFO_WANTSND) {
info_->sndDataLoaded = ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, nullptr);
info_->sndDataLoaded = ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock);
}
}

Expand Down

0 comments on commit 74f5be0

Please sign in to comment.