Fix NanoVDB volume loading and rendering
This commit is contained in:
@@ -379,6 +379,14 @@ bool WriteVolumeFieldArtifactFile(const fs::path& artifactPath, const VolumeFiel
|
||||
header.boundsMin = volumeField.GetBounds().GetMin();
|
||||
header.boundsMax = volumeField.GetBounds().GetMax();
|
||||
header.voxelSize = volumeField.GetVoxelSize();
|
||||
header.indexBoundsMin[0] = volumeField.GetIndexBounds().minX;
|
||||
header.indexBoundsMin[1] = volumeField.GetIndexBounds().minY;
|
||||
header.indexBoundsMin[2] = volumeField.GetIndexBounds().minZ;
|
||||
header.indexBoundsMax[0] = volumeField.GetIndexBounds().maxX;
|
||||
header.indexBoundsMax[1] = volumeField.GetIndexBounds().maxY;
|
||||
header.indexBoundsMax[2] = volumeField.GetIndexBounds().maxZ;
|
||||
header.gridType = volumeField.GetGridType();
|
||||
header.gridClass = volumeField.GetGridClass();
|
||||
header.payloadSize = static_cast<Core::uint64>(volumeField.GetPayloadSize());
|
||||
|
||||
output.write(reinterpret_cast<const char*>(&header), sizeof(header));
|
||||
|
||||
@@ -89,7 +89,7 @@ void ResourceCache::OnZeroRefCount(ResourceGUID guid) {
|
||||
void ResourceCache::Evict(size_t requiredBytes) {
|
||||
size_t released = 0;
|
||||
|
||||
// Simple eviction: remove from end of LRU list
|
||||
// ResourceManager owns resource lifetime. This cache only drops its LRU bookkeeping.
|
||||
while (released < requiredBytes && m_lruOrder.Size() > 0) {
|
||||
ResourceGUID guid = m_lruOrder.Back();
|
||||
m_lruOrder.PopBack();
|
||||
@@ -98,7 +98,6 @@ void ResourceCache::Evict(size_t requiredBytes) {
|
||||
if (it != nullptr) {
|
||||
m_memoryUsage -= it->memorySize;
|
||||
released += it->memorySize;
|
||||
it->resource->Release();
|
||||
m_cache.Erase(guid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,11 @@ void ResourceManager::Unload(ResourceGUID guid) {
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
auto* refCount = m_refCounts.Find(guid);
|
||||
if (refCount != nullptr && *refCount > 0u) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* it = m_resourceCache.Find(guid);
|
||||
if (it != nullptr) {
|
||||
resource = *it;
|
||||
@@ -233,22 +238,38 @@ void ResourceManager::Unload(ResourceGUID guid) {
|
||||
|
||||
void ResourceManager::UnloadAll() {
|
||||
Containers::Array<IResource*> resourcesToRelease;
|
||||
Containers::Array<ResourceGUID> guidsToRelease;
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
const auto cachedResources = m_resourceCache.GetPairs();
|
||||
resourcesToRelease.Reserve(cachedResources.Size());
|
||||
guidsToRelease.Reserve(cachedResources.Size());
|
||||
for (const auto& pair : cachedResources) {
|
||||
if (pair.second != nullptr) {
|
||||
resourcesToRelease.PushBack(pair.second);
|
||||
if (pair.second == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto* refCount = m_refCounts.Find(pair.first);
|
||||
if (refCount != nullptr && *refCount > 0u) {
|
||||
continue;
|
||||
}
|
||||
|
||||
guidsToRelease.PushBack(pair.first);
|
||||
resourcesToRelease.PushBack(pair.second);
|
||||
}
|
||||
|
||||
m_resourceCache.Clear();
|
||||
m_cache.Clear();
|
||||
m_refCounts.Clear();
|
||||
m_guidToPath.Clear();
|
||||
m_memoryUsage = 0;
|
||||
for (const ResourceGUID& guid : guidsToRelease) {
|
||||
auto* it = m_resourceCache.Find(guid);
|
||||
if (it == nullptr || *it == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
m_memoryUsage -= (*it)->GetMemorySize();
|
||||
m_resourceCache.Erase(guid);
|
||||
m_cache.Remove(guid);
|
||||
m_guidToPath.Erase(guid);
|
||||
}
|
||||
}
|
||||
|
||||
for (IResource* resource : resourcesToRelease) {
|
||||
|
||||
Reference in New Issue
Block a user