Add Texture Conversion IPC and use texture tasks.

This commit is contained in:
Ottermandias 2023-08-10 16:55:43 +02:00
parent af93c2aca9
commit 6e11b36401
9 changed files with 305 additions and 109 deletions

View file

@ -2,6 +2,7 @@ using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
@ -144,7 +145,7 @@ public partial class ModEditWindow
_left.Format is DXGIFormat.BC7Typeless or DXGIFormat.BC7UNorm or DXGIFormat.BC7UNormSRGB))
{
_center.SaveAsTex(_textures, _left.Path, CombinedTexture.TextureSaveType.BC7, _left.MipMaps > 1);
ReloadConvertedSubscribe(_left.Path, _center.SaveGuid);
AddReloadTask(_left.Path);
}
ImGui.SameLine();
@ -153,7 +154,7 @@ public partial class ModEditWindow
_left.Format is DXGIFormat.BC3Typeless or DXGIFormat.BC3UNorm or DXGIFormat.BC3UNormSRGB))
{
_center.SaveAsTex(_textures, _left.Path, CombinedTexture.TextureSaveType.BC3, _left.MipMaps > 1);
ReloadConvertedSubscribe(_left.Path, _center.SaveGuid);
AddReloadTask(_left.Path);
}
ImGui.SameLine();
@ -162,7 +163,7 @@ public partial class ModEditWindow
_left.Format is DXGIFormat.B8G8R8A8UNorm or DXGIFormat.B8G8R8A8Typeless or DXGIFormat.B8G8R8A8UNormSRGB))
{
_center.SaveAsTex(_textures, _left.Path, CombinedTexture.TextureSaveType.Bitmap, _left.MipMaps > 1);
ReloadConvertedSubscribe(_left.Path, _center.SaveGuid);
AddReloadTask(_left.Path);
}
}
else
@ -173,18 +174,20 @@ public partial class ModEditWindow
ImGui.NewLine();
}
if (_center.SaveGuid != Guid.Empty)
switch (_center.SaveTask.Status)
{
var state = _textures.GetState(_center.SaveGuid, out var saveException, out _, out _);
if (saveException != null)
case TaskStatus.WaitingForActivation:
case TaskStatus.WaitingToRun:
case TaskStatus.Running:
ImGui.TextUnformatted("Computing...");
break;
case TaskStatus.Canceled:
case TaskStatus.Faulted:
{
ImGui.TextUnformatted("Could not save file:");
using var color = ImRaii.PushColor(ImGuiCol.Text, 0xFF0000FF);
ImGuiUtil.TextWrapped(saveException.ToString());
}
else if (state == ActionState.Running)
{
ImGui.TextUnformatted("Computing...");
ImGuiUtil.TextWrapped(_center.SaveTask.Exception?.ToString() ?? "Unknown Error");
break;
}
}
@ -193,23 +196,18 @@ public partial class ModEditWindow
_center.Draw(_textures, imageSize);
}
private void ReloadConvertedSubscribe(string path, Guid guid)
private void AddReloadTask(string path)
{
void Reload(Guid eventGuid, ActionState state, Exception? ex)
_center.SaveTask.ContinueWith(t =>
{
if (guid != eventGuid)
if (!t.IsCompletedSuccessfully)
return;
if (_left.Path != path)
return;
if (state is ActionState.Succeeded)
_dalamud.Framework.RunOnFrameworkThread(() => _left.Reload(_textures));
_textures.Finished -= Reload;
}
_textures.Finished += Reload;
_dalamud.Framework.RunOnFrameworkThread(() => _left.Reload(_textures));
});
}
private Vector2 GetChildWidth()

View file

@ -19,6 +19,7 @@ using Penumbra.Collections.Manager;
using Penumbra.GameData.Actors;
using Penumbra.GameData.Files;
using Penumbra.Import.Structs;
using Penumbra.Import.Textures;
using Penumbra.Interop.ResourceLoading;
using Penumbra.Interop.PathResolving;
using Penumbra.Interop.Structs;
@ -61,13 +62,15 @@ public class DebugTab : Window, ITab
private readonly ModImportManager _modImporter;
private readonly ImportPopup _importPopup;
private readonly FrameworkManager _framework;
private readonly TextureManager _textureManager;
public DebugTab(StartTracker timer, PerformanceTracker performance, Configuration config, CollectionManager collectionManager,
ValidityChecker validityChecker, ModManager modManager, HttpApi httpApi, ActorService actorService,
DalamudServices dalamud, StainService stains, CharacterUtility characterUtility, ResidentResourceManager residentResources,
ResourceManagerService resourceManager, PenumbraIpcProviders ipc, CollectionResolver collectionResolver,
DrawObjectState drawObjectState, PathState pathState, SubfileHelper subfileHelper, IdentifiedCollectionCache identifiedCollectionCache,
CutsceneService cutsceneService, ModImportManager modImporter, ImportPopup importPopup, FrameworkManager framework)
CutsceneService cutsceneService, ModImportManager modImporter, ImportPopup importPopup, FrameworkManager framework,
TextureManager textureManager)
: base("Penumbra Debug Window", ImGuiWindowFlags.NoCollapse, false)
{
IsOpen = true;
@ -99,6 +102,7 @@ public class DebugTab : Window, ITab
_modImporter = modImporter;
_importPopup = importPopup;
_framework = framework;
_textureManager = textureManager;
}
public ReadOnlySpan<byte> Label
@ -147,14 +151,15 @@ public class DebugTab : Window, ITab
private void DrawCollectionCaches()
{
if (!ImGui.CollapsingHeader($"Collections ({_collectionManager.Caches.Count}/{_collectionManager.Storage.Count - 1} Caches)###Collections"))
if (!ImGui.CollapsingHeader(
$"Collections ({_collectionManager.Caches.Count}/{_collectionManager.Storage.Count - 1} Caches)###Collections"))
return;
foreach (var collection in _collectionManager.Storage)
{
if (collection.HasCache)
{
using var color = ImRaii.PushColor(ImGuiCol.Text, ColorId.FolderExpanded.Value());
using var color = PushColor(ImGuiCol.Text, ColorId.FolderExpanded.Value());
using var node = TreeNode($"{collection.AnonymizedName} (Change Counter {collection.ChangeCounter})");
if (!node)
continue;
@ -177,8 +182,9 @@ public class DebugTab : Window, ITab
}
else
{
using var color = ImRaii.PushColor(ImGuiCol.Text, ColorId.UndefinedMod.Value());
TreeNode($"{collection.AnonymizedName} (Change Counter {collection.ChangeCounter})", ImGuiTreeNodeFlags.Bullet | ImGuiTreeNodeFlags.Leaf).Dispose();
using var color = PushColor(ImGuiCol.Text, ColorId.UndefinedMod.Value());
TreeNode($"{collection.AnonymizedName} (Change Counter {collection.ChangeCounter})",
ImGuiTreeNodeFlags.Bullet | ImGuiTreeNodeFlags.Leaf).Dispose();
}
}
}
@ -293,6 +299,20 @@ public class DebugTab : Window, ITab
}
}
}
using (var tree = TreeNode($"Texture Manager {_textureManager.Tasks.Count}###Texture Manager"))
{
if (tree)
{
using var table = Table("##Tasks", 2, ImGuiTableFlags.RowBg);
if (table)
foreach (var task in _textureManager.Tasks)
{
ImGuiUtil.DrawTableColumn(task.Key.ToString()!);
ImGuiUtil.DrawTableColumn(task.Value.Item1.Status.ToString());
}
}
}
}
private void DrawPerformanceTab()
@ -500,7 +520,7 @@ public class DebugTab : Window, ITab
if (agent->Data != null)
{
using var table = Table("###PBannerTable", 2, ImGuiTableFlags.SizingFixedFit);
using var table = Table("###PBannerTable", 2, ImGuiTableFlags.SizingFixedFit);
if (table)
for (var i = 0; i < 8; ++i)
{