From 2481fe9716820d1aa7b31c760ddf12cbf448a1be Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Tue, 10 Dec 2024 10:17:21 +1100 Subject: [PATCH] Add support for tile selection state debugging. --- Source/CesiumRuntime/CesiumRuntime.Build.cs | 5 ++- .../CesiumRuntime/Private/Cesium3DTileset.cpp | 38 ++++++++++++++++++- Source/CesiumRuntime/Public/Cesium3DTileset.h | 8 ++++ extern/cesium-native | 2 +- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Source/CesiumRuntime/CesiumRuntime.Build.cs b/Source/CesiumRuntime/CesiumRuntime.Build.cs index 080c0ed6e..56ac39daa 100644 --- a/Source/CesiumRuntime/CesiumRuntime.Build.cs +++ b/Source/CesiumRuntime/CesiumRuntime.Build.cs @@ -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", } ); diff --git a/Source/CesiumRuntime/Private/Cesium3DTileset.cpp b/Source/CesiumRuntime/Private/Cesium3DTileset.cpp index 28f6ea89b..cea903d15 100644 --- a/Source/CesiumRuntime/Private/Cesium3DTileset.cpp +++ b/Source/CesiumRuntime/Private/Cesium3DTileset.cpp @@ -56,6 +56,11 @@ #include #include +#ifdef CESIUM_DEBUG_TILE_STATES +#include "HAL/PlatformFileManager.h" +#include +#endif + FCesium3DTilesetLoadFailure OnCesium3DTilesetLoadFailure{}; #if WITH_EDITOR @@ -77,6 +82,10 @@ ACesium3DTileset::ACesium3DTileset() _pTileset(nullptr), +#ifdef CESIUM_DEBUG_TILE_STATES + _pStateDebug(nullptr), +#endif + _lastTilesRendered(0), _lastWorkerThreadTileLoadQueueLength(0), _lastMainThreadTileLoadQueueLength(0), @@ -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( + TCHAR_TO_UTF8(*dbFile)); +#endif + for (UCesiumRasterOverlay* pOverlay : rasterOverlays) { if (pOverlay->IsActive()) { pOverlay->AddToTileset(); @@ -2011,6 +2037,14 @@ void ACesium3DTileset::updateLastViewUpdateResultState( return; } +#ifdef CESIUM_DEBUG_TILE_STATES + if (this->_pStateDebug && GetWorld()->IsPlayInEditor()) { + this->_pStateDebug->recordAllTileStates( + result.frameNumber, + *this->_pTileset); + } +#endif + if (result.tilesToRenderThisFrame.size() != this->_lastTilesRendered || result.workerThreadTileLoadQueueLength != this->_lastWorkerThreadTileLoadQueueLength || @@ -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(), diff --git a/Source/CesiumRuntime/Public/Cesium3DTileset.h b/Source/CesiumRuntime/Public/Cesium3DTileset.h index 7600f631d..e5b793bde 100644 --- a/Source/CesiumRuntime/Public/Cesium3DTileset.h +++ b/Source/CesiumRuntime/Public/Cesium3DTileset.h @@ -27,6 +27,10 @@ #include #include "Cesium3DTileset.generated.h" +#ifdef CESIUM_DEBUG_TILE_STATES +#include +#endif + class UMaterialInterface; class ACesiumCartographicSelection; class ACesiumCameraManager; @@ -1238,6 +1242,10 @@ class CESIUMRUNTIME_API ACesium3DTileset : public AActor { private: TUniquePtr _pTileset; +#ifdef CESIUM_DEBUG_TILE_STATES + TUniquePtr _pStateDebug; +#endif + std::optional _featuresMetadataDescription; diff --git a/extern/cesium-native b/extern/cesium-native index 1ece56dec..9e7f8522c 160000 --- a/extern/cesium-native +++ b/extern/cesium-native @@ -1 +1 @@ -Subproject commit 1ece56deca0cb068e720ae67ae716fe80ec231ac +Subproject commit 9e7f8522c3ff71ec6c284d954eef11e3b8042e18