passages: memoized exact MC midpoints + wider conservative sweep bounds (L101, exact vs L100)

Off-grid census by caller (MC midpoints, skirts, far shells); all 63.0M sweep misses accounted
(1.9M exact-route fallbacks, 61.1M counted bound skips). Exact MC midpoint queries memoized by
float bits (Unreal enables it too); feature bounds expanded. L100/L101 whole-view hashes equal in
all four strata (v216 unchanged); 0 added/removed crossings; 15 capture pairs pixel-identical.
Near-ready @W12 L100 -> L101: FI 1.77 -> 1.65, TN 1.66 -> 1.54, SW 0.85 -> 0.84, VS 1.03 -> 1.03 s
(L98 2.28/2.23/1.02/1.11). Fast tier PASS; Linux UE host builds. Unreal arrival traces not obtained
(the runner wrongly applied the 6 GiB address-space cap to Unreal).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016dhxM43dnWvUu2B5Ph1iG1
This commit is contained in:
Fr0zkaandClaude Opus 5.5 committed 2026-10-28 18:57:56 +01:00
1 parent 2d5822cdf7
commit 55e20f4a7e
48 files changed
+2087 -38

No files matched your search

+193 -12
View File
@@ -105,12 +105,46 @@ static double VF_L93PassageCarveReachMetres()
return 4.0;
}
enum class EPassageDensityQueryCaller : std::size_t
{
Unknown,
DensityGrid,
GradientNormalFallback,
MidpointCorrection,
SkirtSurfaceVertex,
SkirtExtrudedVertex,
SkirtClippedVertex,
SkirtRefinementFace,
SkirtCoarseCentroid,
FarShellSurfaceQuery,
FarShellProjectionNormal,
FarShellStratumRefinement,
Count
};
inline constexpr std::size_t PassageDensityQueryCallerCount=
static_cast<std::size_t>(EPassageDensityQueryCaller::Count);
// Standalone-only world compiler. It compiles the runtime room/tunnel/passages into
// axis-line intervals, composes rock/cave signs into packed Z-column words, then displaces
// only the conservative surface band. The copied Unreal generator remains the A/B reference.
class FStandaloneShapeWorld
{
public:
static EPassageDensityQueryCaller& CurrentPassageDensityQueryCaller() noexcept
{
static thread_local EPassageDensityQueryCaller Caller=
EPassageDensityQueryCaller::Unknown;
return Caller;
}
struct FScopedPassageDensityQueryCaller
{
explicit FScopedPassageDensityQueryCaller(EPassageDensityQueryCaller Caller)
:Previous(CurrentPassageDensityQueryCaller())
{CurrentPassageDensityQueryCaller()=Caller;}
~FScopedPassageDensityQueryCaller()
{CurrentPassageDensityQueryCaller()=Previous;}
EPassageDensityQueryCaller Previous;
};
const VoxelForgeCore::ResolvedLayoutSnapshotV3* ResolvedLayout=nullptr;
struct FResolvedStratumBounds
{
@@ -299,6 +333,11 @@ public:
std::vector<FPassageSamples> passages;
std::atomic<std::uint64_t> lookups{0},cacheHits{0},baseInfluenceHits{0},
outOfInfluenceHits{0},missingSamples{0};
std::array<std::atomic<std::uint64_t>,PassageDensityQueryCallerCount>
missingLookupsByCaller{},exactRouteFallbacksByCaller{},
featureBoundSkipsByCaller{},tileFreeSkipsByCaller{},
verticalBoundSkipsByCaller{},negativeReachSkipsByCaller{},
positiveReachSkipsByCaller{};
};
FScopedPassageTileQueries(const FStandaloneShapeWorld& shape,
const std::array<std::int64_t,3>& minimumSubvoxels,
@@ -397,10 +436,12 @@ public:
&&feature.segmentIndex<shape.PassageSegmentData[
feature.passageIndex].size())
{
const auto& segment=shape.PassageSegmentData[feature.passageIndex][
feature.segmentIndex];
candidate.sweepMinimumSubvoxels=segment.sweepMinimumSubvoxels;
candidate.sweepMaximumSubvoxels=segment.sweepMaximumSubvoxels;
// Cover the full conservative route feature box when preparing
// the lattice sweep. The wider exact samples avoid rescanning the
// direct route for in-bound bridge/tread/clearance points; the
// existing carve-reach check still rejects out-of-influence values.
candidate.sweepMinimumSubvoxels=featureBounds.minimumSubvoxels;
candidate.sweepMaximumSubvoxels=featureBounds.maximumSubvoxels;
}
if(feature.bColumn)passageColumns_[feature.passageIndex]=1;
else if(feature.bMouthSupport)
@@ -480,6 +521,30 @@ public:
passageSweepData_->outOfInfluenceHits.load(std::memory_order_relaxed);
profileStats_->passageSweepMissingSamples=passageSweepData_->missingSamples.load(
std::memory_order_relaxed);
for(std::size_t caller=0;caller<PassageDensityQueryCallerCount;++caller)
{
profileStats_->passageSweepMissingLookupsByCaller[caller]=
passageSweepData_->missingLookupsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepExactRouteFallbacksByCaller[caller]=
passageSweepData_->exactRouteFallbacksByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepFeatureBoundSkipsByCaller[caller]=
passageSweepData_->featureBoundSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepTileFreeSkipsByCaller[caller]=
passageSweepData_->tileFreeSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepVerticalBoundSkipsByCaller[caller]=
passageSweepData_->verticalBoundSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepNegativeReachSkipsByCaller[caller]=
passageSweepData_->negativeReachSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepPositiveReachSkipsByCaller[caller]=
passageSweepData_->positiveReachSkipsByCaller[caller].load(
std::memory_order_relaxed);
}
}
if(ownsReuseCounters_&&reuseCounters_)
std::printf("[L98PassageReuseTile] lod=%d projection_columns=%llu projection_computes=%llu projection_hits=%llu floor_profile_reads=%llu carve_prepared=%llu support_prepared=%llu capsule_prepared=%llu mouth_prepared=%llu\n",
@@ -558,6 +623,7 @@ public:
FScopedPassageTileQueries& operator=(const FScopedPassageTileQueries&)=delete;
bool matches(const FStandaloneShapeWorld& shape) const{return shape_==&shape;}
bool capturesCallerDiagnostics() const noexcept{return profileStats_!=nullptr;}
void prepareSweptTubeBase(const FIntVector& origin,std::int32_t step,
std::int32_t cells,std::uint32_t seed);
const FPassageSweepSample* sweptSample(std::size_t passageIndex,
@@ -576,6 +642,72 @@ public:
passageSweepData_->outOfInfluenceHits.load(std::memory_order_relaxed);
profileStats_->passageSweepMissingSamples=passageSweepData_->missingSamples.load(
std::memory_order_relaxed);
for(std::size_t caller=0;caller<PassageDensityQueryCallerCount;++caller)
{
profileStats_->passageSweepMissingLookupsByCaller[caller]=
passageSweepData_->missingLookupsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepExactRouteFallbacksByCaller[caller]=
passageSweepData_->exactRouteFallbacksByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepFeatureBoundSkipsByCaller[caller]=
passageSweepData_->featureBoundSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepTileFreeSkipsByCaller[caller]=
passageSweepData_->tileFreeSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepVerticalBoundSkipsByCaller[caller]=
passageSweepData_->verticalBoundSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepNegativeReachSkipsByCaller[caller]=
passageSweepData_->negativeReachSkipsByCaller[caller].load(
std::memory_order_relaxed);
profileStats_->passageSweepPositiveReachSkipsByCaller[caller]=
passageSweepData_->positiveReachSkipsByCaller[caller].load(
std::memory_order_relaxed);
}
}
void recordExactRouteFallback() const noexcept
{
if(!profileStats_||!passageSweepData_)return;
const auto caller=static_cast<std::size_t>(
FStandaloneShapeWorld::CurrentPassageDensityQueryCaller());
if(caller<PassageDensityQueryCallerCount)
passageSweepData_->exactRouteFallbacksByCaller[caller].fetch_add(
1,std::memory_order_relaxed);
}
void recordFeatureBoundSkip() const noexcept
{
if(!profileStats_||!passageSweepData_)return;
const auto caller=static_cast<std::size_t>(
FStandaloneShapeWorld::CurrentPassageDensityQueryCaller());
if(caller<PassageDensityQueryCallerCount)
passageSweepData_->featureBoundSkipsByCaller[caller].fetch_add(
1,std::memory_order_relaxed);
}
enum class ESweepMissSkipReason : std::uint8_t
{
TileFree,VerticalBound,NegativeReach,PositiveReach
};
void recordSweepMissSkip(ESweepMissSkipReason reason) const noexcept
{
if(!profileStats_||!passageSweepData_)return;
const auto caller=static_cast<std::size_t>(
FStandaloneShapeWorld::CurrentPassageDensityQueryCaller());
if(caller>=PassageDensityQueryCallerCount)return;
std::atomic<std::uint64_t>* counts=nullptr;
switch(reason)
{
case ESweepMissSkipReason::TileFree:
counts=&passageSweepData_->tileFreeSkipsByCaller[caller];break;
case ESweepMissSkipReason::VerticalBound:
counts=&passageSweepData_->verticalBoundSkipsByCaller[caller];break;
case ESweepMissSkipReason::NegativeReach:
counts=&passageSweepData_->negativeReachSkipsByCaller[caller];break;
case ESweepMissSkipReason::PositiveReach:
counts=&passageSweepData_->positiveReachSkipsByCaller[caller];break;
}
if(counts)counts->fetch_add(1,std::memory_order_relaxed);
}
bool beginProjectionColumn() const
{
@@ -1945,25 +2077,34 @@ public:
const bool usePreparedPassageSweep=preparedSweepSample!=nullptr;
// Candidate route bounds include the carve reach, tread/clearance extents,
// and conservative padding. A missing lattice sample outside every route
// bound cannot affect this query; keep direct evaluation for all in-bound
// misses and for the separate column and mouth-support paths.
// bound cannot affect this query, even when another segment or column in
// this tile overlaps elsewhere. Column composition above and mouth-support
// paths below remain separate and are preserved.
if(preparedPassageSweepRequested&&!preparedSweepSample
&&!passageTileQueries->hasFeature(passageIndex,true)
&&!passageTileQueries->hasMouthSupport(passageIndex)
&&!passageTileQueries->hasUpperMouthSupport(passageIndex)
&&!passageTileQueries->routeFeatureMayAffect(passageIndex,qx,qy,qz))
&&!passageTileQueries->routeFeatureMayAffect(passageIndex,qx,qy,qz))
{
passageTileQueries->recordFeatureBoundSkip();
continue;
}
if(usePreparedPassageSweep
&&preparedSweepSample->signedDistance>passageCarveReachQ)continue;
const bool tilePassageFree=passageTileScopeMatches
&&!ActivePassageTileQueries->hasFeature(passageIndex,false);
if(composed>=0.0f&&tilePassageFree)
{
if(preparedPassageSweepRequested&&!preparedSweepSample)
passageTileQueries->recordSweepMissSkip(
FScopedPassageTileQueries::ESweepMissSkipReason::TileFree);
continue;
}
if(qz>firstFloorQ+2.0*passage.mouthRadiusSubvoxels
||qz<lastFloorQ-2.0*passage.mouthRadiusSubvoxels)
{
if(preparedPassageSweepRequested&&!preparedSweepSample)
passageTileQueries->recordSweepMissSkip(
FScopedPassageTileQueries::ESweepMissSkipReason::VerticalBound);
continue;
}
const std::ptrdiff_t lastIndex=passageConstants.lastIndex;
@@ -2018,6 +2159,9 @@ public:
carveSourceReachQ(composed)))
{
if(passageProfile)++passageProfile->passageNegativeBoundRejects;
if(preparedPassageSweepRequested&&!preparedSweepSample)
passageTileQueries->recordSweepMissSkip(
FScopedPassageTileQueries::ESweepMissSkipReason::NegativeReach);
continue;
}
}
@@ -2037,6 +2181,9 @@ public:
carveSourceReachQ(composed)))
{
if(passageProfile)++passageProfile->passagePositiveBoundRejects;
if(preparedPassageSweepRequested&&!preparedSweepSample)
passageTileQueries->recordSweepMissSkip(
FScopedPassageTileQueries::ESweepMissSkipReason::PositiveReach);
continue;
}
}
@@ -2153,6 +2300,7 @@ public:
}
else if(passageTileScopeMatches)
{
passageTileQueries->recordExactRouteFallback();
VisitNearestPassageSegmentRange(passageIndex,carveBegin,carveEnd,qx,qy,qz,
0,bestSignedDistance,considerCarveSegment);
VisitNearestPassageSegmentRange(passageIndex,0,
@@ -3123,6 +3271,8 @@ public:
bool CaptureDensityQueryProfile=false;
uint64 DensityPointCalls=0,DensityFloatPointCalls=0,DensityLatticePointCalls=0,
DensityUnclampedPointCalls=0,DensityX8PointCalls=0;
std::array<uint64,PassageDensityQueryCallerCount> DensityOffGridFloatByCaller{},
DensityOffGridUnclampedByCaller{},DensityOffGridDetailByCaller{};
uint64 DensityFieldEvalNanoseconds=0,DensityFieldEvalSamplePoints=0;
std::array<uint64,4> DensityFieldEvalNanosecondsByKind{},DensityFieldEvalSamplePointsByKind{};
static constexpr std::size_t LegacyFieldTermCount=9;
@@ -3149,6 +3299,16 @@ public:
{ThreadClassificationStats().CaptureDensityQueryProfile=Enabled;}
static FClassificationThreadStats GetThreadClassificationStats()
{ return ThreadClassificationStats(); }
static void RecordOffGridDensityQuery(float X,float Y,float Z,
std::array<uint64,PassageDensityQueryCallerCount>& Counts)
{
if((std::abs(static_cast<double>(X)-std::round(static_cast<double>(X)))<=1.0e-5
&&std::abs(static_cast<double>(Y)-std::round(static_cast<double>(Y)))<=1.0e-5
&&std::abs(static_cast<double>(Z)-std::round(static_cast<double>(Z)))<=1.0e-5))
return;
const auto Caller=static_cast<std::size_t>(CurrentPassageDensityQueryCaller());
if(Caller<Counts.size())++Counts[Caller];
}
static void RecordLinux77Dispatch(VoxelForgeCore::Linux77Profiler::ERoute route,
uint64 points)
{
@@ -4326,6 +4486,10 @@ public:
float DensityAt(float X,float Y,float Z) const
{
if(SharedDensitySource)return SharedDensitySource->DensityAt(X,Y,Z);
if(const auto* QueryProfile=FScopedPassageTileQueries::CurrentFor(*this);
QueryProfile&&QueryProfile->capturesCallerDiagnostics())
RecordOffGridDensityQuery(X,Y,Z,
ThreadClassificationStats().DensityOffGridFloatByCaller);
FScopedDensityQueryProfile queryProfile(EDensityQueryKind::Float);
using namespace VoxelForgeCore::Linux77Profiler;
FScopedRoute l77DispatchRoute(ERoute::Dispatch);
@@ -4547,6 +4711,10 @@ public:
FScopedPhase l77Phase(EPhase::BaseField);
return SharedDensitySource->DensityAtUnclamped(X,Y,Z);
}
if(const auto* QueryProfile=FScopedPassageTileQueries::CurrentFor(*this);
QueryProfile&&QueryProfile->capturesCallerDiagnostics())
RecordOffGridDensityQuery(X,Y,Z,
ThreadClassificationStats().DensityOffGridUnclampedByCaller);
FScopedDensityQueryProfile queryProfile(EDensityQueryKind::Unclamped);
FScopedRoute l77DispatchRoute(ERoute::Dispatch);
FScopedPhase l77DispatchPhase(EPhase::Dispatch);
@@ -4596,6 +4764,10 @@ public:
VoxelForgeCore::DetailFieldSample DetailSampleAt(float X,float Y,float Z) const
{
if(SharedDensitySource)return SharedDensitySource->DetailSampleAt(X,Y,Z);
if(const auto* QueryProfile=FScopedPassageTileQueries::CurrentFor(*this);
QueryProfile&&QueryProfile->capturesCallerDiagnostics())
RecordOffGridDensityQuery(X,Y,Z,
ThreadClassificationStats().DensityOffGridDetailByCaller);
VoxelForgeCore::DetailFieldSample Sample;
if(bNativeOnly)
{RecordNativeOnlyViolation();return Sample;}
@@ -14354,15 +14526,24 @@ FStandaloneShapeWorld::FScopedPassageTileQueries::sweptSample(
const auto sweep=passageSweepData_;
if(!sweep)return nullptr;
sweep->lookups.fetch_add(1,std::memory_order_relaxed);
if(passageIndex>=sweep->passageToSweep.size())
const auto recordMissing=[&]()
{
sweep->missingSamples.fetch_add(1,std::memory_order_relaxed);
if(!profileStats_)return;
const auto caller=static_cast<std::size_t>(
FStandaloneShapeWorld::CurrentPassageDensityQueryCaller());
if(caller<PassageDensityQueryCallerCount)
sweep->missingLookupsByCaller[caller].fetch_add(1,std::memory_order_relaxed);
};
if(passageIndex>=sweep->passageToSweep.size())
{
recordMissing();
return nullptr;
}
const std::int32_t passageSweepIndex=sweep->passageToSweep[passageIndex];
if(passageSweepIndex<0||static_cast<std::size_t>(passageSweepIndex)>=sweep->passages.size())
{
sweep->missingSamples.fetch_add(1,std::memory_order_relaxed);
recordMissing();
return nullptr;
}
const std::array<double,3> query={qx,qy,qz};
@@ -14375,7 +14556,7 @@ FStandaloneShapeWorld::FScopedPassageTileQueries::sweptSample(
if(rounded<0||rounded>=sweep->dimension
||std::abs(coordinate-static_cast<double>(rounded))>1.0e-5)
{
sweep->missingSamples.fetch_add(1,std::memory_order_relaxed);
recordMissing();
return nullptr;
}
grid[axis]=rounded;
@@ -14386,7 +14567,7 @@ FStandaloneShapeWorld::FScopedPassageTileQueries::sweptSample(
const auto& samples=sweep->passages[static_cast<std::size_t>(passageSweepIndex)].samples;
if(index>=samples.size()||!samples[index].valid)
{
sweep->missingSamples.fetch_add(1,std::memory_order_relaxed);
recordMissing();
return nullptr;
}
sweep->cacheHits.fetch_add(1,std::memory_order_relaxed);