Files
UnrealEngineUWP/Engine/Plugins/Runtime/Metasound/Source/MetasoundEditor/Private/SMetasoundRenderStats.cpp
phil popp 56737d13eb MetaSound Graph Render Cost
The main elements of this change are:
- Incorporation of "Relative Render Cost" to the AudioDevice in order to do more nuanced voice limiting
- Added a method for tracking a RenderCost in MetaSounds
- Live information on RenderCost is displayed in the MetaSound editor when a sound is previewed

There was some small cleanup as well
- Moved the GraphHierarhcy MetaSound environment variable
- Renamed the MetaSound Environment Variable  TransmissionID to InstanceID
- Put CPU cost and Render Cost into their own widget in the MS editor.

#jira UE-215467
#rb Rob.Gay, Jimmy.Smith

[CL 34020333 by phil popp in ue5-main branch]
2024-05-30 19:36:18 -04:00

81 lines
2.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SMetasoundRenderStats.h"
#include "Components/AudioComponent.h"
#include "Containers/UnrealString.h"
#include "Editor.h"
#include "Internationalization/Text.h"
#include "MetasoundSource.h"
#include "MetasoundGenerator.h"
#include "Templates/SharedPointer.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/SBoxPanel.h"
#include "Widgets/Text/STextBlock.h"
void SMetaSoundRenderStats::Construct(const FArguments& InArgs)
{
SVerticalBox::Construct(SVerticalBox::FArguments());
AddSlot()
.HAlign(HAlign_Left)
[
SAssignNew(RenderStatsCostWidget, STextBlock)
.Visibility(EVisibility::HitTestInvisible)
.TextStyle(FAppStyle::Get(), "Graph.ZoomText")
.ColorAndOpacity(FLinearColor(1, 1, 1, 0.30f))
];
AddSlot()
.HAlign(HAlign_Left)
[
SAssignNew(RenderStatsCPUWidget, STextBlock)
.Visibility(EVisibility::HitTestInvisible)
.TextStyle(FAppStyle::Get(), "Graph.ZoomText")
.ColorAndOpacity(FLinearColor(1, 1, 1, 0.30f))
];
}
void SMetaSoundRenderStats::Update(bool bIsPlaying, const UMetaSoundSource* InSource)
{
using namespace Metasound;
// Reset maximum values when play restarts
if (bIsPlaying && !bPreviousIsPlaying)
{
MaxRelativeRenderCost = 0.f;
MaxCPUCoreUtilization = 0;
}
bPreviousIsPlaying = bIsPlaying;
if (RenderStatsCPUWidget.IsValid() && RenderStatsCostWidget.IsValid())
{
double CPUCoreUtilization = 0;
float RelativeRenderCost = 0.f;
// Find generator for playing preview component.
if (bIsPlaying && InSource)
{
if (const UAudioComponent* PreviewComponent = GEditor->GetPreviewAudioComponent())
{
TSharedPtr<FMetasoundGenerator> Generator = InSource->GetGeneratorForAudioComponent(PreviewComponent->GetAudioComponentID()).Pin();
if (Generator.IsValid())
{
// Update render stats
CPUCoreUtilization = Generator->GetCPUCoreUtilization();
MaxCPUCoreUtilization = FMath::Max(MaxCPUCoreUtilization, CPUCoreUtilization);
RelativeRenderCost = Generator->GetRelativeRenderCost();
MaxRelativeRenderCost = FMath::Max(MaxRelativeRenderCost, RelativeRenderCost);
}
}
}
// Display updated render stats.
FString CPUCoreUtilizationString = FString::Printf(TEXT("%3.2f%% (%3.2f%% Max) CPU Core"), 100. * CPUCoreUtilization, 100. * MaxCPUCoreUtilization);
RenderStatsCPUWidget->SetText(FText::FromString(CPUCoreUtilizationString));
FString RenderCostString = FString::Printf(TEXT("%3.2f (%3.2f Max) Relative Render Cost"), RelativeRenderCost, MaxRelativeRenderCost);
RenderStatsCostWidget->SetText(FText::FromString(RenderCostString));
}
}