Add events for streamable resources residency changes tracking

This commit is contained in:
Wojciech Figat
2022-04-21 12:37:39 +02:00
parent 0a458d94c4
commit 5345d1f685
6 changed files with 27 additions and 7 deletions

View File

@@ -91,6 +91,7 @@ public:
// Update residency level
model->_loadedLODs++;
model->ResidencyChanged();
return false;
}
@@ -697,11 +698,8 @@ bool Model::Init(const Span<int32>& meshesCountPerLod)
// Setup LODs
for (int32 lodIndex = 0; lodIndex < LODs.Count(); lodIndex++)
{
LODs[lodIndex].Dispose();
}
LODs.Resize(meshesCountPerLod.Length());
_loadedLODs = meshesCountPerLod.Length();
// Setup meshes
for (int32 lodIndex = 0; lodIndex < meshesCountPerLod.Length(); lodIndex++)
@@ -720,6 +718,10 @@ bool Model::Init(const Span<int32>& meshesCountPerLod)
}
}
// Update resource residency
_loadedLODs = meshesCountPerLod.Length();
ResidencyChanged();
return false;
}
@@ -836,6 +838,7 @@ Task* Model::CreateStreamingTask(int32 residency)
for (int32 i = HighestResidentLODIndex(); i < LODs.Count() - residency; i++)
LODs[i].Unload();
_loadedLODs = residency;
ResidencyChanged();
}
return result;
@@ -945,7 +948,7 @@ Asset::LoadResult Model::load()
sdfStream.Read(&data);
if (!SDF.Texture)
SDF.Texture = GPUTexture::New();
if (SDF.Texture->Init(GPUTextureDescription::New3D(data.Width, data.Height, data.Depth, data.Format, GPUTextureFlags::ShaderResource | GPUTextureFlags::UnorderedAccess, data.MipLevels)))
if (SDF.Texture->Init(GPUTextureDescription::New3D(data.Width, data.Height, data.Depth, data.Format, GPUTextureFlags::ShaderResource, data.MipLevels)))
return LoadResult::Failed;
SDF.LocalToUVWMul = data.LocalToUVWMul;
SDF.LocalToUVWAdd = data.LocalToUVWAdd;

View File

@@ -85,6 +85,7 @@ protected:
// Update residency level
model->_loadedLODs++;
model->ResidencyChanged();
return false;
}
@@ -676,11 +677,8 @@ bool SkinnedModel::Init(const Span<int32>& meshesCountPerLod)
// Setup LODs
for (int32 lodIndex = 0; lodIndex < LODs.Count(); lodIndex++)
{
LODs[lodIndex].Dispose();
}
LODs.Resize(meshesCountPerLod.Length());
_loadedLODs = meshesCountPerLod.Length();
// Setup meshes
for (int32 lodIndex = 0; lodIndex < meshesCountPerLod.Length(); lodIndex++)
@@ -699,6 +697,10 @@ bool SkinnedModel::Init(const Span<int32>& meshesCountPerLod)
}
}
// Update resource residency
_loadedLODs = meshesCountPerLod.Length();
ResidencyChanged();
return false;
}
@@ -827,6 +829,7 @@ Task* SkinnedModel::CreateStreamingTask(int32 residency)
for (int32 i = HighestResidentLODIndex(); i < LODs.Count() - residency; i++)
LODs[i].Unload();
_loadedLODs = residency;
ResidencyChanged();
}
return result;

View File

@@ -814,4 +814,5 @@ void GPUTexture::SetResidentMipLevels(int32 count)
return;
_residentMipLevels = count;
OnResidentMipsChanged();
ResidentMipsChanged(this);
}

View File

@@ -568,6 +568,11 @@ public:
/// </summary>
API_PROPERTY() void SetResidentMipLevels(int32 count);
/// <summary>
/// Event called when texture residency gets changed. Texture Mip gets loaded into GPU memory and is ready to use.
/// </summary>
Delegate<GPUTexture*> ResidentMipsChanged;
protected:
virtual bool OnInit() = 0;

View File

@@ -233,6 +233,7 @@ protected:
{
Swap(_streamingTexture->_texture, _newTexture);
_streamingTexture->GetTexture()->SetResidentMipLevels(_uploadedMipCount);
_streamingTexture->ResidencyChanged();
SAFE_DELETE_GPU_RESOURCE(_newTexture);
// Base
@@ -447,6 +448,7 @@ Task* StreamingTexture::CreateStreamingTask(int32 residency)
{
// Do the quick data release
_texture->ReleaseGPU();
ResidencyChanged();
}
else
{

View File

@@ -2,6 +2,7 @@
#pragma once
#include "Engine/Core/Delegate.h"
#include "Engine/Core/Collections/SamplesBuffer.h"
class StreamingGroup;
@@ -111,6 +112,11 @@ public:
};
StreamingCache Streaming;
/// <summary>
/// Event called when current resource residency gets changed (eg. model LOD or texture MIP gets loaded). Usually called from async thread.
/// </summary>
Action ResidencyChanged;
/// <summary>
/// Requests the streaming update for this resource during next streaming manager update.