Add more features to GPU Memory profiler tab
This commit is contained in:
@@ -218,11 +218,27 @@ namespace FlaxEditor.GUI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Action RightClick;
|
public Action RightClick;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The double click event.
|
||||||
|
/// </summary>
|
||||||
|
public Action<ClickableRow> RowDoubleClick;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The left mouse button click event.
|
||||||
|
/// </summary>
|
||||||
|
public Action<ClickableRow> RowLeftClick;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The right mouse button click event.
|
||||||
|
/// </summary>
|
||||||
|
public Action<ClickableRow> RowRightClick;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
|
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
|
||||||
{
|
{
|
||||||
DoubleClick?.Invoke();
|
DoubleClick?.Invoke();
|
||||||
|
RowDoubleClick?.Invoke(this);
|
||||||
|
|
||||||
return base.OnMouseDoubleClick(location, button);
|
return base.OnMouseDoubleClick(location, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,11 +260,13 @@ namespace FlaxEditor.GUI
|
|||||||
{
|
{
|
||||||
_leftClick = false;
|
_leftClick = false;
|
||||||
LeftClick?.Invoke();
|
LeftClick?.Invoke();
|
||||||
|
RowLeftClick?.Invoke(this);
|
||||||
}
|
}
|
||||||
else if (button == MouseButton.Right && _isRightDown)
|
else if (button == MouseButton.Right && _isRightDown)
|
||||||
{
|
{
|
||||||
_isRightDown = false;
|
_isRightDown = false;
|
||||||
RightClick?.Invoke();
|
RightClick?.Invoke();
|
||||||
|
RowRightClick?.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnMouseUp(location, button);
|
return base.OnMouseUp(location, button);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
using FlaxEditor.GUI;
|
using FlaxEditor.GUI;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
@@ -17,9 +18,11 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
private struct Resource
|
private struct Resource
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
|
public string Tooltip;
|
||||||
public GPUResourceType Type;
|
public GPUResourceType Type;
|
||||||
public ulong MemoryUsage;
|
public ulong MemoryUsage;
|
||||||
public Guid AssetId;
|
public Guid AssetId;
|
||||||
|
public bool IsAssetItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly SingleChart _memoryUsageChart;
|
private readonly SingleChart _memoryUsageChart;
|
||||||
@@ -29,6 +32,7 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
private string[] _resourceTypesNames;
|
private string[] _resourceTypesNames;
|
||||||
private Dictionary<string, Guid> _assetPathToId;
|
private Dictionary<string, Guid> _assetPathToId;
|
||||||
private Dictionary<Guid, Resource> _resourceCache;
|
private Dictionary<Guid, Resource> _resourceCache;
|
||||||
|
private StringBuilder _stringBuilder;
|
||||||
|
|
||||||
public MemoryGPU()
|
public MemoryGPU()
|
||||||
: base("GPU Memory")
|
: base("GPU Memory")
|
||||||
@@ -111,10 +115,14 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
_resourceCache = new Dictionary<Guid, Resource>();
|
_resourceCache = new Dictionary<Guid, Resource>();
|
||||||
if (_assetPathToId == null)
|
if (_assetPathToId == null)
|
||||||
_assetPathToId = new Dictionary<string, Guid>();
|
_assetPathToId = new Dictionary<string, Guid>();
|
||||||
|
if (_stringBuilder == null)
|
||||||
|
_stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
// Capture current GPU resources usage info
|
// Capture current GPU resources usage info
|
||||||
|
var contentDatabase = Editor.Instance.ContentDatabase;
|
||||||
var gpuResources = GPUDevice.Instance.Resources;
|
var gpuResources = GPUDevice.Instance.Resources;
|
||||||
var resources = new Resource[gpuResources.Length];
|
var resources = new Resource[gpuResources.Length];
|
||||||
|
var sb = _stringBuilder;
|
||||||
for (int i = 0; i < resources.Length; i++)
|
for (int i = 0; i < resources.Length; i++)
|
||||||
{
|
{
|
||||||
var gpuResource = gpuResources[i];
|
var gpuResource = gpuResources[i];
|
||||||
@@ -129,6 +137,35 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
Type = gpuResource.ResourceType,
|
Type = gpuResource.ResourceType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create tooltip
|
||||||
|
sb.Clear();
|
||||||
|
if (gpuResource is GPUTexture gpuTexture)
|
||||||
|
{
|
||||||
|
var desc = gpuTexture.Description;
|
||||||
|
sb.Append("Format: ").Append(desc.Format).AppendLine();
|
||||||
|
sb.Append("Size: ").Append(desc.Width).Append('x').Append(desc.Height);
|
||||||
|
if (desc.Depth != 1)
|
||||||
|
sb.Append('x').Append(desc.Depth);
|
||||||
|
if (desc.ArraySize != 1)
|
||||||
|
sb.Append('[').Append(desc.ArraySize).Append(']');
|
||||||
|
sb.AppendLine();
|
||||||
|
sb.Append("Mip Levels: ").Append(desc.MipLevels).AppendLine();
|
||||||
|
if (desc.IsMultiSample)
|
||||||
|
sb.Append("MSAA: ").Append('x').Append((int)desc.MultiSampleLevel).AppendLine();
|
||||||
|
sb.Append("Flags: ").Append(desc.Flags).AppendLine();
|
||||||
|
sb.Append("Usage: ").Append(desc.Usage);
|
||||||
|
}
|
||||||
|
else if (gpuResource is GPUBuffer gpuBuffer)
|
||||||
|
{
|
||||||
|
var desc = gpuBuffer.Description;
|
||||||
|
sb.Append("Format: ").Append(desc.Format).AppendLine();
|
||||||
|
sb.Append("Stride: ").Append(desc.Stride).AppendLine();
|
||||||
|
sb.Append("Elements: ").Append(desc.ElementsCount).AppendLine();
|
||||||
|
sb.Append("Flags: ").Append(desc.Flags).AppendLine();
|
||||||
|
sb.Append("Usage: ").Append(desc.Usage);
|
||||||
|
}
|
||||||
|
resource.Tooltip = _stringBuilder.ToString();
|
||||||
|
|
||||||
// Detect asset path in the resource name
|
// Detect asset path in the resource name
|
||||||
int ext = resource.Name.LastIndexOf(".flax", StringComparison.OrdinalIgnoreCase);
|
int ext = resource.Name.LastIndexOf(".flax", StringComparison.OrdinalIgnoreCase);
|
||||||
if (ext != -1)
|
if (ext != -1)
|
||||||
@@ -141,6 +178,12 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
resource.AssetId = asset.ID;
|
resource.AssetId = asset.ID;
|
||||||
_assetPathToId.Add(assetPath, resource.AssetId);
|
_assetPathToId.Add(assetPath, resource.AssetId);
|
||||||
}
|
}
|
||||||
|
var assetItem = contentDatabase.FindAsset(resource.AssetId);
|
||||||
|
if (assetItem != null)
|
||||||
|
{
|
||||||
|
resource.IsAssetItem = true;
|
||||||
|
resource.Name = assetItem.NamePath + resource.Name.Substring(ext + 5); // Use text after asset path to display (eg. subobject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_resourceCache.Add(gpuResourceId, resource);
|
_resourceCache.Add(gpuResourceId, resource);
|
||||||
@@ -190,6 +233,7 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
_resourceCache?.Clear();
|
_resourceCache?.Clear();
|
||||||
_assetPathToId?.Clear();
|
_assetPathToId?.Clear();
|
||||||
_tableRowsCache?.Clear();
|
_tableRowsCache?.Clear();
|
||||||
|
_stringBuilder?.Clear();
|
||||||
|
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
@@ -234,7 +278,6 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
|
|
||||||
// Add rows
|
// Add rows
|
||||||
var rowColor2 = Style.Current.Background * 1.4f;
|
var rowColor2 = Style.Current.Background * 1.4f;
|
||||||
var contentDatabase = Editor.Instance.ContentDatabase;
|
|
||||||
for (int i = 0; i < resources.Length; i++)
|
for (int i = 0; i < resources.Length; i++)
|
||||||
{
|
{
|
||||||
ref var e = ref resources[i];
|
ref var e = ref resources[i];
|
||||||
@@ -259,15 +302,12 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
row.Values[2] = e.MemoryUsage;
|
row.Values[2] = e.MemoryUsage;
|
||||||
|
|
||||||
// Setup row interactions
|
// Setup row interactions
|
||||||
row.TooltipText = null;
|
row.Tag = e;
|
||||||
row.DoubleClick = null;
|
row.TooltipText = e.Tooltip;
|
||||||
var assetItem = contentDatabase.FindAsset(e.AssetId);
|
row.RowDoubleClick = null;
|
||||||
if (assetItem != null)
|
if (e.IsAssetItem)
|
||||||
{
|
{
|
||||||
row.Values[0] = assetItem.NamePath;
|
row.RowDoubleClick = OnRowDoubleClickAsset;
|
||||||
assetItem.UpdateTooltipText();
|
|
||||||
row.TooltipText = assetItem.TooltipText;
|
|
||||||
row.DoubleClick = () => { Editor.Instance.ContentEditing.Open(assetItem); };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add row to the table
|
// Add row to the table
|
||||||
@@ -276,5 +316,12 @@ namespace FlaxEditor.Windows.Profiler
|
|||||||
row.Parent = _table;
|
row.Parent = _table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRowDoubleClickAsset(ClickableRow row)
|
||||||
|
{
|
||||||
|
var e = (Resource)row.Tag;
|
||||||
|
var assetItem = Editor.Instance.ContentDatabase.FindAsset(e.AssetId);
|
||||||
|
Editor.Instance.ContentEditing.Open(assetItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user