Skip to content

Commit

Permalink
Adding support for UE5
Browse files Browse the repository at this point in the history
  • Loading branch information
bombomby committed May 15, 2022
1 parent d89ea8d commit eb392f1
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ Publish/
/Samples/UnrealEnginePlugin/Binaries
/.vs
/samples/UnrealEnginePlugin/GUI/Optick.exe
samples/UnrealEnginePlugin/Source/ThirdParty/Optick/src
*.bak
6 changes: 3 additions & 3 deletions gui/Optick/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("https://optick.dev")]
[assembly: AssemblyProduct("Optick")]
[assembly: AssemblyCopyright("Copyright © Vadim Slyusarev 2020")]
[assembly: AssemblyCopyright("Copyright © Vadim Slyusarev 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.3.0")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
5 changes: 3 additions & 2 deletions samples/UnrealEnginePlugin/OptickPlugin.uplugin
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.3.0",
"VersionName": "1.4.0",
"FriendlyName": "Optick",
"Description": "Super Lightweight Performance Profiler",
"Category": "Performance",
"CreatedBy": "Vadim Slyusarev",
"CreatedByURL": "https://github.com/bombomby/optick",
"DocsURL": "https://github.com/bombomby/optick/wiki/UE4-Optick-Plugin",
"DocsURL": "https://github.com/bombomby/optick/wiki/UE5-Optick-Plugin",
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/95c078f6fa924b2b82fd8f281e04850f",
"SupportURL": "https://github.com/bombomby/optick/issues",
"EngineVersion": "5.0.0",
"CanContainContent": false,
"IsBetaVersion": false,
"Installed": true,
Expand Down
1 change: 1 addition & 0 deletions samples/UnrealEnginePlugin/Source/OptickPlugin.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public OptickPlugin(ReadOnlyTargetRules Target) : base(Target)
"InputCore",
"LevelEditor",
"DesktopPlatform",
"ToolMenus",
}
);
}
Expand Down
60 changes: 45 additions & 15 deletions samples/UnrealEnginePlugin/Source/Private/OptickPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "CoreMinimal.h"
#include "Containers/Ticker.h"
#include "GenericPlatform/GenericPlatformFile.h"
#include "HAL/PlatformFilemanager.h"
#include "HAL/PlatformFileManager.h"
#include "HAL/PlatformProcess.h"
#include "Misc/EngineVersion.h"
#include "Misc/CoreDelegates.h"
Expand All @@ -28,6 +28,7 @@
#include "Editor/LevelEditor/Public/LevelEditor.h"
#include "Editor/UnrealEd/Public/SEditorViewportToolBarMenu.h"
#include "Projects/Public/Interfaces/IPluginManager.h"
#include "ToolMenus.h"
//#include "Windows/WindowsPlatformProcess.h"

#include "OptickStyle.h"
Expand Down Expand Up @@ -74,7 +75,7 @@ class FOptickPlugin : public IOptickPlugin

uint64 OriginTimestamp;

FDelegateHandle TickDelegateHandle;
FTSTicker::FDelegateHandle TickDelegateHandle;
FDelegateHandle StatFrameDelegateHandle;
FDelegateHandle EndFrameRTDelegateHandle;

Expand Down Expand Up @@ -106,6 +107,7 @@ class FOptickPlugin : public IOptickPlugin
TSharedPtr<class FUICommandList> PluginCommands;

void AddToolbarExtension(FToolBarBuilder& ToolbarBuilder);
void RegisterMenus();
#endif

void OnScreenshotProcessed();
Expand Down Expand Up @@ -175,6 +177,26 @@ void FOptickPlugin::AddToolbarExtension(FToolBarBuilder& ToolbarBuilder)
ToolbarBuilder.EndSection();
}

void FOptickPlugin::RegisterMenus()
{
FToolMenuOwnerScoped OwnerScoped(this);

if (UToolMenu* ProfileMenu = UToolMenus::Get()->ExtendMenu("MainFrame.MainMenu.Tools"))
{
FToolMenuSection& Section = ProfileMenu->AddSection("Optick Profiler", FText::FromString(TEXT("Optick Profiler")));
Section.AddMenuEntry("OpenOptickProfiler",
LOCTEXT("OpenOptickProfiler_Label", "Open Optick Profiler"),
LOCTEXT("OpenOptickProfiler_Desc", "Open Optick Profiler"),
FSlateIcon(FOptickStyle::GetStyleSetName(), "Optick.PluginAction"),
FUIAction(FExecuteAction::CreateRaw(this, &FOptickPlugin::OnOpenGUI), FCanExecuteAction())
);
}
else
{
UE_LOG(OptickLog, Error, TEXT("Can't find 'MainFrame.MainMenu.Tools' menu section"))
}
}

#endif

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -240,7 +262,7 @@ void FOptickPlugin::StartupModule()
GPUThreadStorage.EventStorage = Optick::RegisterStorage(TCHAR_TO_ANSI(*FPlatformMisc::GetPrimaryGPUBrand()), (uint64_t)-1, Optick::ThreadMask::GPU);

// Subscribing for Ticker
TickDelegateHandle = FTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateRaw(this, &FOptickPlugin::Tick));
TickDelegateHandle = FTSTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateRaw(this, &FOptickPlugin::Tick));

// Register Optick callback
Optick::SetStateChangedCallback(OnOptickStateChanged);
Expand All @@ -252,18 +274,31 @@ void FOptickPlugin::StartupModule()
FOptickStyle::ReloadTextures();
FOptickCommands::Register();

RegisterMenus();

PluginCommands = MakeShareable(new FUICommandList);

PluginCommands->MapAction(
FOptickCommands::Get().PluginAction,
FExecuteAction::CreateRaw(this, &FOptickPlugin::OnOpenGUI),
FCanExecuteAction());

FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
ExtensionManager = LevelEditorModule.GetToolBarExtensibilityManager();
ToolbarExtender = MakeShareable(new FExtender);
ToolbarExtension = ToolbarExtender->AddToolBarExtension("Game", EExtensionHook::After, PluginCommands, FToolBarExtensionDelegate::CreateLambda([this](FToolBarBuilder& ToolbarBuilder) { AddToolbarExtension(ToolbarBuilder); }) );
ExtensionManager->AddExtender(ToolbarExtender);
//FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
//ExtensionManager = LevelEditorModule.GetToolBarExtensibilityManager();
//ToolbarExtender = MakeShareable(new FExtender);
//ToolbarExtension = ToolbarExtender->AddToolBarExtension("Game", EExtensionHook::After, PluginCommands, FToolBarExtensionDelegate::CreateLambda([this](FToolBarBuilder& ToolbarBuilder) { AddToolbarExtension(ToolbarBuilder); }) );
//ExtensionManager->AddExtender(ToolbarExtender);

//if (UToolMenu* ToolbarMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar"))
//{
// FToolMenuSection& Section = ToolbarMenu->AddSection("Optick Profiler", FText::FromString(TEXT("Optick Profiler")));
// FToolMenuEntry& Entry = Section.AddEntry(FToolMenuEntry::InitToolBarButton(FOptickCommands::Get().PluginAction));
// Entry.SetCommandList(PluginCommands);
//}
//else
//{
// UE_LOG(OptickLog, Error, TEXT("Can't find 'LevelEditor.LevelEditorToolBar' menu section"))
//}
}
#endif

Expand All @@ -276,8 +311,8 @@ void FOptickPlugin::StartupModule()
void FOptickPlugin::ShutdownModule()
{
// Remove delegate
FTicker::GetCoreTicker().RemoveTicker(TickDelegateHandle);
FCoreDelegates::OnEndFrameRT.Remove(EndFrameRTDelegateHandle);
FTSTicker::GetCoreTicker().RemoveTicker(TickDelegateHandle);
FCoreDelegates::OnEndFrameRT.Remove(EndFrameRTDelegateHandle);

// Stop capture if needed
StopCapture();
Expand Down Expand Up @@ -408,13 +443,8 @@ bool FOptickPlugin::UpdateCalibrationTimestamp(FRealtimeGPUProfilerFrameImpl* Fr

if (Frame->TimestampCalibrationQuery.IsValid())
{
#if UE_4_27_OR_LATER
CalibrationTimestamp.GPUMicroseconds = Frame->TimestampCalibrationQuery->GPUMicroseconds[GPUIndex];
CalibrationTimestamp.CPUMicroseconds = Frame->TimestampCalibrationQuery->CPUMicroseconds[GPUIndex];
#else
CalibrationTimestamp.GPUMicroseconds = Frame->TimestampCalibrationQuery->GPUMicroseconds;
CalibrationTimestamp.CPUMicroseconds = Frame->TimestampCalibrationQuery->CPUMicroseconds;
#endif
}

if (CalibrationTimestamp.GPUMicroseconds == 0 || CalibrationTimestamp.CPUMicroseconds == 0) // Unimplemented platforms, or invalid on the first frame
Expand Down
136 changes: 69 additions & 67 deletions samples/UnrealEnginePlugin/Source/Private/OptickUE4Classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@
#include "ProfilingDebugging/TracingProfiler.h"
#include "Runtime/Launch/Resources/Version.h"

#define UE_4_27_OR_LATER (ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 27)


#define REALTIME_GPU_PROFILER_EVENT_TRACK_FRAME_NUMBER (TRACING_PROFILER || DO_CHECK)

/*-----------------------------------------------------------------------------
FRealTimeGPUProfilerEvent class
-----------------------------------------------------------------------------*/
class FRealtimeGPUProfilerEventImpl
{
public:
static const uint64 InvalidQueryResult = 0xFFFFFFFFFFFFFFFFull;

public:
/*-----------------------------------------------------------------------------
FRealTimeGPUProfilerEvent class
-----------------------------------------------------------------------------*/
class FRealtimeGPUProfilerEventImpl
{
public:
static const uint64 InvalidQueryResult = 0xFFFFFFFFFFFFFFFFull;

public:
bool GatherQueryResults(FRHICommandListImmediate& RHICmdList)
{
//QUICK_SCOPE_CYCLE_COUNTER(STAT_SceneUtils_GatherQueryResults);
Expand Down Expand Up @@ -113,66 +110,71 @@ class FRealtimeGPUProfilerEventImpl
uint32 GetFrameNumber() const
{
return FrameNumber;
}

}

TStaticArray<uint64, MAX_NUM_GPUS> StartResultMicroseconds;
TStaticArray<uint64, MAX_NUM_GPUS> EndResultMicroseconds;

FRHIPooledRenderQuery StartQuery;
FRHIPooledRenderQuery EndQuery;

FName Name;
STAT(FName StatName;)

FRHIGPUMask GPUMask;

uint32 FrameNumber;

#if DO_CHECK
bool bInsideQuery;
#endif
};

class FRealtimeGPUProfilerFrameImpl
{
public:
struct FGPUEventTimeAggregate
{
uint32 ExclusiveTimeUs;
uint32 InclusiveTimeUs;
};

TStaticArray<uint64, MAX_NUM_GPUS> EndResultMicroseconds;

FRHIPooledRenderQuery StartQuery;
FRHIPooledRenderQuery EndQuery;

FName Name;
STAT(FName StatName;)

FRHIGPUMask GPUMask;

uint32 FrameNumber;

#if DO_CHECK
bool bInsideQuery;
#endif
};

class FRealtimeGPUProfilerFrameImpl
{
public:
struct FGPUEventTimeAggregate
{
uint32 ExclusiveTimeUs;
uint32 InclusiveTimeUs;
};

uint64 CPUFrameStartTimestamp;
FTimestampCalibrationQueryRHIRef TimestampCalibrationQuery;

static constexpr uint32 GPredictedMaxNumEvents = 100u;
static constexpr uint32 GPredictedMaxNumEventsUpPow2 = 128u;
static constexpr uint32 GPredictedMaxStackDepth = 32u;

int32 NextEventIdx;
int32 OverflowEventCount;
int32 NextResultPendingEventIdx;

uint32& QueryCount;
FRenderQueryPoolRHIRef RenderQueryPool;

TArray<FRealtimeGPUProfilerEventImpl, TInlineAllocator<GPredictedMaxNumEvents>> GpuProfilerEvents;
TArray<int32, TInlineAllocator<GPredictedMaxNumEvents>> GpuProfilerEventParentIndices;
TArray<int32, TInlineAllocator<GPredictedMaxStackDepth>> EventStack;
TArray<FGPUEventTimeAggregate, TInlineAllocator<GPredictedMaxNumEvents>> EventAggregates;

static constexpr uint32 GPredictedMaxNumEvents = 100u;
static constexpr uint32 GPredictedMaxNumEventsUpPow2 = 128u;
static constexpr uint32 GPredictedMaxStackDepth = 32u;

int32 NextEventIdx;
int32 OverflowEventCount;
int32 NextResultPendingEventIdx;

uint32& QueryCount;
FRenderQueryPoolRHIRef RenderQueryPool;

TArray<FRealtimeGPUProfilerEventImpl, TInlineAllocator<GPredictedMaxNumEvents>> GpuProfilerEvents;
TArray<int32, TInlineAllocator<GPredictedMaxNumEvents>> GpuProfilerEventParentIndices;
TArray<int32, TInlineAllocator<GPredictedMaxStackDepth>> EventStack;
TArray<FGPUEventTimeAggregate, TInlineAllocator<GPredictedMaxNumEvents>> EventAggregates;
};

class FRealtimeGPUProfilerImpl
{
public:
TArray<FRealtimeGPUProfilerFrameImpl*> Frames;
int32 WriteBufferIndex;
int32 ReadBufferIndex;
uint32 WriteFrameNumber;
uint32 QueryCount;
FRenderQueryPoolRHIRef RenderQueryPool;
bool bStatGatheringPaused;
bool bInBeginEndBlock;
class FRealtimeGPUProfilerImpl
{
public:
TArray<FRealtimeGPUProfilerFrameImpl*> Frames;
int32 WriteBufferIndex;
int32 ReadBufferIndex;
uint32 WriteFrameNumber;
uint32 QueryCount;
FRenderQueryPoolRHIRef RenderQueryPool;
bool bStatGatheringPaused;
bool bInBeginEndBlock;
bool bLocked;

#if GPUPROFILERTRACE_ENABLED
FRealtimeGPUProfilerHistoryByDescription HistoryByDescription;
#endif
};

static_assert(sizeof(FRealtimeGPUProfilerImpl) == sizeof(FRealtimeGPUProfiler), "Size mismatch");
Expand Down
7 changes: 6 additions & 1 deletion src/optick_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ namespace Optick
Allocator(const Allocator<U>&) {}
template<typename U> struct rebind { typedef Allocator<U> other; };

typename std::allocator<T>::value_type* allocate(typename std::allocator<T>::size_type n, const typename std::allocator<void>::value_type* = 0)
typename std::allocator<T>::value_type* allocate(typename std::allocator<T>::size_type n)
{
return reinterpret_cast<typename std::allocator<T>::value_type*>(Memory::Alloc(n * sizeof(T)));
}

typename std::allocator<T>::value_type* allocate(typename std::allocator<T>::size_type n, const typename std::allocator<void>::value_type*)
{
return reinterpret_cast<typename std::allocator<T>::value_type*>(Memory::Alloc(n * sizeof(T)));
}
Expand Down
3 changes: 1 addition & 2 deletions tools/Publish.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@echo off

call Publish_Main.bat
call Publish_UE4.bat 4.26
call Publish_UE4.bat 4.27
call Publish_UnrealEngine.bat 5.0
4 changes: 2 additions & 2 deletions tools/Publish_UE4.bat → tools/Publish_UnrealEngine.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ rem MsBuild gui/OptickApp_vs2017.sln /t:Rebuild /p:Configuration=Release /p:Plat

for /f %%i in ('powershell "(Get-Item -path gui\Bin\Release\x64\Optick.exe).VersionInfo.ProductVersion"') do set VERSION=%%i

set UNREAL_VERSION=4.27
set UNREAL_VERSION=5.0

IF "%~1" == "" GOTO skipversion
set UNREAL_VERSION="%~1"
:skipversion

set VERSION_NAME=%VERSION:~0,-2%_UE4Plugin%UNREAL_VERSION%
set VERSION_NAME=%VERSION:~0,-2%_UE_Plugin_%UNREAL_VERSION%

xcopy /Y gui\Bin\Release\x64\Optick.exe samples\UnrealEnginePlugin\GUI\*

Expand Down

0 comments on commit eb392f1

Please sign in to comment.