Add GPUDevice.DumpResources command and fix output to be sorted by size and cleaner to read
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "Engine/Content/Assets/Material.h"
|
||||
#include "Engine/Content/Content.h"
|
||||
#include "Engine/Content/SoftAssetReference.h"
|
||||
#include "Engine/Core/Collections/Sorting.h"
|
||||
#include "Engine/Render2D/Render2D.h"
|
||||
#include "Engine/Engine/CommandLine.h"
|
||||
#include "Engine/Engine/Engine.h"
|
||||
@@ -511,7 +512,7 @@ void GPUDevice::DumpResourcesToLog() const
|
||||
true, // CubeTexture
|
||||
true, // VolumeTexture
|
||||
true, // Buffer
|
||||
true, // Shader
|
||||
false, // Shader
|
||||
false, // PipelineState
|
||||
false, // Descriptor
|
||||
false, // Query
|
||||
@@ -522,29 +523,86 @@ void GPUDevice::DumpResourcesToLog() const
|
||||
const auto type = static_cast<GPUResourceType>(typeIndex);
|
||||
const auto printType = printTypes[typeIndex];
|
||||
|
||||
output.AppendFormat(TEXT("Group: {0}s"), ScriptingEnum::ToString(type));
|
||||
output.AppendLine();
|
||||
|
||||
int32 count = 0;
|
||||
// Get resource sof a given type
|
||||
uint64 memUsage = 0;
|
||||
struct Resource
|
||||
{
|
||||
const GPUResource* Object;
|
||||
uint64 MemoryUsage;
|
||||
|
||||
bool operator<(const Resource& other) const
|
||||
{
|
||||
if (MemoryUsage != other.MemoryUsage)
|
||||
return MemoryUsage > other.MemoryUsage;
|
||||
return Object->GetName().Compare(other.Object->GetName()) > 0;
|
||||
}
|
||||
};
|
||||
Array<Resource> resources;
|
||||
for (int32 i = 0; i < _resources.Count(); i++)
|
||||
{
|
||||
const GPUResource* resource = _resources[i];
|
||||
if (resource->GetResourceType() == type && resource->GetMemoryUsage() != 0)
|
||||
{
|
||||
count++;
|
||||
memUsage += resource->GetMemoryUsage();
|
||||
auto str = resource->ToString();
|
||||
if (str.HasChars() && printType)
|
||||
{
|
||||
output.Append(TEXT('\t'));
|
||||
output.Append(str);
|
||||
output.AppendLine();
|
||||
}
|
||||
resources.Add({ resource, resource->GetMemoryUsage() });
|
||||
}
|
||||
}
|
||||
if (resources.IsEmpty())
|
||||
continue;
|
||||
output.AppendFormat(TEXT("> {0}:"), ScriptingEnum::ToString(type));
|
||||
output.AppendLine();
|
||||
|
||||
output.AppendFormat(TEXT("Total count: {0}, memory usage: {1}"), count, Utilities::BytesToText(memUsage));
|
||||
// Sort them by size
|
||||
Sorting::QuickSort(resources);
|
||||
|
||||
// Print resources
|
||||
for (auto e : resources)
|
||||
{
|
||||
memUsage += e.MemoryUsage;
|
||||
if (!printType)
|
||||
continue;
|
||||
output.Append(TEXT(" "));
|
||||
output.Append(Utilities::BytesToText(e.MemoryUsage));
|
||||
output.Append(TEXT(", "));
|
||||
if (e.Object->Is<GPUTexture>())
|
||||
{
|
||||
auto texture = (GPUTexture*)e.Object;
|
||||
auto& desc = texture->GetDescription();
|
||||
output.AppendFormat(TEXT("Size: {}x{}x{}[{}], "), desc.Width, desc.Height, desc.Depth, desc.ArraySize);
|
||||
if (texture->ResidentMipLevels() == desc.MipLevels)
|
||||
output.AppendFormat(TEXT("Mips: {}, "), desc.MipLevels);
|
||||
else
|
||||
output.AppendFormat(TEXT("Mips: {}/{}, "), texture->ResidentMipLevels(), desc.MipLevels);
|
||||
#if GPU_ENABLE_RESOURCE_NAMING
|
||||
auto name = texture->GetName();
|
||||
#else
|
||||
StringView name;
|
||||
#endif
|
||||
output.AppendFormat(TEXT("Format: {}, Flags: {}, {}"), ScriptingEnum::ToString(desc.Format), ScriptingEnum::ToStringFlags(desc.Flags), name);
|
||||
}
|
||||
else if (e.Object->Is<GPUBuffer>())
|
||||
{
|
||||
auto buffer = (GPUBuffer*)e.Object;
|
||||
auto& desc = buffer->GetDescription();
|
||||
output.AppendFormat(TEXT("Stride: {} bytes, "), desc.Stride);
|
||||
if (desc.Format != PixelFormat::Unknown)
|
||||
output.AppendFormat(TEXT("Format: {}, "), ScriptingEnum::ToString(desc.Format));
|
||||
if (desc.Usage != GPUResourceUsage::Default)
|
||||
output.AppendFormat(TEXT("Usage: {}, "), ScriptingEnum::ToString(desc.Usage));
|
||||
#if GPU_ENABLE_RESOURCE_NAMING
|
||||
auto name = buffer->GetName();
|
||||
#else
|
||||
StringView name;
|
||||
#endif
|
||||
output.AppendFormat(TEXT("Flags: {}, {}"), ScriptingEnum::ToStringFlags(desc.Flags), name);
|
||||
}
|
||||
else
|
||||
{
|
||||
output.Append(e.Object->ToString());
|
||||
}
|
||||
output.AppendLine();
|
||||
}
|
||||
|
||||
output.AppendFormat(TEXT("Total count: {0}, memory usage: {1}"), resources.Count(), Utilities::BytesToText(memUsage));
|
||||
output.AppendLine();
|
||||
output.AppendLine();
|
||||
}
|
||||
@@ -553,6 +611,12 @@ void GPUDevice::DumpResourcesToLog() const
|
||||
LOG_STR(Info, output.ToStringView());
|
||||
}
|
||||
|
||||
void GPUDevice::DumpResources()
|
||||
{
|
||||
if (GPUDevice::Instance)
|
||||
GPUDevice::Instance->DumpResourcesToLog();
|
||||
}
|
||||
|
||||
extern void ClearVertexLayoutCache();
|
||||
|
||||
void GPUDevice::preDispose()
|
||||
|
||||
@@ -389,6 +389,11 @@ public:
|
||||
/// </summary>
|
||||
void DumpResourcesToLog() const;
|
||||
|
||||
/// <summary>
|
||||
/// Dumps all GPU resources information to the log.
|
||||
/// </summary>
|
||||
API_FUNCTION(Attributes="DebugCommand") static void DumpResources();
|
||||
|
||||
protected:
|
||||
virtual void preDispose();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user