fix(rendering): bound portal resource lifetime

Separate logical ownership, render publication, and GPU retirement across live entities, landblocks, particles, textures, mesh arenas, portal/UI teardown, and per-frame scratch storage. Add bounded DAT/texture caches, upload budgets, three-frame fence retirement, exact-incarnation appearance reconciliation, frame pacing, and extensive lifetime conformance coverage.\n\nThe seven-destination connected route now cuts peak working/private memory roughly in half, returns Caul to 125-153 FPS locally, and produces no WER or AMD reset.\n\nCo-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-18 21:35:16 +02:00
parent 3971997689
commit 749e8ceeb1
225 changed files with 29107 additions and 3914 deletions

View file

@ -6,6 +6,7 @@ using AcDream.Core.Combat;
using AcDream.Core.Items;
using AcDream.UI.Abstractions.Panels.Settings;
using DatReaderWriter;
using AcDream.Content;
namespace AcDream.App.Studio;
@ -51,7 +52,7 @@ public static class FixtureProvider
ImportedLayout layout,
RenderStack stack,
ClientObjectTable objects,
DatCollection dats)
IDatReaderWriter dats)
{
switch (layoutId)
{

View file

@ -1,6 +1,7 @@
using AcDream.App.UI;
using AcDream.App.UI.Layout;
using DatReaderWriter;
using AcDream.Content;
namespace AcDream.App.Studio;
@ -18,7 +19,7 @@ public enum LayoutSourceKind { DatLayout, Markup }
/// </summary>
public sealed class LayoutSource
{
private readonly DatCollection _dats;
private readonly IDatReaderWriter _dats;
private readonly Func<uint, (uint, int, int)> _resolve;
private readonly UiDatFont? _datFont;
private readonly Func<uint, UiDatFont?>? _fontResolve;
@ -41,7 +42,7 @@ public sealed class LayoutSource
/// Pass null (default) for the original single-font behavior — the live
/// <see cref="GameWindow"/> path passes null so it is provably unchanged.</param>
public LayoutSource(
DatCollection dats,
IDatReaderWriter dats,
Func<uint, (uint, int, int)> resolve,
UiDatFont? datFont,
Func<uint, UiDatFont?>? fontResolve = null)

View file

@ -5,6 +5,7 @@ using AcDream.Core.Chat;
using AcDream.UI.Abstractions;
using AcDream.UI.Abstractions.Panels.Chat;
using DatReaderWriter;
using AcDream.Content;
using System.Numerics;
namespace AcDream.App.Studio;
@ -17,7 +18,7 @@ namespace AcDream.App.Studio;
/// </summary>
internal static class MockupDesktop
{
public static void Load(DatCollection dats, RenderStack stack)
public static void Load(IDatReaderWriter dats, RenderStack stack)
{
var objects = SampleData.BuildObjectTable();
var windows = new List<MockupWindow>();
@ -36,11 +37,11 @@ internal static class MockupDesktop
MountControls(stack, windows);
}
private static ImportedLayout? Import(DatCollection dats, uint layoutId, RenderStack stack)
private static ImportedLayout? Import(IDatReaderWriter dats, uint layoutId, RenderStack stack)
=> LayoutImporter.Import(dats, layoutId, stack.ResolveChrome, stack.VitalsDatFont,
fontResolve: stack.ResolveDatFont);
private static RetailWindowHandle? MountVitals(DatCollection dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
private static RetailWindowHandle? MountVitals(IDatReaderWriter dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
{
var layout = Import(dats, 0x2100006Cu, stack);
if (layout is null) return null;
@ -66,7 +67,7 @@ internal static class MockupDesktop
});
}
private static RetailWindowHandle? MountToolbar(DatCollection dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
private static RetailWindowHandle? MountToolbar(IDatReaderWriter dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
{
var layout = Import(dats, 0x21000016u, stack);
if (layout is null) return null;
@ -136,7 +137,7 @@ internal static class MockupDesktop
frame.MaxHeight = expandedH;
}
private static RetailWindowHandle? MountCharacter(DatCollection dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
private static RetailWindowHandle? MountCharacter(IDatReaderWriter dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
{
var layout = Import(dats, 0x2100002Eu, stack);
if (layout is null) return null;
@ -164,7 +165,7 @@ internal static class MockupDesktop
});
}
private static RetailWindowHandle? MountInventory(DatCollection dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
private static RetailWindowHandle? MountInventory(IDatReaderWriter dats, RenderStack stack, AcDream.Core.Items.ClientObjectTable objects)
{
var layout = Import(dats, 0x21000023u, stack);
if (layout is null) return null;
@ -219,7 +220,7 @@ internal static class MockupDesktop
element.Anchors = AnchorEdges.Left | AnchorEdges.Top;
}
private static RetailWindowHandle? MountChat(DatCollection dats, RenderStack stack)
private static RetailWindowHandle? MountChat(IDatReaderWriter dats, RenderStack stack)
{
var rootInfo = LayoutImporter.ImportInfos(dats, ChatWindowController.LayoutId);
if (rootInfo is null) return null;

View file

@ -1,8 +1,8 @@
using System.Numerics;
using AcDream.Content;
using AcDream.App.Rendering;
using AcDream.App.UI;
using DatReaderWriter;
using DatReaderWriter.Options;
using Silk.NET.Input;
using Silk.NET.Maths;
using Silk.NET.OpenGL;
@ -39,7 +39,7 @@ public sealed class StudioWindow : IDisposable
// Created in OnLoad, released in OnClosing.
private IWindow? _window;
private DatCollection? _dats;
private IDatReaderWriter? _dats;
private RenderStack? _stack;
private LayoutSource? _source;
@ -113,7 +113,7 @@ public sealed class StudioWindow : IDisposable
{
var gl = GL.GetApi(_window!);
_dats = new DatCollection(_opts.DatDir, DatAccessType.Read);
_dats = RuntimeDatCollectionFactory.OpenReadOnly(_opts.DatDir);
// Build QualitySettings for RenderBootstrap (same as Run() above — re-read
// after the GL context is confirmed, mirroring GameWindow.OnLoad).
@ -218,6 +218,10 @@ public sealed class StudioWindow : IDisposable
private void OnRender(double dt)
{
if (_stack is null || _panelFbo is null) return;
_stack.BeginFrame();
Exception? renderFailure = null;
try
{
// ── HEADLESS SCREENSHOT PATH ──────────────────────────────────────────────
if (_opts.ScreenshotPath is not null)
@ -415,6 +419,26 @@ public sealed class StudioWindow : IDisposable
// 9. Finalise ImGui and flush draw data to the window.
_imgui.Render();
}
catch (Exception ex)
{
renderFailure = ex;
throw;
}
finally
{
try
{
_stack.EndFrame();
}
catch (Exception closeFailure) when (renderFailure is not null)
{
throw new AggregateException(
"UI Studio rendering failed and its GPU frame could not be closed.",
renderFailure,
closeFailure);
}
}
}
/// <summary>