feat: show used video memory in dev bar

This commit is contained in:
goat 2023-01-02 13:23:36 +01:00
parent 41d41036d7
commit 0dc58cce56
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
2 changed files with 25 additions and 3 deletions

View file

@ -849,7 +849,12 @@ internal class DalamudInterface : IDisposable, IServiceType
ImGui.BeginMenu(Util.GetGitHash(), false);
ImGui.BeginMenu(this.FrameCount.ToString("000000"), false);
ImGui.BeginMenu(ImGui.GetIO().Framerate.ToString("000"), false);
ImGui.BeginMenu($"{Util.FormatBytes(GC.GetTotalMemory(false))}", false);
ImGui.BeginMenu($"W:{Util.FormatBytes(GC.GetTotalMemory(false))}", false);
var videoMem = Service<InterfaceManager>.Get().GetD3dMemoryInfo();
ImGui.BeginMenu(
!videoMem.HasValue ? $"V:???" : $"V:{Util.FormatBytes(videoMem.Value.Used)}",
false);
ImGui.PopFont();
}

View file

@ -26,7 +26,6 @@ using ImGuiNET;
using ImGuiScene;
using PInvoke;
using Serilog;
using SharpDX.Direct3D11;
// general dev notes, here because it's easiest
@ -147,7 +146,7 @@ internal class InterfaceManager : IDisposable, IServiceType
/// <summary>
/// Gets the D3D11 device instance.
/// </summary>
public Device? Device => this.scene?.Device;
public SharpDX.Direct3D11.Device? Device => this.scene?.Device;
/// <summary>
/// Gets the address handle to the main process window.
@ -409,6 +408,24 @@ internal class InterfaceManager : IDisposable, IServiceType
this.deferredDisposeTextures.Add(wrap);
}
/// <summary>
/// Get video memory information.
/// </summary>
/// <returns>The currently used video memory, or null if not available.</returns>
public (long Used, long Available)? GetD3dMemoryInfo()
{
if (this.Device == null)
return null;
var dxgiDev = this.Device.QueryInterface<SharpDX.DXGI.Device>();
var dxgiAdapter = dxgiDev.Adapter.QueryInterfaceOrNull<SharpDX.DXGI.Adapter4>();
if (dxgiAdapter == null)
return null;
var memInfo = dxgiAdapter.QueryVideoMemoryInfo(0, SharpDX.DXGI.MemorySegmentGroup.Local);
return (memInfo.CurrentUsage, memInfo.CurrentReservation);
}
private static void ShowFontError(string path)
{
Util.Fatal($"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}", "Error");