perf(streaming): reserve destination reveal capacity

Join destination scheduling to the canonical reveal generation, protect its share across every typed frame-budget dimension, and prevent stale work from clearing a replacement reservation. Remove forced incomplete materialization and project retail's centered portal wait cue while the authored tunnel remains active.

Tests: Release build clean; 91 focused reservation/reveal tests; full solution 8,158 passed, 5 skipped.

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Erik 2026-07-24 19:39:23 +02:00
parent 98f1ac8934
commit 2ff8f844b0
33 changed files with 870 additions and 230 deletions

View file

@ -18,7 +18,7 @@ public class StreamingControllerPriorityApplyTests
generation);
[Fact]
public void PriorityLandblock_WinsExecutionOrderAfterBoundedAdmission()
public void DestinationReservation_WinsExecutionOrderAfterBoundedAdmission()
{
uint priority = StreamingRegion.EncodeLandblockIdForTest(169, 180);
var outbox = new Queue<LandblockStreamResult>(new LandblockStreamResult[]
@ -48,7 +48,7 @@ public class StreamingControllerPriorityApplyTests
workBudgetOptions: GenerousBudget())
{ MaxCompletionsPerFrame = 4 };
ctrl.PriorityLandblockId = priority;
ctrl.BeginDestinationReservation(1, priority, 0);
ctrl.Tick(169, 180);
Assert.NotEmpty(applied);
@ -87,10 +87,10 @@ public class StreamingControllerPriorityApplyTests
nearRadius: 4,
farRadius: 12)
{ MaxCompletionsPerFrame = 4 };
ctrl.PriorityLandblockId = priority;
ctrl.BeginDestinationReservation(1, priority, 0);
ctrl.Tick(169, 180); // priority + some others
ctrl.PriorityLandblockId = 0u;
ctrl.EndDestinationReservation(1);
ctrl.Tick(169, 180); // drains the deferred remainder
ctrl.Tick(169, 180);
@ -101,7 +101,7 @@ public class StreamingControllerPriorityApplyTests
[Fact]
public void PriorityNeverArrives_noThrow_noLoss_noDoubleApply()
{
// While a PriorityLandblockId is set but the matching completion never
// While a reveal reservation is active but its matching completion never
// arrives (e.g. the load failed), ordinary results still enter the typed
// Near/Far queues and advance under the same budget without loss.
uint priority = StreamingRegion.EncodeLandblockIdForTest(169, 180);
@ -134,7 +134,7 @@ public class StreamingControllerPriorityApplyTests
{ MaxCompletionsPerFrame = 4 };
// Set a priority id that will NEVER appear in the outbox.
ctrl.PriorityLandblockId = priority;
ctrl.BeginDestinationReservation(1, priority, 0);
// Tick several times — should not throw and every non-priority completion
// must still be applied without duplication.
@ -160,6 +160,30 @@ public class StreamingControllerPriorityApplyTests
MaxGlRetireOperations: 10_000,
DestinationReserveFraction: 0.75f);
[Fact]
public void DestinationReservation_StaleGenerationCannotClearReplacement()
{
var controller = new StreamingController(
enqueueLoad: (_, _) => { },
enqueueUnload: _ => { },
drainCompletions: _ => Array.Empty<LandblockStreamResult>(),
applyTerrain: (_, _) => { },
state: new GpuWorldState(),
nearRadius: 1,
farRadius: 2);
controller.BeginDestinationReservation(1, 0x11340021u, 1);
controller.BeginDestinationReservation(2, 0x20210123u, 0);
controller.EndDestinationReservation(1);
Assert.Equal(2, controller.ActiveRevealGeneration);
Assert.Equal(0x2021FFFFu, controller.DestinationLandblockId);
Assert.Equal(0, controller.DestinationRadius);
controller.EndDestinationReservation(2);
Assert.Equal(0, controller.ActiveRevealGeneration);
}
[Fact]
public void DeferredCompaction_ApplyFailureRetainsExactResultWithoutReplayingCommittedPrefix()
{
@ -199,8 +223,8 @@ public class StreamingControllerPriorityApplyTests
farRadius: 12)
{
MaxCompletionsPerFrame = 3,
PriorityLandblockId = priority,
};
ctrl.BeginDestinationReservation(1, priority, 0);
Assert.Throws<InvalidOperationException>(() => ctrl.Tick(169, 180));
Assert.Equal([first], applied);
@ -215,7 +239,6 @@ public class StreamingControllerPriorityApplyTests
[Fact]
public void ForceReloadWindow_DiscardsBufferedCompletionsFromOldWindow()
{
uint priority = StreamingRegion.EncodeLandblockIdForTest(169, 180);
var outbox = new Queue<LandblockStreamResult>(
Enumerable.Range(0, 6)
.Select(i => (LandblockStreamResult)LoadedOf(
@ -243,8 +266,7 @@ public class StreamingControllerPriorityApplyTests
MaxGpuUploadBytes: 1_000_000,
MaxGlRetireOperations: 1_000,
DestinationReserveFraction: 0.75f))
{ MaxCompletionsPerFrame = 4, PriorityLandblockId = priority };
{ MaxCompletionsPerFrame = 4 };
ctrl.Tick(169, 180);
Assert.Equal(4, applied.Count);
applied.Clear();
@ -452,7 +474,8 @@ public class StreamingControllerPriorityApplyTests
state: state,
nearRadius: 0,
farRadius: 0,
onLandblockLoaded: loadedCallbacks.Add);
onLandblockLoaded: loadedCallbacks.Add,
workBudgetOptions: GenerousBudget());
ctrl.Tick(10, 10);