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:
parent
3971997689
commit
749e8ceeb1
225 changed files with 29107 additions and 3914 deletions
|
|
@ -338,6 +338,58 @@ public sealed class ParticleHookSinkTests
|
|||
Assert.Equal(1, deathNotices);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LogicalTeardown_AttemptsEveryEmitterWhenDeathSubscriberThrows()
|
||||
{
|
||||
const uint emitterId = 0x3200005Bu;
|
||||
var (system, sink, _) = Harness(emitterId);
|
||||
sink.OnHook(Owner, Vector3.Zero, Create(emitterId, logicalId: 31u));
|
||||
sink.OnHook(Owner, Vector3.Zero, Create(emitterId, logicalId: 32u));
|
||||
int deathAttempts = 0;
|
||||
system.EmitterDied += _ =>
|
||||
{
|
||||
deathAttempts++;
|
||||
throw new InvalidOperationException("observer failed after emitter removal");
|
||||
};
|
||||
|
||||
AggregateException error = Assert.Throws<AggregateException>(
|
||||
() => sink.StopAllForEntity(Owner, fadeOut: false));
|
||||
|
||||
Assert.Equal(2, error.InnerExceptions.Count);
|
||||
Assert.Equal(2, deathAttempts);
|
||||
Assert.Equal(0, system.ActiveEmitterCount);
|
||||
Assert.Equal(0, sink.ActiveBindingCount);
|
||||
Assert.Equal(0, sink.LogicalEmitterCount);
|
||||
Assert.Equal(0, sink.TrackedOwnerCount);
|
||||
|
||||
// Every physical stop committed despite observer failures, so a retry
|
||||
// is a clean no-op rather than replaying dead handles.
|
||||
sink.StopAllForEntity(Owner, fadeOut: false);
|
||||
Assert.Equal(2, deathAttempts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LogicalTeardown_DeathCallbackCannotResurrectSameOwnerEmitter()
|
||||
{
|
||||
const uint emitterId = 0x3200005Cu;
|
||||
var (system, sink, _) = Harness(emitterId);
|
||||
sink.OnHook(Owner, Vector3.Zero, Create(emitterId, logicalId: 41u));
|
||||
int resurrectionAttempts = 0;
|
||||
system.EmitterDied += _ =>
|
||||
{
|
||||
resurrectionAttempts++;
|
||||
sink.OnHook(Owner, Vector3.Zero, Create(emitterId, logicalId: 42u));
|
||||
};
|
||||
|
||||
sink.StopAllForEntity(Owner, fadeOut: false);
|
||||
|
||||
Assert.Equal(1, resurrectionAttempts);
|
||||
Assert.Equal(0, system.ActiveEmitterCount);
|
||||
Assert.Equal(0, sink.ActiveBindingCount);
|
||||
Assert.Equal(0, sink.LogicalEmitterCount);
|
||||
Assert.Equal(0, sink.TrackedOwnerCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExaminationObjectPolicyAppliesToExistingAndFutureEmittersAndTearsDown()
|
||||
{
|
||||
|
|
@ -362,17 +414,115 @@ public sealed class ParticleHookSinkTests
|
|||
Assert.Equal(0, sink.ExaminationOwnerCount);
|
||||
}
|
||||
|
||||
private sealed class MutablePoseSource : IEntityEffectPoseSource
|
||||
[Fact]
|
||||
public void PoseChangeWorkset_RefreshesOnlyChangedOwnersAndVisibilityEdges()
|
||||
{
|
||||
const uint emitterId = 0x32000059u;
|
||||
const int ownerCount = 2_000;
|
||||
var registry = new EmitterDescRegistry();
|
||||
registry.Register(MakeDesc(emitterId, attachLocal: true));
|
||||
var system = new ParticleSystem(registry, new Random(42));
|
||||
var poses = new MutablePoseSource();
|
||||
var sink = new ParticleHookSink(system, poses);
|
||||
|
||||
for (uint owner = 1; owner <= ownerCount; owner++)
|
||||
{
|
||||
poses.Publish(owner, Matrix4x4.Identity, Matrix4x4.Identity);
|
||||
sink.OnHook(owner, Vector3.Zero, Create(emitterId, logicalId: 0));
|
||||
}
|
||||
|
||||
// Spawn resolves the current pose directly; unchanged static owners
|
||||
// create no recurring frame work.
|
||||
sink.RefreshAttachedEmitters();
|
||||
Assert.Equal(0, sink.LastRefreshOwnerVisitCount);
|
||||
Assert.Equal(0, sink.LastRefreshBindingVisitCount);
|
||||
|
||||
poses.Publish(777u, Matrix4x4.CreateTranslation(1, 2, 3), Matrix4x4.Identity);
|
||||
poses.Publish(777u, Matrix4x4.CreateTranslation(7, 8, 9), Matrix4x4.Identity);
|
||||
sink.RefreshAttachedEmitters();
|
||||
Assert.Equal(1, sink.LastRefreshOwnerVisitCount);
|
||||
Assert.Equal(1, sink.LastRefreshBindingVisitCount);
|
||||
Assert.Equal(new Vector3(7, 8, 9),
|
||||
system.EnumerateEmitters().Single(emitter => emitter.AttachedObjectId == 777u).AnchorPos);
|
||||
|
||||
sink.RefreshAttachedEmitters();
|
||||
Assert.Equal(0, sink.LastRefreshOwnerVisitCount);
|
||||
|
||||
sink.SetEntityPresentationVisible(777u, false);
|
||||
sink.SetEntityPresentationVisible(777u, true);
|
||||
sink.RefreshAttachedEmitters();
|
||||
Assert.Equal(1, sink.LastRefreshOwnerVisitCount);
|
||||
Assert.True(system.EnumerateEmitters()
|
||||
.Single(emitter => emitter.AttachedObjectId == 777u)
|
||||
.PresentationVisible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PoseChangeRaisedDuringRefresh_IsRetainedForNextRefresh()
|
||||
{
|
||||
const uint emitterId = 0x3200005Au;
|
||||
const uint firstOwner = 1u;
|
||||
const uint secondOwner = 2u;
|
||||
var registry = new EmitterDescRegistry();
|
||||
registry.Register(MakeDesc(emitterId, attachLocal: true));
|
||||
var system = new ParticleSystem(registry, new Random(42));
|
||||
var poses = new MutablePoseSource();
|
||||
poses.Publish(firstOwner, Matrix4x4.Identity, Matrix4x4.Identity);
|
||||
poses.Publish(secondOwner, Matrix4x4.Identity, Matrix4x4.Identity);
|
||||
var sink = new ParticleHookSink(system, poses);
|
||||
sink.OnHook(firstOwner, Vector3.Zero, Create(emitterId, logicalId: 0));
|
||||
sink.OnHook(secondOwner, Vector3.Zero, Create(emitterId, logicalId: 0));
|
||||
|
||||
bool raised = false;
|
||||
poses.RootRead = owner =>
|
||||
{
|
||||
if (owner != firstOwner || raised)
|
||||
return;
|
||||
raised = true;
|
||||
poses.Publish(
|
||||
secondOwner,
|
||||
Matrix4x4.CreateTranslation(20, 0, 0),
|
||||
Matrix4x4.Identity);
|
||||
};
|
||||
poses.Publish(
|
||||
firstOwner,
|
||||
Matrix4x4.CreateTranslation(10, 0, 0),
|
||||
Matrix4x4.Identity);
|
||||
|
||||
sink.RefreshAttachedEmitters();
|
||||
Assert.Equal(1, sink.LastRefreshOwnerVisitCount);
|
||||
sink.RefreshAttachedEmitters();
|
||||
Assert.Equal(1, sink.LastRefreshOwnerVisitCount);
|
||||
Assert.Equal(new Vector3(20, 0, 0),
|
||||
system.EnumerateEmitters()
|
||||
.Single(emitter => emitter.AttachedObjectId == secondOwner)
|
||||
.AnchorPos);
|
||||
}
|
||||
|
||||
private sealed class MutablePoseSource :
|
||||
IEntityEffectPoseSource,
|
||||
IEntityEffectPoseChangeSource
|
||||
{
|
||||
private readonly Dictionary<uint, (Matrix4x4 Root, Matrix4x4[] Parts)> _poses = new();
|
||||
|
||||
public void Publish(uint id, Matrix4x4 root, params Matrix4x4[] parts) =>
|
||||
_poses[id] = (root, parts);
|
||||
public event Action<uint>? EffectPoseChanged;
|
||||
public Action<uint>? RootRead { get; set; }
|
||||
|
||||
public void Remove(uint id) => _poses.Remove(id);
|
||||
public void Publish(uint id, Matrix4x4 root, params Matrix4x4[] parts)
|
||||
{
|
||||
_poses[id] = (root, parts);
|
||||
EffectPoseChanged?.Invoke(id);
|
||||
}
|
||||
|
||||
public void Remove(uint id)
|
||||
{
|
||||
_poses.Remove(id);
|
||||
EffectPoseChanged?.Invoke(id);
|
||||
}
|
||||
|
||||
public bool TryGetRootPose(uint localEntityId, out Matrix4x4 rootWorld)
|
||||
{
|
||||
RootRead?.Invoke(localEntityId);
|
||||
if (_poses.TryGetValue(localEntityId, out var pose))
|
||||
{
|
||||
rootWorld = pose.Root;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue