Skip to content

Commit

Permalink
Merge pull request #1568 from CesiumGS/debug-tile-states
Browse files Browse the repository at this point in the history
Add support for tile selection state debugging.
  • Loading branch information
kring authored Dec 24, 2024
2 parents ba15e90 + 5f6e124 commit 377444b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Source/CesiumRuntime/CesiumRuntime.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ public CesiumRuntime(ReadOnlyTargetRules Target) : base(Target)
"GLM_FORCE_SIZE_T_LENGTH",
"TIDY_STATIC",
"URI_STATIC_BUILD",
"SWL_VARIANT_NO_CONSTEXPR_EMPLACE"
"SWL_VARIANT_NO_CONSTEXPR_EMPLACE",
// Define to record the state of every tile, every frame, to a SQLite database.
// The database will be found in [Project Dir]/Saved/CesiumDebugTileStateDatabase.
// "CESIUM_DEBUG_TILE_STATES",
}
);

Expand Down
38 changes: 37 additions & 1 deletion Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
#include <memory>
#include <spdlog/spdlog.h>

#ifdef CESIUM_DEBUG_TILE_STATES
#include "HAL/PlatformFileManager.h"
#include <Cesium3DTilesSelection/DebugTileStateDatabase.h>
#endif

FCesium3DTilesetLoadFailure OnCesium3DTilesetLoadFailure{};

#if WITH_EDITOR
Expand All @@ -77,6 +82,10 @@ ACesium3DTileset::ACesium3DTileset()

_pTileset(nullptr),

#ifdef CESIUM_DEBUG_TILE_STATES
_pStateDebug(nullptr),
#endif

_lastTilesRendered(0),
_lastWorkerThreadTileLoadQueueLength(0),
_lastMainThreadTileLoadQueueLength(0),
Expand Down Expand Up @@ -1326,6 +1335,23 @@ void ACesium3DTileset::LoadTileset() {
break;
}

#ifdef CESIUM_DEBUG_TILE_STATES
FString dbDirectory = FPaths::Combine(
FPaths::ProjectSavedDir(),
TEXT("CesiumDebugTileStateDatabase"));

IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
if (!PlatformFile.DirectoryExists(*dbDirectory)) {
PlatformFile.CreateDirectory(*dbDirectory);
}

FString dbFile =
FPaths::Combine(dbDirectory, this->GetName() + TEXT(".sqlite"));
this->_pStateDebug =
MakeUnique<Cesium3DTilesSelection::DebugTileStateDatabase>(
TCHAR_TO_UTF8(*dbFile));
#endif

for (UCesiumRasterOverlay* pOverlay : rasterOverlays) {
if (pOverlay->IsActive()) {
pOverlay->AddToTileset();
Expand Down Expand Up @@ -2007,6 +2033,14 @@ void ACesium3DTileset::updateLastViewUpdateResultState(
}
}

#ifdef CESIUM_DEBUG_TILE_STATES
if (this->_pStateDebug && GetWorld()->IsPlayInEditor()) {
this->_pStateDebug->recordAllTileStates(
result.frameNumber,
*this->_pTileset);
}
#endif

if (!this->LogSelectionStats && !this->LogSharedAssetStats) {
return;
}
Expand Down Expand Up @@ -2042,11 +2076,13 @@ void ACesium3DTileset::updateLastViewUpdateResultState(
LogCesium,
Display,
TEXT(
"%s: %d ms, Visited %d, Culled Visited %d, Rendered %d, Culled %d, Occluded %d, Waiting For Occlusion Results %d, Max Depth Visited: %d, Loading-Worker %d, Loading-Main %d, Loaded tiles %g%%"),
"%s: %d ms, Unreal Frame #%d, Tileset Frame: #%d, Visited %d, Culled Visited %d, Rendered %d, Culled %d, Occluded %d, Waiting For Occlusion Results %d, Max Depth Visited: %d, Loading-Worker %d, Loading-Main %d, Loaded tiles %g%%"),
*this->GetName(),
(std::chrono::high_resolution_clock::now() - this->_startTime)
.count() /
1000000,
GFrameCounter,
result.frameNumber,
result.tilesVisited,
result.culledTilesVisited,
result.tilesToRenderThisFrame.size(),
Expand Down
8 changes: 8 additions & 0 deletions Source/CesiumRuntime/Public/Cesium3DTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <vector>
#include "Cesium3DTileset.generated.h"

#ifdef CESIUM_DEBUG_TILE_STATES
#include <Cesium3DTilesSelection/DebugTileStateDatabase.h>
#endif

class UMaterialInterface;
class ACesiumCartographicSelection;
class ACesiumCameraManager;
Expand Down Expand Up @@ -1240,6 +1244,10 @@ class CESIUMRUNTIME_API ACesium3DTileset : public AActor {
private:
TUniquePtr<Cesium3DTilesSelection::Tileset> _pTileset;

#ifdef CESIUM_DEBUG_TILE_STATES
TUniquePtr<Cesium3DTilesSelection::DebugTileStateDatabase> _pStateDebug;
#endif

std::optional<FCesiumFeaturesMetadataDescription>
_featuresMetadataDescription;

Expand Down

0 comments on commit 377444b

Please sign in to comment.