mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 08:30:35 +02:00
clear all _cacheFiles on recycle
This commit is contained in:
parent
3477aa57a8
commit
3ae52c0e0e
3 changed files with 23 additions and 4 deletions
|
@ -772,7 +772,7 @@ void GLBackend::recycle() const {
|
||||||
|
|
||||||
GLVariableAllocationSupport::manageMemory();
|
GLVariableAllocationSupport::manageMemory();
|
||||||
GLVariableAllocationSupport::_frameTexturesCreated = 0;
|
GLVariableAllocationSupport::_frameTexturesCreated = 0;
|
||||||
|
Texture::KtxStorage::clearKtxFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::setCameraCorrection(const Mat4& correction) {
|
void GLBackend::setCameraCorrection(const Mat4& correction) {
|
||||||
|
|
|
@ -321,10 +321,15 @@ public:
|
||||||
|
|
||||||
void reset() override { }
|
void reset() override { }
|
||||||
|
|
||||||
|
// Don't keep files open forever. We close them at the beginning of each frame (GLBackend::recycle)
|
||||||
|
static std::vector<std::pair<std::shared_ptr<storage::FileStorage>, std::shared_ptr<std::mutex>>> _cachedKtxFiles;
|
||||||
|
static std::mutex _cachedKtxFilesMutex;
|
||||||
|
static void clearKtxFiles();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<storage::FileStorage> maybeOpenFile() const;
|
std::shared_ptr<storage::FileStorage> maybeOpenFile() const;
|
||||||
|
|
||||||
mutable std::mutex _cacheFileMutex;
|
mutable std::shared_ptr<std::mutex> _cacheFileMutex { std::make_shared<std::mutex>() };
|
||||||
mutable std::shared_ptr<storage::FileStorage> _cacheFile;
|
mutable std::shared_ptr<storage::FileStorage> _cacheFile;
|
||||||
|
|
||||||
std::string _filename;
|
std::string _filename;
|
||||||
|
|
|
@ -23,6 +23,9 @@ using namespace gpu;
|
||||||
using PixelsPointer = Texture::PixelsPointer;
|
using PixelsPointer = Texture::PixelsPointer;
|
||||||
using KtxStorage = Texture::KtxStorage;
|
using KtxStorage = Texture::KtxStorage;
|
||||||
|
|
||||||
|
std::vector<std::pair<std::shared_ptr<storage::FileStorage>, std::shared_ptr<std::mutex>>> KtxStorage::_cachedKtxFiles;
|
||||||
|
std::mutex KtxStorage::_cachedKtxFilesMutex;
|
||||||
|
|
||||||
struct GPUKTXPayload {
|
struct GPUKTXPayload {
|
||||||
using Version = uint8;
|
using Version = uint8;
|
||||||
|
|
||||||
|
@ -190,15 +193,26 @@ KtxStorage::KtxStorage(const std::string& filename) : _filename(filename) {
|
||||||
std::shared_ptr<storage::FileStorage> KtxStorage::maybeOpenFile() const {
|
std::shared_ptr<storage::FileStorage> KtxStorage::maybeOpenFile() const {
|
||||||
if (!_cacheFile) {
|
if (!_cacheFile) {
|
||||||
_cacheFile = std::make_shared<storage::FileStorage>(_filename.c_str());
|
_cacheFile = std::make_shared<storage::FileStorage>(_filename.c_str());
|
||||||
|
std::lock_guard<std::mutex> lock(KtxStorage::_cachedKtxFilesMutex);
|
||||||
|
_cachedKtxFiles.emplace_back(_cacheFile, _cacheFileMutex);
|
||||||
}
|
}
|
||||||
return _cacheFile;
|
return _cacheFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KtxStorage::clearKtxFiles() {
|
||||||
|
std::lock_guard<std::mutex> lock(KtxStorage::_cachedKtxFilesMutex);
|
||||||
|
for (auto& cacheFileAndMutex : KtxStorage::_cachedKtxFiles) {
|
||||||
|
std::lock_guard<std::mutex> lock(*(cacheFileAndMutex.second));
|
||||||
|
cacheFileAndMutex.first.reset();
|
||||||
|
}
|
||||||
|
_cachedKtxFiles.clear();
|
||||||
|
}
|
||||||
|
|
||||||
PixelsPointer KtxStorage::getMipFace(uint16 level, uint8 face) const {
|
PixelsPointer KtxStorage::getMipFace(uint16 level, uint8 face) const {
|
||||||
auto faceOffset = _ktxDescriptor->getMipFaceTexelsOffset(level, face);
|
auto faceOffset = _ktxDescriptor->getMipFaceTexelsOffset(level, face);
|
||||||
auto faceSize = _ktxDescriptor->getMipFaceTexelsSize(level, face);
|
auto faceSize = _ktxDescriptor->getMipFaceTexelsSize(level, face);
|
||||||
if (faceSize != 0 && faceOffset != 0) {
|
if (faceSize != 0 && faceOffset != 0) {
|
||||||
std::lock_guard<std::mutex> lock(_cacheFileMutex);
|
std::lock_guard<std::mutex> lock(*_cacheFileMutex);
|
||||||
auto file = maybeOpenFile();
|
auto file = maybeOpenFile();
|
||||||
if (file) {
|
if (file) {
|
||||||
auto storageView = file->createView(faceSize, faceOffset);
|
auto storageView = file->createView(faceSize, faceOffset);
|
||||||
|
@ -244,7 +258,7 @@ void KtxStorage::assignMipData(uint16 level, const storage::StoragePointer& stor
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(_cacheFileMutex);
|
std::lock_guard<std::mutex> lock(*_cacheFileMutex);
|
||||||
auto file = maybeOpenFile();
|
auto file = maybeOpenFile();
|
||||||
if (!file) {
|
if (!file) {
|
||||||
qWarning() << "Failed to open file to assign mip data " << QString::fromStdString(_filename);
|
qWarning() << "Failed to open file to assign mip data " << QString::fromStdString(_filename);
|
||||||
|
|
Loading…
Reference in a new issue