perf(render): bound animation and alpha scratch residency
Complete Slice D3 by replacing the unbounded animation dictionary with a concurrent byte/count LRU and by putting the three retail alpha scratch owners behind one typed aggregate budget. Preserve immediate growth and draw order while reclaiming one-frame density spikes after sustained under-use. Close stale bounds-cache issue evidence without inventing a cache.
This commit is contained in:
parent
3e18fc2730
commit
f2644d42c2
18 changed files with 857 additions and 34 deletions
|
|
@ -7,6 +7,20 @@ public sealed class ResidencyManagerTests
|
|||
private sealed class MeshAsset;
|
||||
private sealed class TextureAsset;
|
||||
|
||||
[Fact]
|
||||
public void ScratchBytesAreCommittedCpuResidence()
|
||||
{
|
||||
var charges = new ResidencyCharges(
|
||||
LogicalBytes: 1,
|
||||
CpuPreparedBytes: 2,
|
||||
DecodedBytes: 3,
|
||||
ScratchBytes: 4,
|
||||
StagingBytes: 5);
|
||||
|
||||
Assert.Equal(15, charges.CommittedCpuBytes);
|
||||
charges.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandlesAndOwnersReserveZeroAsInvalid()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
using AcDream.App.Rendering.Residency;
|
||||
|
||||
namespace AcDream.App.Tests.Rendering.Residency;
|
||||
|
||||
public sealed class RetainedScratchCapacityPolicyTests
|
||||
{
|
||||
[Fact]
|
||||
public void AlphaBudgetProfilePartitionsTheAggregateExactly()
|
||||
{
|
||||
AlphaScratchBudgetProfile profile =
|
||||
AlphaScratchBudgetProfile.Create(16 * 1024 * 1024);
|
||||
|
||||
Assert.Equal(4 * 1024 * 1024, profile.QueueBytes);
|
||||
Assert.Equal(8 * 1024 * 1024, profile.DispatcherBytes);
|
||||
Assert.Equal(4 * 1024 * 1024, profile.ParticleBytes);
|
||||
Assert.Equal(16 * 1024 * 1024, profile.TotalBytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SpikeRetainsWarmCapacityUntilDemandFallsThenConverges()
|
||||
{
|
||||
var policy = new RetainedScratchCapacityPolicy(
|
||||
budgetBytes: 1024,
|
||||
lowDemandSamplesBeforeShrink: 3);
|
||||
|
||||
Assert.Equal(
|
||||
4096,
|
||||
policy.ObserveAndSelectCapacity(
|
||||
currentCapacity: 4096,
|
||||
requiredCapacity: 4096,
|
||||
bytesPerUnit: 4,
|
||||
minimumCapacity: 64,
|
||||
growthQuantum: 64));
|
||||
Assert.Equal(4096, ObserveLowDemand(policy));
|
||||
Assert.Equal(4096, ObserveLowDemand(policy));
|
||||
|
||||
int converged = ObserveLowDemand(policy);
|
||||
|
||||
Assert.InRange(converged, 64, 256);
|
||||
Assert.True((long)converged * 4 <= 1024);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SustainedLegitimateDemandIsNeverTrimmedBelowRequirement()
|
||||
{
|
||||
var policy = new RetainedScratchCapacityPolicy(
|
||||
budgetBytes: 1024,
|
||||
lowDemandSamplesBeforeShrink: 2);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Assert.Equal(
|
||||
4096,
|
||||
policy.ObserveAndSelectCapacity(
|
||||
currentCapacity: 4096,
|
||||
requiredCapacity: 4096,
|
||||
bytesPerUnit: 4,
|
||||
minimumCapacity: 64,
|
||||
growthQuantum: 64));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequiredGrowthIsImmediateAndQuantumRounded()
|
||||
{
|
||||
var policy = new RetainedScratchCapacityPolicy(1024);
|
||||
|
||||
Assert.Equal(
|
||||
320,
|
||||
policy.ObserveAndSelectCapacity(
|
||||
currentCapacity: 64,
|
||||
requiredCapacity: 257,
|
||||
bytesPerUnit: 4,
|
||||
minimumCapacity: 64,
|
||||
growthQuantum: 64));
|
||||
}
|
||||
|
||||
private static int ObserveLowDemand(
|
||||
RetainedScratchCapacityPolicy policy) =>
|
||||
policy.ObserveAndSelectCapacity(
|
||||
currentCapacity: 4096,
|
||||
requiredCapacity: 32,
|
||||
bytesPerUnit: 4,
|
||||
minimumCapacity: 64,
|
||||
growthQuantum: 64);
|
||||
}
|
||||
|
|
@ -157,6 +157,31 @@ public sealed class RetailAlphaQueueTests
|
|||
Assert.Equal(expected, source.PreparedTokens);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetainedScratchConvergesAfterAOneScopeSpike()
|
||||
{
|
||||
const int budgetBytes = 128 * 1024;
|
||||
var log = new List<string>();
|
||||
var source = new RecordingSource("alpha", log);
|
||||
var queue = new RetailAlphaQueue(budgetBytes);
|
||||
|
||||
queue.BeginFrame();
|
||||
for (int i = 0; i < 8_192; i++)
|
||||
queue.Submit(source, i, i);
|
||||
queue.EndFrame();
|
||||
Assert.True(queue.RetainedScratchBytes > budgetBytes);
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
queue.BeginFrame();
|
||||
queue.EndFrame();
|
||||
}
|
||||
|
||||
Assert.True(queue.RetainedScratchBytes <= budgetBytes);
|
||||
Assert.False(queue.IsCollecting);
|
||||
Assert.Equal(0, queue.PendingCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Flush_EqualDistanceOrderStartsFreshInEachFrameScope()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue