perf(gen): the landing work was per-voxel -- 342s to 2.6s, same world
The owner played64f5d61and reported the truth: "generation still takes ages... TunnelNetwork doesn't even finish generating, as big as the surface world" while SurfaceWorld completed in under 10s, and stopping PIE hung for 30+ seconds. e08b49a's 21x was real and irrelevant. It fixed per-CHUNK state rebuilds, which dominate the commandlet export path. The game is bound by per-VOXEL evaluation. Same symptom, different bottleneck, and nobody had measured the second one. WHY PIE HUNG bShuttingDown was never checked inside VoxelMarchingCubesMesher.cpp -- zero occurrences. A worker inside GenerateMesh could not abort, so 64f5d61's correct unconditional EndPlay wait was waiting on tiles physically unable to stop. The hang was not a teardown bug; it was evidence that one tile took tens of seconds. Added shutdown polling per slab/row in the mesher and through GenerateTileResult; aborted results carry Epoch + bAborted and ProcessQueue drops them. EndPlay still waits unconditionally -- the 3s mark only logs now. PIE stop 3.409s / 44.759s -> 4 ms teardown, 38 us worker drain WHERE THE PER-VOXEL COST WAS The owner's own comparison was the sharpest instrument available. Profiled both: GetDensityAt TunnelNetwork 12.64 us/sample SurfaceWorld 1.32 tunnel candidates evaluated 7.088 per sample 0 tunnel-core candidates evaluated 7.201 per sample 0 room candidates evaluated 1.000 per sample 0 largest buckets: RoomGraphSource 2.57, TunnelCorePosts 0.76, PassageCarveOp 0.22, PassageStructuralPosts 0.20 The three regressing commits map cleanly, and one is innocent:7a20eeedrainage tree -- cache-build work, NOT per-voxel413c15dlandings -- repeated full passage modification per sample55bf807landing rooms -- room SDF + tunnel/core evaluation per sample Fixes: FPassageCarveOp carves only, landing/support moved to the structural MC post; tunnel core support and SDF fused into one pass; room graph caches shared per worker on complete deterministic keys; tunnel density cache uses open addressing with 4096 slots. Room cache rebuilds fell to 9 per 42,875 samples, so what remains is genuine O(local cached room/tunnel count) work. TunnelNetwork 128^3, seed 1337 slot 1, same region: 342.2 s / 163.161 us/vox -> 2.623 s / 1.251 us/vox (130x) Geometry SHA-256 aaf95559..066b4, IDENTICAL to the pre-optimisation run at the same roughness. 153,692 triangles either way. Verified independently of the agent's own report. NOT FIXED, and the first one is the next real target: - L4 tiles still cost 16.93 s. Hit rate falls 99.9% (L0) -> 23.7% (L4), but 1024 -> 4096 slots only moved 18.39s -> 16.93s and the 1,927 misses ARE the distinct key count. That is low reuse, not eviction. A bigger cache will not save it. - TunnelNetwork is still ~10x SurfaceWorld (0.354s vs 0.028s on a matched 32^3). - The live PIE tile table is SurfaceWorld: this checkout's PIE map is configured that way. TunnelNetwork went through the same mesher and density path via the commandlet, but no TunnelNetwork tile has been timed in an actual game session. Export numbers are not presented as game numbers. Still outstanding, untouched here: the inter-strate passage has intersections it should not have, routes through open passage when it should not, and should descend from a low point of the current strate. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aheo2crrZmHuYtPpdY2Cb
This commit is contained in:
1 parent
64f5d61e08
commit
0576e800c4
15 files changed
+1042
-131
No files matched your search
@@ -21,6 +21,7 @@
|
||||
#include "UObject/StrongObjectPtr.h"
|
||||
#include "UObject/UObjectGlobals.h"
|
||||
#include "VoxelDiffLayer.h"
|
||||
#include "VoxelDensityProfile.h"
|
||||
#include "VoxelGenerator.h"
|
||||
#include "VoxelMarchingCubesMesher.h"
|
||||
#include "VoxelNoise.h"
|
||||
@@ -172,6 +173,8 @@ struct FExploreArguments
|
||||
bool bRender = true;
|
||||
bool bWalk = true;
|
||||
bool bExport = true;
|
||||
bool bProfileDensity = false;
|
||||
bool bProfileLod = false;
|
||||
bool bFailureFocusRender = false;
|
||||
FString OutDirectory;
|
||||
|
||||
@@ -209,6 +212,8 @@ bool ParseArguments(const FString& Params, FExploreArguments& OutArguments, FStr
|
||||
FParse::Value(*Params, TEXT("archetype="), ArchetypeText);
|
||||
FParse::Value(*Params, TEXT("slot="), OutArguments.Slot);
|
||||
FParse::Value(*Params, TEXT("modes="), ModesText);
|
||||
OutArguments.bProfileDensity = FParse::Param(*Params, TEXT("profiledensity"));
|
||||
OutArguments.bProfileLod = FParse::Param(*Params, TEXT("profilelod"));
|
||||
FParse::Value(*Params, TEXT("out="), OutText);
|
||||
FParse::Value(*Params, TEXT("renderwidth="), OutArguments.RenderWidth);
|
||||
FParse::Value(*Params, TEXT("renderheight="), OutArguments.RenderHeight);
|
||||
@@ -3840,6 +3845,12 @@ int32 UVoxelForgeExploreCommandlet::Main(const FString& Params)
|
||||
UE_LOG(LogTemp, Error, TEXT("[VoxelForgeExplore] %s"), *Error);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (Arguments.bProfileDensity)
|
||||
{
|
||||
VoxelDensityProfile::Reset();
|
||||
VoxelDensityProfile::SetEnabled(true);
|
||||
}
|
||||
if (!IFileManager::Get().MakeDirectory(*Arguments.OutDirectory, true))
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("[VoxelForgeExplore] Could not create output directory '%s'."),
|
||||
@@ -3860,6 +3871,61 @@ int32 UVoxelForgeExploreCommandlet::Main(const FString& Params)
|
||||
}
|
||||
const double SetupSeconds = FPlatformTime::Seconds() - SetupStartSeconds;
|
||||
|
||||
if (Arguments.bProfileLod)
|
||||
{
|
||||
const FIntVector ProbeOrigin(0, 0, World.TargetBottomWorldZ);
|
||||
const int32 FullRes = World.Settings
|
||||
? FMath::Max(1, World.Settings->FullResClipLevels)
|
||||
: 2;
|
||||
const int32 CoarseCells = World.Settings
|
||||
? FMath::Clamp(World.Settings->CoarseTileCells, 4, CHUNK_SIZE)
|
||||
: 16;
|
||||
const int32 CutMin = World.Settings
|
||||
? World.Settings->StrateContentCutMinLevel
|
||||
: 9;
|
||||
for (int32 Level = 0; Level <= 4; ++Level)
|
||||
{
|
||||
// Match AVoxelWorld::LoadTile exactly: the probe is a production tile at this LOD,
|
||||
// including the configured coarse sample count. Using 1<<Level here would measure
|
||||
// a denser mesh than the game generates at levels >= FullResClipLevels.
|
||||
const int32 Extent = CHUNK_SIZE << Level;
|
||||
const int32 Cells = Level < FullRes ? CHUNK_SIZE : CoarseCells;
|
||||
const int32 Step = FMath::Max(1, Extent / Cells);
|
||||
VoxelDensityProfile::Reset();
|
||||
VoxelDensityProfile::SetEnabled(true);
|
||||
const double Start = FPlatformTime::Seconds();
|
||||
const bool bBanded = Level >= CutMin;
|
||||
const FVoxelMeshData Mesh = World.Mesher->GenerateMesh(
|
||||
ProbeOrigin, Step, Cells, nullptr,
|
||||
bBanded ? World.TargetBottomWorldZ : INT32_MIN,
|
||||
bBanded ? World.TargetTopWorldZ - 1 : INT32_MAX);
|
||||
const double Seconds = FPlatformTime::Seconds() - Start;
|
||||
const VoxelDensityProfile::FSnapshot Profile = VoxelDensityProfile::Snapshot();
|
||||
const int32 DensityIndex = static_cast<int32>(VoxelDensityProfile::EBucket::GetDensityAt);
|
||||
const uint64 Calls = Profile.Calls[DensityIndex];
|
||||
const uint64 Lookups = Profile.Counters[static_cast<int32>(VoxelDensityProfile::ECounter::TunnelCacheLookup)];
|
||||
const uint64 Hits = Profile.Counters[static_cast<int32>(VoxelDensityProfile::ECounter::TunnelCacheHit)];
|
||||
const uint64 SdfBuilds = Profile.Counters[static_cast<int32>(VoxelDensityProfile::ECounter::SdfCacheBuild)];
|
||||
const double DensityUs = static_cast<double>(Profile.Cycles[DensityIndex])
|
||||
* FPlatformTime::GetSecondsPerCycle64() * 1.0e6;
|
||||
UE_LOG(LogTemp, Display,
|
||||
TEXT("[VoxelForgeLODProfile] level=%d step=%d cells=%d banded=%d seconds=%.6f density_calls=%llu "
|
||||
"density_us_per_call=%.3f sdf_builds=%llu cache_lookups=%llu cache_hits=%llu cache_misses=%llu "
|
||||
"hit_rate=%.3f vertices=%d triangles=%d mesh_empty=%d"),
|
||||
Level, Step, Cells, bBanded ? 1 : 0, Seconds,
|
||||
static_cast<unsigned long long>(Calls),
|
||||
Calls > 0 ? DensityUs / static_cast<double>(Calls) : 0.0,
|
||||
static_cast<unsigned long long>(SdfBuilds),
|
||||
static_cast<unsigned long long>(Lookups),
|
||||
static_cast<unsigned long long>(Hits),
|
||||
static_cast<unsigned long long>(Profile.Counters[static_cast<int32>(VoxelDensityProfile::ECounter::TunnelCacheMiss)]),
|
||||
Lookups > 0 ? static_cast<double>(Hits) / static_cast<double>(Lookups) : 0.0,
|
||||
Mesh.Vertices.Num(), Mesh.Triangles.Num() / 3,
|
||||
Mesh.IsEmpty() ? 1 : 0);
|
||||
}
|
||||
VoxelDensityProfile::SetEnabled(false);
|
||||
}
|
||||
|
||||
FExploreRunOutput Output;
|
||||
if (Budget.ShouldStop(TEXT("setup")))
|
||||
{
|
||||
@@ -4044,5 +4110,48 @@ int32 UVoxelForgeExploreCommandlet::Main(const FString& Params)
|
||||
FPlatformTime::Seconds() - MainStartSeconds,
|
||||
*ReportPath,
|
||||
(bPayloadRepeatEqual && bFinalRepeatEqual) ? TEXT("yes") : TEXT("no"));
|
||||
|
||||
if (Arguments.bProfileDensity)
|
||||
{
|
||||
const VoxelDensityProfile::FSnapshot Profile = VoxelDensityProfile::Snapshot();
|
||||
const double CycleToMicroseconds = FPlatformTime::GetSecondsPerCycle64() * 1.0e6;
|
||||
const uint64 DensityCalls = Profile.Calls[static_cast<int32>(VoxelDensityProfile::EBucket::GetDensityAt)];
|
||||
const uint64 DensityCycles = Profile.Cycles[static_cast<int32>(VoxelDensityProfile::EBucket::GetDensityAt)];
|
||||
const double DensityTotalUs = static_cast<double>(DensityCycles) * CycleToMicroseconds;
|
||||
UE_LOG(LogTemp, Display,
|
||||
TEXT("[VoxelForgeDensityProfile] total calls=%llu total_us=%.3f us_per_call=%.6f"),
|
||||
static_cast<unsigned long long>(DensityCalls), DensityTotalUs,
|
||||
DensityCalls > 0 ? DensityTotalUs / static_cast<double>(DensityCalls) : 0.0);
|
||||
|
||||
for (int32 Index = 0; Index < VoxelDensityProfile::CounterCount; ++Index)
|
||||
{
|
||||
const VoxelDensityProfile::ECounter Counter =
|
||||
static_cast<VoxelDensityProfile::ECounter>(Index);
|
||||
UE_LOG(LogTemp, Display,
|
||||
TEXT("[VoxelForgeDensityProfile] counter=%s value=%llu per_density_call=%.3f"),
|
||||
VoxelDensityProfile::CounterName(Counter),
|
||||
static_cast<unsigned long long>(Profile.Counters[Index]),
|
||||
DensityCalls > 0
|
||||
? static_cast<double>(Profile.Counters[Index])
|
||||
/ static_cast<double>(DensityCalls)
|
||||
: 0.0);
|
||||
}
|
||||
|
||||
for (int32 Index = 0; Index < VoxelDensityProfile::BucketCount; ++Index)
|
||||
{
|
||||
const uint64 Calls = Profile.Calls[Index];
|
||||
if (Calls == 0 || Index == static_cast<int32>(VoxelDensityProfile::EBucket::GetDensityAt))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const double TotalUs = static_cast<double>(Profile.Cycles[Index]) * CycleToMicroseconds;
|
||||
UE_LOG(LogTemp, Display,
|
||||
TEXT("[VoxelForgeDensityProfile] op=%s calls=%llu total_us=%.3f us_per_call=%.6f"),
|
||||
VoxelDensityProfile::BucketName(static_cast<VoxelDensityProfile::EBucket>(Index)),
|
||||
static_cast<unsigned long long>(Calls), TotalUs,
|
||||
TotalUs / static_cast<double>(Calls));
|
||||
}
|
||||
VoxelDensityProfile::SetEnabled(false);
|
||||
}
|
||||
return bRequestedModeFailed ? 2 : 0;
|
||||
}
|
||||
Reference in new issue
Block a user