standalone: whole view under one second -- 0.955 s cold @8 workers, full payload, world unchanged

- Eight-sample X batching of fine density rows, reuse of solved Z intervals in the candidate mask,
  AVX2 marching-cubes cell classification. LOD0/1 density-grid time -61/-62%; interval/sign stage
  140 -> 97 ms; candidate-axis allocation -18 MiB. Shape stage ~413 ms, detail band ~219 ms.
- W1/W8 hashes equal across 44 fields and equal to round 8; routes 5642/5642; look and far-survival
  audits pass; bad-shell control still fails; six fixed captures pixel-identical.
  Remote-view recapture pending (camera 500,0,0).
Verified by me, interleaved (8 workers, cold, BelowNormal 0xFF00, 2,226 tiles, 110.9 MiB payload):
1.012 / 0.927 / 0.926 s vs round 8 1.100 / 1.099 / 1.088 s.

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-05 05:15:19 +02:00
1 parent 16612acba4
commit 2656d81ac9
4 files changed
+667 -109

No files matched your search

@@ -3,6 +3,7 @@
#include "VoxelMarchingCubesMesher.h"
#include "MarchingCubesTables.h"
#include "StandaloneShapeWorld.h"
#include "VoxelDensityProfile.h"
#if WITH_EDITOR
#include "VoxelRedefinedDensityField.h"
@@ -14,6 +15,7 @@
#include "HAL/IConsoleManager.h"
#include "Misc/CommandLine.h"
#include <atomic>
#include <immintrin.h>
namespace
{
@@ -940,8 +942,8 @@ FVoxelMeshData UVoxelMarchingCubesMesher::GenerateMesh(FIntVector OriginVoxels,
const int32 GZ = GzLo + BrickZ + Z;
const int32 LocalIndex =
((GZ + 1) * MDim + (GY + 1)) * MDim + (GX + 1);
DensityGrid[LocalIndex] =
BrickValues[(Z * BrickSize.Y + Y) * BrickSize.X + X];
const float Density=BrickValues[(Z * BrickSize.Y + Y) * BrickSize.X + X];
DensityGrid[LocalIndex]=Density;
}
if (OutDensitySampleCount != nullptr)
{
@@ -1022,6 +1024,9 @@ FVoxelMeshData UVoxelMarchingCubesMesher::GenerateMesh(FIntVector OriginVoxels,
// lower overhead when a tile spans only one room-graph region.
const int64 TileExtentVoxels = static_cast<int64>(Step) * CellsPerAxis;
const bool bUseVerticalCacheTraversal = TileExtentVoxels > CHUNK_SIZE * 16;
const FStandaloneShapeWorld* ActiveShapeWorld=FStandaloneShapeWorldAccess::GetActive();
const bool bUseShapeWorldXBatch=ActiveShapeWorld!=nullptr
&&!bUseSharedDensityGrid&&!bCapturePreEditGrid;
if (bUseVerticalCacheTraversal)
{
for (const std::vector<int32>& YGroup : YGroups)
@@ -1058,9 +1063,54 @@ FVoxelMeshData UVoxelMarchingCubesMesher::GenerateMesh(FIntVector OriginVoxels,
if (bUseOperatorBlock) { Generator->EndDensityBlock(); }
return FVoxelMeshData();
}
for (const int32 gx : XGroup)
if(bUseShapeWorldXBatch)
{
SampleGridPoint(gx,gy,gz);
for(size_t Offset=0;Offset<XGroup.size();)
{
const int32 BatchCount=static_cast<int32>(std::min<size_t>(
8,XGroup.size()-Offset));
const int32 GX0=XGroup[Offset];
bool bContiguous=true;
for(int32 Lane=1;Lane<BatchCount;++Lane)
bContiguous&=XGroup[Offset+static_cast<size_t>(Lane)]==GX0+Lane;
if(!bContiguous)
{
for(int32 Lane=0;Lane<BatchCount;++Lane)
SampleGridPoint(XGroup[Offset+static_cast<size_t>(Lane)],gy,gz);
Offset+=static_cast<size_t>(BatchCount);
continue;
}
float Densities[8]{};
ActiveShapeWorld->DensityAtLatticeX8(
OriginVoxels.X+GX0*Step,Step,
OriginVoxels.Y+gy*Step,OriginVoxels.Z+gz*Step,
BatchCount,Densities);
for(int32 Lane=0;Lane<BatchCount;++Lane)
{
const int32 GX=GX0+Lane;
const int32 LocalIndex=
((gz+1)*MDim+(gy+1))*MDim+(GX+1);
DensityGrid[LocalIndex]=Densities[Lane];
}
const int32 LastGX=GX0+BatchCount-1;
const int32 ReachBlockX=FMath::Clamp(LastGX,0,CellsPerAxis-1)
/VoxelGenLOD::TileReachBlockCells;
const int32 ReachBlockY=FMath::Clamp(gy,0,CellsPerAxis-1)
/VoxelGenLOD::TileReachBlockCells;
const int32 ReachBlockZ=FMath::Clamp(gz,0,CellsPerAxis-1)
/VoxelGenLOD::TileReachBlockCells;
VoxelGenLOD::TileReachBlockIndex=
((ReachBlockZ*ReachBlocksPerAxis)+ReachBlockY)
*ReachBlocksPerAxis+ReachBlockX;
if(OutDensitySampleCount)
*OutDensitySampleCount+=BatchCount;
Offset+=static_cast<size_t>(BatchCount);
}
}
else
{
for(const int32 gx:XGroup)SampleGridPoint(gx,gy,gz);
}
}
}
@@ -1219,12 +1269,103 @@ FVoxelMeshData UVoxelMarchingCubesMesher::GenerateMesh(FIntVector OriginVoxels,
const bool bProfileMesher = VoxelDensityProfile::IsCycleTimingEnabled();
uint64 CellClassificationCalls = 0;
uint64 SurfaceCellCalls = 0;
uint8 CaseIndexRow[CHUNK_SIZE]{};
uint8 SurfaceRow[CHUNK_SIZE]{};
uint8 SampleClassificationRow[CHUNK_SIZE]{};
for (int32 cz = CzLo; cz <= CzHi; cz++) // bande de strate : cf. CzLo/CzHi plus haut
{
if (ShouldAbortWork()) return FVoxelMeshData();
for (int32 cy = 0; cy < CellsPerAxis; cy++)
{
if (ShouldAbortWork()) return FVoxelMeshData();
FMemory::Memzero(SampleClassificationRow, sizeof(SampleClassificationRow));
const uint64 ClassificationRowStart = bProfileMesher
? FPlatformTime::Cycles64() : 0;
int32 ClassificationRowCalls = 0;
for (int32 GroupX = 0; GroupX < CellsPerAxis; GroupX += 8)
{
const int32 GroupCount = FMath::Min(8, CellsPerAxis - GroupX);
if (bUseProofBlocks
&& BlockSkip[((cz / 8) * BlocksPerAxis + (cy / 8)) * BlocksPerAxis
+ (GroupX / 8)] != 0)
{
continue;
}
if (GroupCount == 8)
{
const float* Row00 = DensityGrid.GetData()
+ ((cz + 1) * MDim + (cy + 1)) * MDim + GroupX + 1;
const float* Row01 = Row00 + MDim;
const float* Row10 = Row00 + MDim * MDim;
const float* Row11 = Row10 + MDim;
const __m256 Iso = _mm256_set1_ps(IsoLevel);
const int32 Masks[8] = {
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row00), Iso, _CMP_GE_OQ)),
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row00 + 1), Iso, _CMP_GE_OQ)),
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row01 + 1), Iso, _CMP_GE_OQ)),
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row01), Iso, _CMP_GE_OQ)),
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row10), Iso, _CMP_GE_OQ)),
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row10 + 1), Iso, _CMP_GE_OQ)),
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row11 + 1), Iso, _CMP_GE_OQ)),
_mm256_movemask_ps(_mm256_cmp_ps(_mm256_loadu_ps(Row11), Iso, _CMP_GE_OQ)),
};
for (int32 Lane = 0; Lane < 8; ++Lane)
{
const int32 CellX = GroupX + Lane;
int32 CaseIndex = 0;
for (int32 Corner = 0; Corner < 8; ++Corner)
{
CaseIndex |= ((Masks[Corner] >> Lane) & 1) << Corner;
}
CaseIndexRow[CellX] = static_cast<uint8>(CaseIndex);
SurfaceRow[CellX] = MCEdgeTable[CaseIndex] != 0;
SampleClassificationRow[CellX] = bProfileMesher
&& VoxelDensityProfile::ShouldSample(
VoxelDensityProfile::EBucket::MesherCellClassification);
++ClassificationRowCalls;
++CellClassificationCalls;
}
}
else
{
for (int32 Lane = 0; Lane < GroupCount; ++Lane)
{
const int32 CellX = GroupX + Lane;
int32 CaseIndex = 0;
for (int32 Corner = 0; Corner < 8; ++Corner)
{
const float Density = SampleG(
CellX + CornerOffsets[Corner].X,
cy + CornerOffsets[Corner].Y,
cz + CornerOffsets[Corner].Z);
if (Density >= IsoLevel) CaseIndex |= 1 << Corner;
}
CaseIndexRow[CellX] = static_cast<uint8>(CaseIndex);
SurfaceRow[CellX] = MCEdgeTable[CaseIndex] != 0;
SampleClassificationRow[CellX] = bProfileMesher
&& VoxelDensityProfile::ShouldSample(
VoxelDensityProfile::EBucket::MesherCellClassification);
++ClassificationRowCalls;
++CellClassificationCalls;
}
}
}
if (bProfileMesher && ClassificationRowCalls > 0)
{
const uint64 RowCycles = FPlatformTime::Cycles64() - ClassificationRowStart;
const uint64 PerCellCycles = RowCycles
/ static_cast<uint64>(ClassificationRowCalls);
for (int32 cx = 0; cx < CellsPerAxis; ++cx)
{
if (SampleClassificationRow[cx])
{
VoxelDensityProfile::AddSampledMeasurement(
VoxelDensityProfile::EBucket::MesherCellClassification,
PerCellCycles);
}
}
}
for (int32 cx = 0; cx < CellsPerAxis; cx++)
{
if (bUseProofBlocks
@@ -1232,37 +1373,19 @@ FVoxelMeshData UVoxelMarchingCubesMesher::GenerateMesh(FIntVector OriginVoxels,
{
continue;
}
const bool bSampleCell = bProfileMesher
&& VoxelDensityProfile::ShouldSample(
VoxelDensityProfile::EBucket::MesherCellClassification);
const uint64 ClassificationStart = bSampleCell
? FPlatformTime::Cycles64() : 0;
// PASSE 1 : densités aux 8 coins + index de cas MC SEULEMENT.
// ~70% des cellules d'un chunk sont tout-roc ou tout-air (aucune surface) ;
// on les rejette ICI, AVANT de payer les 8 positions + 8 gradients (48 lectures
// grille + maths vectorielles). Sortie bit-identique : positions et gradients ne
// servent qu'aux cellules réellement traversées par l'isosurface.
const bool bSampleCell = SampleClassificationRow[cx] != 0;
float Densities[8];
int32 CaseIndex = 0;
for (int32 i = 0; i < 8; i++)
{
const float D = SampleG(cx + CornerOffsets[i].X,
cy + CornerOffsets[i].Y,
cz + CornerOffsets[i].Z);
Densities[i] = D;
if (D >= IsoLevel) CaseIndex |= (1 << i);
}
const bool bHasSurface = MCEdgeTable[CaseIndex] != 0;
if (bSampleCell)
{
VoxelDensityProfile::AddSampledMeasurement(
VoxelDensityProfile::EBucket::MesherCellClassification,
FPlatformTime::Cycles64() - ClassificationStart);
}
++CellClassificationCalls;
const int32 CaseIndex = CaseIndexRow[cx];
const bool bHasSurface = SurfaceRow[cx] != 0;
if (!bHasSurface) continue; // Pas de surface ici → skip
++SurfaceCellCalls;
// Density values are needed only after classification, for edge interpolation.
for (int32 i = 0; i < 8; i++)
{
Densities[i] = SampleG(cx + CornerOffsets[i].X,
cy + CornerOffsets[i].Y,
cz + CornerOffsets[i].Z);
}
// PASSE 2 : positions + gradients aux 8 coins (uniquement si surface présente).
const uint64 GradientStart = bSampleCell