Skip to content

Commit

Permalink
Some code moving, tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 12, 2023
1 parent 3136b9f commit 432f29a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
60 changes: 30 additions & 30 deletions GPU/Common/ReplacedTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ class ReplacedTextureTask : public Task {
LimitedWaitable *waitable_;
};

ReplacedTexture::~ReplacedTexture() {
if (threadWaitable_) {
SetState(ReplacementState::CANCEL_INIT);

std::unique_lock<std::mutex> lock(mutex_);
threadWaitable_->WaitAndRelease();
threadWaitable_ = nullptr;
}

for (auto &level : levels_) {
vfs_->ReleaseFile(level.fileRef);
level.fileRef = nullptr;
}
}

void ReplacedTexture::PurgeIfOlder(double t) {
if (threadWaitable_ && !threadWaitable_->WaitFor(0.0))
return;
if (lastUsed_ >= t)
return;

if (levelData_->lastUsed < t) {
// We have to lock since multiple textures might reference this same data.
std::lock_guard<std::mutex> guard(levelData_->lock);
levelData_->data.clear();
// This means we have to reload. If we never purge any, there's no need.
SetState(ReplacementState::POPULATED);
}
}

// This can only return true if ACTIVE or NOT_FOUND.
bool ReplacedTexture::IsReady(double budget) {
_assert_(vfs_ != nullptr);
Expand Down Expand Up @@ -476,36 +506,6 @@ bool ReplacedTexture::LoadLevelData(ReplacedTextureLevel &level, int mipLevel, D
return true;
}

void ReplacedTexture::PurgeIfOlder(double t) {
if (threadWaitable_ && !threadWaitable_->WaitFor(0.0))
return;
if (lastUsed_ >= t)
return;

if (levelData_->lastUsed < t) {
// We have to lock since multiple textures might reference this same data.
std::lock_guard<std::mutex> guard(levelData_->lock);
levelData_->data.clear();
// This means we have to reload. If we never purge any, there's no need.
SetState(ReplacementState::POPULATED);
}
}

ReplacedTexture::~ReplacedTexture() {
if (threadWaitable_) {
SetState(ReplacementState::CANCEL_INIT);

std::unique_lock<std::mutex> lock(mutex_);
threadWaitable_->WaitAndRelease();
threadWaitable_ = nullptr;
}

for (auto &level : levels_) {
vfs_->ReleaseFile(level.fileRef);
level.fileRef = nullptr;
}
}

bool ReplacedTexture::CopyLevelTo(int level, void *out, int rowPitch) {
_assert_msg_((size_t)level < levels_.size(), "Invalid miplevel");
_assert_msg_(out != nullptr && rowPitch > 0, "Invalid out/pitch");
Expand Down
4 changes: 2 additions & 2 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ void SystemInfoScreen::CreateViews() {
// Simple non-detailed summary of supported tex compression formats.
if (draw->GetDataFormatSupport(Draw::DataFormat::ETC2_R8G8B8_UNORM_BLOCK)) texCompressionFormats += "ETC2 ";
if (draw->GetDataFormatSupport(Draw::DataFormat::ASTC_4x4_UNORM_BLOCK)) texCompressionFormats += "ASTC ";
if (draw->GetDataFormatSupport(Draw::DataFormat::BC1_RGBA_UNORM_BLOCK)) texCompressionFormats += "BC1,2,3 ";
if (draw->GetDataFormatSupport(Draw::DataFormat::BC4_UNORM_BLOCK)) texCompressionFormats += "BC4,5 ";
if (draw->GetDataFormatSupport(Draw::DataFormat::BC1_RGBA_UNORM_BLOCK)) texCompressionFormats += "BC1-3 ";
if (draw->GetDataFormatSupport(Draw::DataFormat::BC4_UNORM_BLOCK)) texCompressionFormats += "BC4-5 ";
if (draw->GetDataFormatSupport(Draw::DataFormat::BC7_UNORM_BLOCK)) texCompressionFormats += "BC7 ";
deviceSpecs->Add(new InfoItem(si->T("Compressed texture formats"), texCompressionFormats));

Expand Down

0 comments on commit 432f29a

Please sign in to comment.