Skip to content

Commit

Permalink
- Optimized/delayed calls to UpdateEditorProperties:
Browse files Browse the repository at this point in the history
  they are now limited to a maximum of once per component/per manager tick.
  This reduces unnecessary calls (non selected HDAs) or duplicate calls to the function.
- Added extra profiler macros the plugin code.
- Wrapped calls to CommitGeo in a FHoudiniEngineUtils function that automates scoped profiling.
  • Loading branch information
dpernuit committed Jul 9, 2024
1 parent 5e078e3 commit a4086d3
Show file tree
Hide file tree
Showing 25 changed files with 248 additions and 129 deletions.
10 changes: 8 additions & 2 deletions Source/HoudiniEngine/Private/HoudiniEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,8 @@ FHoudiniEngine::FinishTaskSlateNotification(const FText& InText)

bool FHoudiniEngine::UpdateCookingNotification(const FText& InText, const bool bExpireAndFade)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngine::UpdateCookingNotification);

#if WITH_EDITOR
TimeSinceLastPersistentNotification = 0.0;

Expand All @@ -1445,13 +1447,17 @@ bool FHoudiniEngine::UpdateCookingNotification(const FText& InText, const bool b
if (HoudiniBrush.IsValid())
Info.Image = HoudiniBrush.Get();


CookingNotificationPtr = FSlateNotificationManager::Get().AddNotification(Info);
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngine::UpdateCookingNotification__AddNotification);
CookingNotificationPtr = FSlateNotificationManager::Get().AddNotification(Info);
}
}

TSharedPtr<SNotificationItem> NotificationItem = CookingNotificationPtr.Pin();
if (NotificationItem.IsValid())
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngine::UpdateCookingNotification__UpdateNotification);

// Update the persistent notification.
NotificationItem->SetText(InText);

Expand Down
29 changes: 23 additions & 6 deletions Source/HoudiniEngine/Private/HoudiniEngineManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ FHoudiniEngineManager::Tick(float DeltaTime)
// Update the tick time for this component
CurrentComponent->LastTickTime = dNow;
}

// See if we need to update this HDA's details panel
if (CurrentComponent->bNeedToUpdateEditorProperties)
{
// Only do an update if the HAC is selected
if(CurrentComponent->IsOwnerSelected())
FHoudiniEngineUtils::UpdateEditorProperties(true);
CurrentComponent->bNeedToUpdateEditorProperties = false;
}
}

// Handle Asset delete
Expand Down Expand Up @@ -483,7 +492,7 @@ FHoudiniEngineManager::ProcessComponent(UHoudiniAssetComponent* HAC)
{
// Trigger a details panel update if the Houdini asset actor is selected
if (HAC->IsOwnerSelected())
FHoudiniEngineUtils::UpdateEditorProperties(true);
HAC->bNeedToUpdateEditorProperties = true;

// Finished refreshing UI of one HDA.
FHoudiniEngine::Get().RefreshUIDisplayedWhenPauseCooking();
Expand Down Expand Up @@ -652,7 +661,7 @@ FHoudiniEngineManager::ProcessComponent(UHoudiniAssetComponent* HAC)
if(!bCookStarted)
{
// Just refresh editor properties?
FHoudiniEngineUtils::UpdateEditorProperties(true);
HAC->bNeedToUpdateEditorProperties = true;

// TODO: Check! update state?
HAC->SetAssetState(EHoudiniAssetState::None);
Expand Down Expand Up @@ -881,6 +890,8 @@ FHoudiniEngineManager::StartTaskAssetInstantiation(UHoudiniAsset* HoudiniAsset,
bool
FHoudiniEngineManager::UpdateInstantiating(UHoudiniAssetComponent* HAC, EHoudiniAssetState& NewState )
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineManager::UpdateInstantiating);

check(HAC);

// Will return true if the asset's state need to be updated
Expand Down Expand Up @@ -1059,6 +1070,8 @@ FHoudiniEngineManager::StartTaskAssetCooking(
bool bOutputTemplateGeos,
FGuid& OutTaskGUID)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineManager::StartTaskAssetCooking);

// Make sure we have a valid session before attempting anything
if (!FHoudiniEngine::Get().GetSession())
return false;
Expand Down Expand Up @@ -1294,8 +1307,8 @@ FHoudiniEngineManager::PostCook(UHoudiniAssetComponent* HAC, const bool& bSucces

FHoudiniEngine::Get().UpdateCookingNotification(FText::FromString(DisplayName + " :\nFinished processing outputs"), true);

// Trigger a details panel update
FHoudiniEngineUtils::UpdateEditorProperties(true);
// Indicate we want to trigger a details panel update
HAC->bNeedToUpdateEditorProperties = true;

// If any outputs have HoudiniStaticMeshes, and if timer based refinement is enabled on the HAC,
// set the RefineMeshesTimer and ensure BuildStaticMeshesForAllHoudiniStaticMeshes is bound to
Expand Down Expand Up @@ -1328,8 +1341,8 @@ FHoudiniEngineManager::PostCook(UHoudiniAssetComponent* HAC, const bool& bSucces

if (bNeedsToTriggerViewportUpdate && GEditor)
{
// We need to manually update the vieport with HoudiniMeshProxies
// if not, modification made in H with the two way debugger wont be visible in Unreal until the vieports gets focus
// We need to manually update the viewport with HoudiniMeshProxies
// if not, modification made in H with the two way debugger wont be visible in Unreal until the viewports gets focus
GEditor->RedrawAllViewports(false);
}

Expand Down Expand Up @@ -1361,6 +1374,8 @@ FHoudiniEngineManager::UpdateProcess(UHoudiniAssetComponent* HAC)
bool
FHoudiniEngineManager::StartTaskAssetRebuild(const HAPI_NodeId& InAssetId, FGuid& OutTaskGUID)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineManager::StartTaskAssetRebuild);

// Check this HAC doesn't already have a running task
if (OutTaskGUID.IsValid())
return false;
Expand Down Expand Up @@ -1389,6 +1404,8 @@ FHoudiniEngineManager::StartTaskAssetRebuild(const HAPI_NodeId& InAssetId, FGuid
bool
FHoudiniEngineManager::StartTaskAssetDelete(const HAPI_NodeId& InNodeId, FGuid& OutTaskGUID, bool bShouldDeleteParent)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineManager::StartTaskAssetDelete);

if (InNodeId < 0)
return false;

Expand Down
21 changes: 21 additions & 0 deletions Source/HoudiniEngine/Private/HoudiniEngineUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ FHoudiniEngineUtils::LocateLibHAPIInRegistry(
bool
FHoudiniEngineUtils::LoadHoudiniAsset(const UHoudiniAsset * HoudiniAsset, HAPI_AssetLibraryId& OutAssetLibraryId)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::LoadHoudiniAsset);

OutAssetLibraryId = -1;

if (!IsValid(HoudiniAsset))
Expand Down Expand Up @@ -2326,6 +2328,8 @@ FHoudiniEngineUtils::GatherAllAssetOutputs(
const bool bOutputTemplatedGeos,
TArray<HAPI_NodeId>& OutOutputNodes)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::GatherAllAssetOutputs);

OutOutputNodes.Empty();

// Ensure the asset has a valid node ID
Expand Down Expand Up @@ -2978,6 +2982,8 @@ FHoudiniEngineUtils::ConvertHoudiniRotEulerToUnrealVector(const TArray<float>& I
bool
FHoudiniEngineUtils::UploadHACTransform(UHoudiniAssetComponent* HAC)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::UploadHACTransform);

if (!HAC || !HAC->bUploadTransformsToHoudiniEngine)
return false;

Expand Down Expand Up @@ -3196,6 +3202,8 @@ FHoudiniEngineUtils::UpdateEditorProperties(const bool bInForceFullUpdate)

void FHoudiniEngineUtils::UpdateBlueprintEditor(UHoudiniAssetComponent* HAC)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::UpdateBlueprintEditor);

if (!IsInGameThread())
{
// We need to be in the game thread to trigger editor properties update
Expand All @@ -3214,6 +3222,8 @@ void FHoudiniEngineUtils::UpdateBlueprintEditor(UHoudiniAssetComponent* HAC)
void
FHoudiniEngineUtils::UpdateEditorProperties_Internal(const bool bInForceFullUpdate)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::UpdateEditorProperties_Internal);

#if WITH_EDITOR
#define HOUDINI_USE_DETAILS_FOCUS_HACK 1

Expand Down Expand Up @@ -6928,6 +6938,8 @@ FHoudiniEngineUtils::CreateNode(
const HAPI_Bool& bInCookOnCreation,
HAPI_NodeId* OutNewNodeId)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::CreateNode);

// Call HAPI::CreateNode
HAPI_Result Result = FHoudiniApi::CreateNode(
FHoudiniEngine::Get().GetSession(),
Expand Down Expand Up @@ -7725,6 +7737,13 @@ FHoudiniEngineUtils::MoveActorToLevel(AActor* InActor, ULevel* InDesiredLevel)
return true;
}

HAPI_Result
FHoudiniEngineUtils::HapiCommitGeo(const HAPI_NodeId& InNodeId)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::HapiCommitGeo);
return FHoudiniApi::CommitGeo(FHoudiniEngine::Get().GetSession(), InNodeId);
}

bool
FHoudiniEngineUtils::HapiCookNode(const HAPI_NodeId& InNodeId, HAPI_CookOptions* InCookOptions, const bool& bWaitForCompletion)
{
Expand Down Expand Up @@ -7784,6 +7803,8 @@ FHoudiniEngineUtils::HapiCookNode(const HAPI_NodeId& InNodeId, HAPI_CookOptions*
HAPI_Result
FHoudiniEngineUtils::CreateInputNode(const FString& InNodeLabel, HAPI_NodeId& OutNodeId, const int32 InParentNodeId)
{
TRACE_CPUPROFILER_EVENT_SCOPE(FHoudiniEngineUtils::CreateInputNode);

HAPI_NodeId NodeId = -1;
HAPI_Session const* const Session = FHoudiniEngine::Get().GetSession();

Expand Down
3 changes: 3 additions & 0 deletions Source/HoudiniEngine/Private/HoudiniEngineUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ struct HOUDINIENGINE_API FHoudiniEngineUtils
// if bWaitForCompletion is true, this call will be blocking until the cook is finished
static bool HapiCookNode(const HAPI_NodeId& InNodeId, HAPI_CookOptions* InCookOptions = nullptr, const bool& bWaitForCompletion = false);

// Wrapper for CommitGeo - adds a profiler scope wrapper
static HAPI_Result HapiCommitGeo(const HAPI_NodeId& InNodeId);

// Return a specified HAPI status string.
static const FString GetStatusString(HAPI_StatusType status_type, HAPI_StatusVerbosity verbosity);

Expand Down
Loading

0 comments on commit a4086d3

Please sign in to comment.