wip(assembler): round S14 -- 4-way column cache + memoized MC gradients (output unchanged)

Worker-local XY column cache uses deterministic 4-way sets at LOD3-8: LOD4
misses 8,224 -> 1,437, conflicts 7,407 -> 0 (direct-map control: 6.62 s /
43.5 worker-s vs 4.24 s / 21.7). Exact LOD0 lattice gradients memoized per
tile: MC-exclusive 242 -> 201 ns/sample, two-pass loop unchanged. Hashes
identical, no recipe bump. Primary cold trace 4.24 s full set, ring 0.45 s,
75/75 at 40 m/s; a repeat ran uniformly ~40% slower on every LOD (machine
contention suspected); tick p95 to re-check on an idle machine. CVars
voxel.CoreColumnCacheDirectMapped / voxel.CoreMCGradientMemoization.
Report: Standalone/Research/WorldAssemblerM3/Round18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MmSoF64BbRFmk9C3p1VsBJ
This commit is contained in:
Fr0zkaandClaude Opus 5.5 committed 2026-10-19 17:58:54 +02:00
1 parent bd5e38594f
commit ec2afe9c93
11 files changed
+769 -50

No files matched your search

+37 -3
View File
@@ -235,6 +235,18 @@ namespace
GVoxelForgeStreamingBackgroundWorkerCap,
TEXT("Size tile admission slots to the TaskGraph background workers used by tile tasks; 0 restores the logical-core cap."));
int32 GVoxelForgeCoreColumnCacheDirectMapped = 0;
FAutoConsoleVariableRef CVarVoxelForgeCoreColumnCacheDirectMapped(
TEXT("voxel.CoreColumnCacheDirectMapped"),
GVoxelForgeCoreColumnCacheDirectMapped,
TEXT("Negative control: 0 uses the four-way deterministic XY column cache; 1 restores S13 direct-map indexing."));
int32 GVoxelForgeCoreMCGradientMemoization = 1;
FAutoConsoleVariableRef CVarVoxelForgeCoreMCGradientMemoization(
TEXT("voxel.CoreMCGradientMemoization"),
GVoxelForgeCoreMCGradientMemoization,
TEXT("Negative control: 1 reuses exact LOD0 lattice gradients across adjacent MC cells; 0 restores per-cell gradient probes."));
int32 GVoxelForgeProfileTileGeneration = 0;
FAutoConsoleVariableRef CVarVoxelForgeProfileTileGeneration(
TEXT("voxel.ProfileTileGeneration"),
@@ -2080,6 +2092,8 @@ void AVoxelWorld::BeginPlay()
int32 CommandLineStreamingResultBacklogCap = GVoxelForgeStreamingResultBacklogCap;
int32 CommandLineStreamingReadyQueueDepth = GVoxelForgeStreamingReadyQueueDepth;
int32 CommandLineStreamingBackgroundWorkerCap = GVoxelForgeStreamingBackgroundWorkerCap;
int32 CommandLineCoreColumnCacheDirectMapped = GVoxelForgeCoreColumnCacheDirectMapped;
int32 CommandLineCoreMCGradientMemoization = GVoxelForgeCoreMCGradientMemoization;
int32 CommandLineStep1GenerationCap = GVoxelForgeStep1GenerationCap;
int32 CommandLineStep1ExitAfterFrames = GVoxelForgeStep1ExitAfterFrames;
int32 CommandLineStep1CsvCaptureOnBeginPlay = GVoxelForgeStep1CsvCaptureOnBeginPlay;
@@ -2186,6 +2200,18 @@ void AVoxelWorld::BeginPlay()
GVoxelForgeStreamingBackgroundWorkerCap =
CommandLineStreamingBackgroundWorkerCap != 0 ? 1 : 0;
}
if (FParse::Value(FCommandLine::Get(), TEXT("voxel.CoreColumnCacheDirectMapped="),
CommandLineCoreColumnCacheDirectMapped))
{
GVoxelForgeCoreColumnCacheDirectMapped=
CommandLineCoreColumnCacheDirectMapped!=0?1:0;
}
if (FParse::Value(FCommandLine::Get(), TEXT("voxel.CoreMCGradientMemoization="),
CommandLineCoreMCGradientMemoization))
{
GVoxelForgeCoreMCGradientMemoization=
CommandLineCoreMCGradientMemoization!=0?1:0;
}
if (FParse::Value(FCommandLine::Get(), TEXT("voxel.Step1PrequeueVisibleLOD0="),
CommandLineStep1PrequeueVisibleLOD0))
{
@@ -2609,7 +2635,9 @@ void AVoxelWorld::BeginPlay()
"\"streaming_legacy_pending_result_cap\":%d,"
"\"streaming_collision_lookahead\":%d,\"core_region_concurrent_admission\":%d,"
"\"collision_gate\":%d,"
"\"streaming_result_backlog_cap\":%d,\"streaming_startup_apply_boost\":%d"),
"\"streaming_result_backlog_cap\":%d,\"streaming_startup_apply_boost\":%d,"
"\"core_column_cache_direct_mapped\":%d,"
"\"core_mc_gradient_memoization\":%d"),
FPlatformMisc::NumberOfCoresIncludingHyperthreads(), GetMaxConcurrentStreamingTasks(),
TaskScheduler.GetNumWorkers(), TaskScheduler.GetMaxNumWorkers(),
static_cast<int32>(TaskScheduler.GetWorkerPriority()),
@@ -2622,7 +2650,9 @@ void AVoxelWorld::BeginPlay()
GVoxelForgeStreamingLegacyPendingResultCap,
GVoxelForgeStreamingCollisionLookahead, GVoxelForgeCoreRegionConcurrentAdmission,
GVoxelForgeCollisionGate,
GVoxelForgeStreamingResultBacklogCap, GVoxelForgeStreamingStartupApplyBoost));
GVoxelForgeStreamingResultBacklogCap, GVoxelForgeStreamingStartupApplyBoost,
GVoxelForgeCoreColumnCacheDirectMapped,
GVoxelForgeCoreMCGradientMemoization));
VoxelForgeStartupTrace::RecordEvent(TEXT("streaming_worker_cap_readback"), FString::Printf(
TEXT("\"streaming_background_worker_cap\":%d,\"background_worker_threads\":%d,"
"\"effective_tile_slots\":%d"),
@@ -13043,13 +13073,15 @@ void AVoxelWorld::LoadCoreTile(const FVoxelTileKey& Tile, EVoxelTileWorkPriority
VoxelForgeStartupTrace::RecordRequest(RequestSample, TaskEpoch);
}
const bool bCaptureHashes = bCaptureVoxelForgeCoreHashesForValidation;
const bool bLegacyDirectMappedColumnCache=GVoxelForgeCoreColumnCacheDirectMapped!=0;
const bool bMemoizeCoreMCGradients=GVoxelForgeCoreMCGradientMemoization!=0;
const UE::Tasks::ETaskPriority TaskPriority = bNearPriority
? UE::Tasks::ETaskPriority::BackgroundHigh
: UE::Tasks::ETaskPriority::BackgroundNormal;
UE::Tasks::Launch(TEXT("VoxelForgeCoreTile"),
[this, State, Cancellation, Tile, WorkPriority, TaskEpoch, TaskDesiredEpoch,
TaskModificationEpoch, RequestStartCycles, RequestOrdinal, bResidentAtRequest,
bCaptureHashes]()
bCaptureHashes,bLegacyDirectMappedColumnCache,bMemoizeCoreMCGradients]()
{
struct FTaskGuard
{
@@ -13153,6 +13185,8 @@ void AVoxelWorld::LoadCoreTile(const FVoxelTileKey& Tile, EVoxelTileWorkPriority
break;
}
Options.hashDensity = bCaptureHashes;
Options.legacyDirectMappedColumnCache=bLegacyDirectMappedColumnCache;
Options.memoizeMcGradients=bMemoizeCoreMCGradients;
std::string CoreError;
std::optional<VoxelForgeCore::TileMesh> CoreMesh;
{
@@ -16204,10 +16204,10 @@ bool RunCoreSharedFeatureCostAudit(VoxelForgeCore::World& World,
}
VoxelForgeCore::Heightfield2D::resetThreadColumnCacheStats(false,true,0);
}
for (const int32 LOD : {0,1,3,4,5,8})
for (const int32 LOD : {0,1,2,3,4,5,6,7,8})
{
TArray<double> FullTimes,CandidateTimes,FullShellTimes,CandidateShellTimes,ListTimes;
TArray<double> UnknownBoxes,FieldCalls,ColumnMisses,StratumShellTimes,ConnectorShellTimes;
TArray<double> UnknownBoxes,FieldCalls,UnclampedFieldCalls,ColumnMisses,ColumnConflictMisses,StratumShellTimes,ConnectorShellTimes;
TArray<double> DensitySamples,ClassificationTimes,ClassificationExclusiveTimes;
TArray<double> ColumnComputeTimes,MeshingTimes,HorizonTimes,RepairSkipped;
TArray<double> ColumnEvalExclusiveTimes,MarchingExclusiveTimes,GroundRefineExclusiveTimes;
@@ -16216,13 +16216,29 @@ bool RunCoreSharedFeatureCostAudit(VoxelForgeCore::World& World,
TArray<double> ClassificationNsPerSample,ColumnNsPerSample,MarchingNsPerSample;
TArray<double> GroundNsPerSample,CapNsPerSample,AssemblyNsPerSample,ListNsPerSample;
TArray<double> MarchingColumnNsPerSample,GroundColumnNsPerSample,CapColumnNsPerSample;
TArray<double> McProfileTotalTimes,McProfileGridTimes,McProfileGridExclusiveTimes;
TArray<double> McProfileCellTimes,McProfileNormalTimes,McProfileInterpolationTimes;
TArray<double> McProfileStreamTimes,McProfileOtherTimes,McProfileResidualTimes;
TArray<double> McProfileGradientFallbackCalls,McProfileEdgeMidpointCalls,McProfileGradientMemoHits;
TArray<double> McProfileGridNsPerSample,McProfileGridExclusiveNsPerSample;
TArray<double> McProfileCellNsPerSample,McProfileNormalNsPerSample;
TArray<double> McProfileInterpolationNsPerSample,McProfileStreamNsPerSample;
TArray<double> McProfileOtherNsPerSample,McProfileResidualNsPerSample;
TArray<double> StratumFieldCalls,ConnectorFieldCalls,ShellTriangles,GroundTriangles,GroundRemoved,CapTriangles;
const bool bMcStageAudit=FParse::Param(FCommandLine::Get(),TEXT("coremcstageaudit"));
int32 AuditDirectMappedColumnCache=0,AuditMemoizeMcGradients=1;
FParse::Value(FCommandLine::Get(),TEXT("voxel.CoreColumnCacheDirectMapped="),
AuditDirectMappedColumnCache);
FParse::Value(FCommandLine::Get(),TEXT("voxel.CoreMCGradientMemoization="),
AuditMemoizeMcGradients);
for (const auto& Key : Keys)
{
if (Key.lod!=LOD || FullTimes.Num()>=8) continue;
VoxelForgeCore::TileGenerationOptions Options;
Options.hashDensity=true;
Options.useAssemblyFeatureQueries=false;
Options.legacyDirectMappedColumnCache=AuditDirectMappedColumnCache!=0;
Options.memoizeMcGradients=AuditMemoizeMcGradients!=0;
std::string Error;
// Check density and mesh parity with hashes, then time uncached runtime generation.
// Verifier la parite avec hashes, puis mesurer la generation sans cache de colonnes.
@@ -16256,7 +16272,9 @@ bool RunCoreSharedFeatureCostAudit(VoxelForgeCore::World& World,
DensitySamples.Add(static_cast<double>(Candidate->densitySampleCount));
UnknownBoxes.Add(static_cast<double>(Diagnostics.unknownBoxes));
FieldCalls.Add(static_cast<double>(Diagnostics.fieldCalls));
UnclampedFieldCalls.Add(static_cast<double>(Diagnostics.unclampedFieldCalls));
ColumnMisses.Add(static_cast<double>(Diagnostics.columnCacheMisses));
ColumnConflictMisses.Add(static_cast<double>(Diagnostics.columnCacheConflictMisses));
ClassificationTimes.Add(Diagnostics.classificationMilliseconds);
ClassificationExclusiveTimes.Add(Diagnostics.classificationExclusiveMilliseconds);
ColumnComputeTimes.Add(Diagnostics.columnComputeMilliseconds);
@@ -16301,13 +16319,66 @@ bool RunCoreSharedFeatureCostAudit(VoxelForgeCore::World& World,
*1000000.0/SampleCount);
ListNsPerSample.Add(Diagnostics.featureListMilliseconds*1000000.0/SampleCount);
}
if(bMcStageAudit)
{
// Profile a separate cold tile so the audit's ordinary timing rows keep the
// uninstrumented path and comparable clock scope.
// Profiler une tuile froide separee pour garder les mesures ordinaires sans instrumentation.
Options.profileMesherStages=true;
VoxelForgeCore::Heightfield2D::resetThreadColumnCacheStats(false,true);
auto Profiled=World.generateTile(Key,Options,Error);
Options.profileMesherStages=false;
if(!Profiled)
{ OutError=TEXT("Cold MC stage profile tile generation failed."); return false; }
const auto& Mc=Profiled->diagnostics;
const double Total=Mc.marchingCubesExclusiveMilliseconds
+Mc.marchingCubesColumnComputeMilliseconds;
const double Grid=Mc.marchingCubesDensityGridMilliseconds;
const double GridExclusive=FMath::Max(0.0,Grid
-Mc.marchingCubesColumnComputeMilliseconds);
const double Cell=Mc.marchingCubesCellClassificationMilliseconds;
const double Normal=Mc.marchingCubesGradientNormalsMilliseconds;
const double Interpolation=Mc.marchingCubesEdgeInterpolationMilliseconds;
const double Stream=Mc.marchingCubesVertexDedupStreamMilliseconds;
const double Other=Mc.marchingCubesOtherMilliseconds;
const double Residual=FMath::Max(0.0,Mc.marchingCubesExclusiveMilliseconds
-GridExclusive-Cell-Normal-Interpolation-Stream);
McProfileTotalTimes.Add(Total);
McProfileGridTimes.Add(Grid);
McProfileGridExclusiveTimes.Add(GridExclusive);
McProfileCellTimes.Add(Cell);
McProfileNormalTimes.Add(Normal);
McProfileInterpolationTimes.Add(Interpolation);
McProfileStreamTimes.Add(Stream);
McProfileOtherTimes.Add(Other);
McProfileResidualTimes.Add(Residual);
McProfileGradientFallbackCalls.Add(static_cast<double>(
Mc.marchingCubesGradientFallbackDensityCalls));
McProfileEdgeMidpointCalls.Add(static_cast<double>(
Mc.marchingCubesEdgeMidpointDensityCalls));
McProfileGradientMemoHits.Add(static_cast<double>(
Mc.marchingCubesGradientMemoHits));
const double ProfileSamples=static_cast<double>(Profiled->densitySampleCount);
if(ProfileSamples>0.0)
{
McProfileGridNsPerSample.Add(Grid*1000000.0/ProfileSamples);
McProfileGridExclusiveNsPerSample.Add(GridExclusive*1000000.0/ProfileSamples);
McProfileCellNsPerSample.Add(Cell*1000000.0/ProfileSamples);
McProfileNormalNsPerSample.Add(Normal*1000000.0/ProfileSamples);
McProfileInterpolationNsPerSample.Add(Interpolation*1000000.0/ProfileSamples);
McProfileStreamNsPerSample.Add(Stream*1000000.0/ProfileSamples);
McProfileOtherNsPerSample.Add(Other*1000000.0/ProfileSamples);
McProfileResidualNsPerSample.Add(Residual*1000000.0/ProfileSamples);
}
}
}
const auto P95=[](TArray<double> Values)
{ Values.Sort(); return Values.IsEmpty() ? 0.0 : Values[FMath::Clamp(
FMath::CeilToInt(Values.Num()*0.95f)-1,0,Values.Num()-1)]; };
UE_LOG(LogTemp,Display,
TEXT("[VoxelForgeSharedFeatureCost] label=%s lod=%d tiles=%d hashes_identical=1 full_p95_ms=%.5f candidate_p95_ms=%.5f list_p95_ms=%.5f classification_wall_p95_ms=%.5f classification_exclusive_p95_ms=%.5f column_compute_p95_ms=%.5f column_eval_exclusive_p95_ms=%.5f mc_column_compute_p95_ms=%.5f mc_exclusive_p95_ms=%.5f ground_column_compute_p95_ms=%.5f ground_refine_exclusive_p95_ms=%.5f cap_column_compute_p95_ms=%.5f cap_refine_exclusive_p95_ms=%.5f mesh_assembly_p95_ms=%.5f meshing_p95_ms=%.5f horizon_p95_ms=%.5f samples_p95=%.0f classification_ns_per_sample_p95=%.2f column_ns_per_sample_p95=%.2f mc_column_ns_per_sample_p95=%.2f mc_ns_per_sample_p95=%.2f ground_column_ns_per_sample_p95=%.2f ground_ns_per_sample_p95=%.2f cap_column_ns_per_sample_p95=%.2f cap_ns_per_sample_p95=%.2f assembly_ns_per_sample_p95=%.2f feature_list_ns_per_sample_p95=%.2f full_shell_p95_ms=%.5f candidate_shell_p95_ms=%.5f repair_skipped_p95=%.0f unknown_boxes_p95=%.0f field_calls_p95=%.0f column_misses_p95=%.0f stratum_shell_p95_ms=%.5f stratum_field_calls_p95=%.0f connector_shell_p95_ms=%.5f connector_field_calls_p95=%.0f shell_triangles_p95=%.0f horizon_ground_triangles_p95=%.0f horizon_ground_removed_p95=%.0f horizon_cap_triangles_p95=%.0f"),
Label,LOD,FullTimes.Num(),P95(FullTimes),P95(CandidateTimes),P95(ListTimes),
TEXT("[VoxelForgeSharedFeatureCost] label=%s lod=%d column_cache_direct_mapped=%d gradient_memoization=%d tiles=%d hashes_identical=1 full_p95_ms=%.5f candidate_p95_ms=%.5f list_p95_ms=%.5f classification_wall_p95_ms=%.5f classification_exclusive_p95_ms=%.5f column_compute_p95_ms=%.5f column_eval_exclusive_p95_ms=%.5f mc_column_compute_p95_ms=%.5f mc_exclusive_p95_ms=%.5f ground_column_compute_p95_ms=%.5f ground_refine_exclusive_p95_ms=%.5f cap_column_compute_p95_ms=%.5f cap_refine_exclusive_p95_ms=%.5f mesh_assembly_p95_ms=%.5f meshing_p95_ms=%.5f horizon_p95_ms=%.5f samples_p95=%.0f classification_ns_per_sample_p95=%.2f column_ns_per_sample_p95=%.2f mc_column_ns_per_sample_p95=%.2f mc_ns_per_sample_p95=%.2f ground_column_ns_per_sample_p95=%.2f ground_ns_per_sample_p95=%.2f cap_column_ns_per_sample_p95=%.2f cap_ns_per_sample_p95=%.2f assembly_ns_per_sample_p95=%.2f feature_list_ns_per_sample_p95=%.2f full_shell_p95_ms=%.5f candidate_shell_p95_ms=%.5f repair_skipped_p95=%.0f unknown_boxes_p95=%.0f field_calls_p95=%.0f unclamped_field_calls_p95=%.0f column_misses_p95=%.0f column_conflict_misses_p95=%.0f stratum_shell_p95_ms=%.5f stratum_field_calls_p95=%.0f connector_shell_p95_ms=%.5f connector_field_calls_p95=%.0f shell_triangles_p95=%.0f horizon_ground_triangles_p95=%.0f horizon_ground_removed_p95=%.0f horizon_cap_triangles_p95=%.0f"),
Label,LOD,AuditDirectMappedColumnCache!=0?1:0,AuditMemoizeMcGradients!=0?1:0,
FullTimes.Num(),P95(FullTimes),P95(CandidateTimes),P95(ListTimes),
P95(ClassificationTimes),P95(ClassificationExclusiveTimes),P95(ColumnComputeTimes),
P95(ColumnEvalExclusiveTimes),P95(MarchingColumnTimes),P95(MarchingExclusiveTimes),
P95(GroundColumnTimes),P95(GroundRefineExclusiveTimes),P95(CapColumnTimes),
@@ -16317,9 +16388,24 @@ bool RunCoreSharedFeatureCostAudit(VoxelForgeCore::World& World,
P95(MarchingNsPerSample),P95(GroundColumnNsPerSample),P95(GroundNsPerSample),
P95(CapColumnNsPerSample),P95(CapNsPerSample),P95(AssemblyNsPerSample),P95(ListNsPerSample),
P95(FullShellTimes),P95(CandidateShellTimes),P95(RepairSkipped),P95(UnknownBoxes),P95(FieldCalls),
P95(ColumnMisses),P95(StratumShellTimes),P95(StratumFieldCalls),
P95(UnclampedFieldCalls),
P95(ColumnMisses),P95(ColumnConflictMisses),P95(StratumShellTimes),P95(StratumFieldCalls),
P95(ConnectorShellTimes),P95(ConnectorFieldCalls),P95(ShellTriangles),
P95(GroundTriangles),P95(GroundRemoved),P95(CapTriangles));
if(bMcStageAudit)
{
UE_LOG(LogTemp,Display,
TEXT("[VoxelForgeMCStageCost] label=%s lod=%d tiles=%d sampling=row_total_and_1_of_8_cells total_p95_ms=%.5f density_grid_inclusive_p95_ms=%.5f density_grid_ex_column_p95_ms=%.5f cell_classification_p95_ms=%.5f gradient_normals_p95_ms=%.5f edge_interpolation_p95_ms=%.5f vertex_dedup_stream_p95_ms=%.5f setup_finalization_p95_ms=%.5f unassigned_residual_p95_ms=%.5f grid_ns_per_sample_p95=%.2f grid_ex_column_ns_per_sample_p95=%.2f cell_ns_per_sample_p95=%.2f normals_ns_per_sample_p95=%.2f interpolation_ns_per_sample_p95=%.2f dedup_stream_ns_per_sample_p95=%.2f setup_finalization_ns_per_sample_p95=%.2f residual_ns_per_sample_p95=%.2f gradient_fallback_density_calls_p95=%.0f edge_midpoint_density_probes_p95=%.0f gradient_memo_hits_p95=%.0f"),
Label,LOD,McProfileTotalTimes.Num(),P95(McProfileTotalTimes),P95(McProfileGridTimes),
P95(McProfileGridExclusiveTimes),P95(McProfileCellTimes),P95(McProfileNormalTimes),
P95(McProfileInterpolationTimes),P95(McProfileStreamTimes),P95(McProfileOtherTimes),
P95(McProfileResidualTimes),P95(McProfileGridNsPerSample),
P95(McProfileGridExclusiveNsPerSample),P95(McProfileCellNsPerSample),
P95(McProfileNormalNsPerSample),P95(McProfileInterpolationNsPerSample),
P95(McProfileStreamNsPerSample),P95(McProfileOtherNsPerSample),
P95(McProfileResidualNsPerSample),P95(McProfileGradientFallbackCalls),
P95(McProfileEdgeMidpointCalls),P95(McProfileGradientMemoHits));
}
}
if(Assembly!=nullptr&&!Assembly->plan.strates.empty())
{