Skip to content
Snippets Groups Projects
Commit ddd5a83c authored by David Gilbert's avatar David Gilbert :bug:
Browse files

added custom stats events for unreal insights - makes performance debugging much easier

parent 213c1d6f
Branches
No related tags found
No related merge requests found
Showing with 119 additions and 29 deletions
......@@ -45,6 +45,7 @@ void ULineInstancedStaticMeshComponent::BeginPlay()
FPrimitiveSceneProxy* ULineInstancedStaticMeshComponent::CreateSceneProxy()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("ULineInstancedStaticMeshComponent::CreateSceneProxy"))
FPrimitiveSceneProxy* Proxy = Super::CreateSceneProxy();
......@@ -82,6 +83,7 @@ FPrimitiveSceneProxy* ULineInstancedStaticMeshComponent::CreateSceneProxy()
// todo currently copies the array, save a reference/ptr instead
void ULineInstancedStaticMeshComponent::InitLineSegments(TArray<int32> Indices, int32 NumberOfSegmentsPerLine, float LineW)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("ULineInstancedStaticMeshComponent::InitLineSegments"))
ClearInstances();
......@@ -149,6 +151,8 @@ void ULineInstancedStaticMeshComponent::InitLineSegments(TArray<int32> Indices,
void ULineInstancedStaticMeshComponent::UpdateLines()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("ULineInstancedStaticMeshComponent::UpdateLines"))
LineNumber = LaserIndices.Num();
for (int32 Line = 0; Line < LineNumber; Line++)
......@@ -175,6 +179,8 @@ void ULineInstancedStaticMeshComponent::UpdateLines()
void ULineInstancedStaticMeshComponent::UpdateLUT(TArray<FColor> ColorMap)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("ULineInstancedStaticMeshComponent::UpdateLUT"))
if (DynamicLaserMaterial != NULL)
{
......@@ -197,6 +203,8 @@ void ULineInstancedStaticMeshComponent::UpdateLUT(TArray<FColor> ColorMap)
void ULineInstancedStaticMeshComponent::SetLaserMaterial(UMaterialInstanceDynamic * Mat)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("ULineInstancedStaticMeshComponent::SetLaserMaterial"))
// 1 for now, could be #Lines if we want multicolored lines
ColorLUT = UTexture2D::CreateTransient(1, LineNumber, EPixelFormat::PF_R32_FLOAT);
ColorLUT->UpdateResource();
......
......@@ -129,6 +129,8 @@ void AOptiXPlayerCameraManager::EndPlay(const EEndPlayReason::Type EndPlayReason
void AOptiXPlayerCameraManager::Tick(float DeltaSeconds)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXPlayerCameraManager::Tick"))
Super::Tick(DeltaSeconds);
if (C == 2)
{
......@@ -155,6 +157,7 @@ void AOptiXPlayerCameraManager::Init()
void AOptiXPlayerCameraManager::CaptureCubemap()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXPlayerCameraManager::CaptureCubemap"))
// 2D
TArray<FVector> Directions =
......
......@@ -35,6 +35,8 @@ optix::Context UOptiXContext::Init()
void UOptiXContext::UpdateVariables()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXContext::UpdateVariables"))
check(IsInRenderingThread());
for (UOptiXTransform* T : TransformMap)
......@@ -917,6 +919,8 @@ void UOptiXContext::Compile()
void UOptiXContext::Launch(int32 EntryPointIndex, uint64 ImageWidth)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXContext::Launch1D"))
try
{
NativeContext->launch(EntryPointIndex, ImageWidth);
......@@ -932,6 +936,7 @@ void UOptiXContext::Launch(int32 EntryPointIndex, uint64 ImageWidth)
void UOptiXContext::Launch(int32 EntryPointIndex, uint64 ImageWidth, uint64 ImageHeight)
{
//UE_LOG(OptiXPluginContext, Warning, TEXT("Child count: %i"), GeometryGroupMap["top_object"]->GetChildCount());
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXContext::Launch2D"))
try
{
......@@ -947,6 +952,8 @@ void UOptiXContext::Launch(int32 EntryPointIndex, uint64 ImageWidth, uint64 Imag
void UOptiXContext::Launch(int32 EntryPointIndex, uint64 ImageWidth, uint64 ImageHeight, uint64 ImageDepth)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXContext::Launch3D"))
try
{
NativeContext->launch(EntryPointIndex, ImageWidth, ImageHeight, ImageDepth);
......
......@@ -89,6 +89,8 @@ void FOptiXContextManager::PreRenderView_RenderThread(FRHICommandListImmediate &
// Called on render thread at the start of rendering.
void FOptiXContextManager::PreRenderViewFamily_RenderThread(FRHICommandListImmediate & RHICmdList, FSceneViewFamily & InViewFamily)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::PreRenderViewFamily_RenderThread"))
//UE_LOG(LogTemp, Warning, TEXT("PreRenderViewFamily_RenderThread"));
if (!bIsInitialized && bStartTracing)
{
......@@ -106,6 +108,7 @@ void FOptiXContextManager::PostRenderViewFamily_RenderThread(FRHICommandListImme
void FOptiXContextManager::PostRenderView_RenderThread(FRHICommandListImmediate & RHICmdList, FSceneView & InView)
{
//UE_LOG(LogTemp, Warning, TEXT("VPM: PostRenderViewFamily_RenderThread %s"), *InView.ViewMatrices.GetViewProjectionMatrix().ToString());
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::PostRenderView_RenderThread"))
if (!bIsInitialized && !bClearToLaunch && !OptiXContext.IsValid() && !bStartTracing)
{
......@@ -258,6 +261,7 @@ void FOptiXContextManager::PostRenderView_RenderThread(FRHICommandListImmediate
void FOptiXContextManager::LaunchLaser()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::LaunchLaser"))
if (/*bSceneChanged && */ bLaserIsInitialized && !CVarDisableLaserTrace.GetValueOnRenderThread())
{
if (LaserActor.IsValid())
......@@ -265,6 +269,9 @@ void FOptiXContextManager::LaunchLaser()
LaserActor->OptiXLaserComponent->UpdateOptiXContextVariables();
}
// Analyze this
// uuuuuuuuh
static uint32 RandomSeed = 0;
OptiXContext->SetUint("random_frame_seed", RandomSeed++);
......@@ -272,12 +279,15 @@ void FOptiXContextManager::LaunchLaser()
bIsTracing.AtomicSet(true);
OptiXContext->Launch(1, 50, 50, 20);
bIsTracing.AtomicSet(false);
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::LaunchLaser::CudaScope"))
if (Resources[4] == NULL)
{
return;
}
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::LaunchLaser::CudaScope::MapAndCopy"))
cudaGraphicsMapResources(1, Resources + 4, 0);
PrintLastCudaError("cudaGraphicsMapResources");
......@@ -292,6 +302,9 @@ void FOptiXContextManager::LaunchLaser()
cudaGraphicsSubResourceGetMappedArray(&CuArrayIntersections, CudaResourceIntersections, 0, 0);
PrintLastCudaError("cudaGraphicsSubResourceGetMappedArray");
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::LaunchLaser::CudaScope::Memcpy"))
cudaMemcpy2DToArray(
CuArrayIntersections, // dst array
0, 0, // offset
......@@ -299,20 +312,28 @@ void FOptiXContextManager::LaunchLaser()
LaserBufferWidth * 4 * sizeof(float), LaserBufferHeight, // extent
cudaMemcpyDeviceToDevice); // kind
PrintLastCudaError("cudaMemcpy2DToArray");
}
}
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::LaunchLaser::CudaScope::Unmap"))
cudaGraphicsUnmapResources(1, Resources + 4, 0);
PrintLastCudaError("cudaGraphicsUnmapResources");
}
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::LaunchLaser::BroadcastFinish"))
bSceneChanged.AtomicSet(false);
LaserTraceFinishedEvent.Broadcast();
}
}
}
bool FOptiXContextManager::IsActiveThisFrame(FViewport * InViewport) const
{
//UE_LOG(LogTemp, Warning, TEXT("IsActiveThisFrame"));
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::IsActiveThisFrame"))
bool bDisableTrace = CVarDisableTrace.GetValueOnGameThread(); // Bad naming fix me
return OptiXContext.IsValid() && !bDisableTrace && bStartTracing /* && !bEndPlay*//* && TrackingSystem->IsHeadTrackingAllowed()*/;
......@@ -320,6 +341,8 @@ bool FOptiXContextManager::IsActiveThisFrame(FViewport * InViewport) const
void FOptiXContextManager::RenderOrthoPass()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::RenderOrthoPass"))
OptiXContext->SetMatrix("invViewProjection", OrthoMatrix.Inverse());
OptiXContext->SetMatrix("viewProjection", OrthoMatrix);
......@@ -377,6 +400,7 @@ void FOptiXContextManager::RenderOrthoPass()
void FOptiXContextManager::Init()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::Init"))
// TODO Fix me there's still an optix error in there somewhere
//if (CubemapSampler.IsValid())
......@@ -424,6 +448,7 @@ void FOptiXContextManager::SceneChangedCallback()
void FOptiXContextManager::InitContext()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::InitContext"))
UE_LOG(LogTemp, Display, TEXT("Initializing Context in ContextManager"));
......@@ -481,6 +506,7 @@ void FOptiXContextManager::InitContext()
void FOptiXContextManager::InitRendering()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::InitRendering"))
UE_LOG(LogTemp, Display, TEXT("Initializing Rendering in ContextManager"));
......@@ -766,6 +792,8 @@ void FOptiXContextManager::InitCubemap()
int32 FOptiXContextManager::RequestCubemapId()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::RequestCubemapId"))
if (UnallocatedCubemapIds.IsEmpty())
{
return 0;
......@@ -777,6 +805,8 @@ int32 FOptiXContextManager::RequestCubemapId()
void FOptiXContextManager::DeleteCubemapId(int32 Id)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::DeleteCubemapId"))
if (Id <= 10)
{
UE_LOG(LogTemp, Warning, TEXT("Trying to free a cubemap that isn't there."));
......@@ -788,6 +818,8 @@ void FOptiXContextManager::DeleteCubemapId(int32 Id)
void FOptiXContextManager::UpdateCubemapBuffer(FRHICommandListImmediate & RHICmdList)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::UpdateCubemapBuffer"))
if (!CameraActor.IsValid() || bValidCubemap)
{
return;
......@@ -840,6 +872,8 @@ void FOptiXContextManager::UpdateCubemapBuffer(FRHICommandListImmediate & RHICmd
void FOptiXContextManager::AddCubemapToBuffer(int32 CubemapId, int32 SamplerId)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::AddCubemapToBuffer"))
int32* Data = static_cast<int32*>(CubemapsInputBuffer->MapNative());
Data[CubemapId] = SamplerId;
CubemapsInputBuffer->Unmap();
......
......@@ -158,6 +158,8 @@ void UOptiXLaserComponent::OnUpdateTransform(EUpdateTransformFlags UpdateTransfo
void UOptiXLaserComponent::UpdateOptiXContextVariables()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::UpdateOptiXContextVariables"))
check(IsInRenderingThread());
if (bUpdateQueued)
......
......@@ -47,6 +47,8 @@ void AOptiXLaserDetectorActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
void AOptiXLaserDetectorActor::Tick(float DeltaTime)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXLaserDetectorActor::Tick"))
Super::Tick(DeltaTime);
OnLaserTraceFinished();
}
......@@ -89,6 +91,7 @@ void AOptiXLaserDetectorActor::Init()
void AOptiXLaserDetectorActor::OnLaserTraceFinished()
{
//UE_LOG(LogTemp, Warning, TEXT("lasertracefinished"));
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXLaserDetectorActor::OnLaserTraceFinished"))
if (bIsEnabled)
{
......@@ -99,6 +102,7 @@ void AOptiXLaserDetectorActor::OnLaserTraceFinished()
void AOptiXLaserDetectorActor::RenderDataToTarget()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXLaserDetectorActor::RenderDataToTarget"))
// Let's try something else:
......@@ -135,6 +139,8 @@ void AOptiXLaserDetectorActor::RenderDataToTarget()
void AOptiXLaserDetectorActor::Clear()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXLaserDetectorActor::Clear"))
uint32 Size = static_cast<int32>(OptiXLaserTargetComponent->TargetRes);
TArray<FColor> Black;
......
......@@ -164,6 +164,7 @@ float UOptiXLaserTargetComponent::GetMaxFromBuffer()
void UOptiXLaserTargetComponent::UpdateBufferData()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXLaserTargetComponent::UpdateBufferData"))
check(IsInRenderingThread());
......
......@@ -44,6 +44,8 @@ void UOptiXLensComponent::BeginPlay()
void UOptiXLensComponent::UpdateOptiXComponentVariables()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXLensComponent::UpdateOptiXComponentVariables"))
check(IsInRenderingThread());
......@@ -205,6 +207,7 @@ void UOptiXLensComponent::InitCubemap(FRHICommandListImmediate & RHICmdList)
void UOptiXLensComponent::UpdateCubemap(FRHICommandListImmediate & RHICmdList)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXLensComponent::UpdateCubemap"))
UE_LOG(LogTemp, Display, TEXT("Updating Cubemap"));
......
......@@ -66,6 +66,8 @@ void UOptiXObjectComponent::RegisterOptiXComponent()
void UOptiXObjectComponent::QueueOptiXContextUpdate()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXObjectComponent::QueueOptiXContextUpdate"))
if (!bUpdateQueued)
{
FOptiXModule::Get().GetOptiXContextManager()->QueueComponentUpdate(this);
......@@ -82,6 +84,8 @@ void UOptiXObjectComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
void UOptiXObjectComponent::OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport/* = ETeleportType::None*/)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXObjectComponent::OnUpdateTransform"))
Super::OnUpdateTransform(EUpdateTransformFlags::SkipPhysicsUpdate, Teleport);
UpdateOptiXComponent();
......@@ -323,6 +327,8 @@ void UOptiXCubemapComponent::SetUpdateQueued(bool UpdateQueued)
void UOptiXCubemapComponent::RequestCubemapUpdate()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UOptiXCubemapComponent::RequestCubemapUpdate"))
CaptureScene();
FOptiXModule::Get().GetOptiXContextManager()->RequestCubemapUpdate(this);
}
......@@ -27,6 +27,8 @@ void AOptiXVRPawn::BeginPlay()
// Called every frame
void AOptiXVRPawn::Tick(float DeltaTime)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXVRPawn::Tick"))
Super::Tick(DeltaTime);
}
......@@ -40,6 +42,8 @@ void AOptiXVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone
void AOptiXVRPawn::UpdateTranslation(UPrimitiveComponent* Interaction)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXVRPawn::UpdateTranslation"))
if (GrabbedLever == NULL)
{
return;
......@@ -105,6 +109,7 @@ UMaterialInstanceDynamic* AOptiXVRPawn::GetMIDOrtho()
void AOptiXVRPawn::RequestOrthoPass(const FMinimalViewInfo& ViewInfo)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXVRPawn::RequestOrthoPass"))
FSceneViewProjectionData ProjectionData;
ProjectionData.ViewOrigin = ViewInfo.Location;
......@@ -123,6 +128,8 @@ void AOptiXVRPawn::RequestOrthoPass(const FMinimalViewInfo& ViewInfo)
UStaticMeshComponent * AOptiXVRPawn::GetNearestMeshComponent(UPrimitiveComponent * Other)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXVRPawn::GetNearestMeshComponent"))
TArray<UPrimitiveComponent*> OverlappingComponents;
Other->GetOverlappingComponents(OverlappingComponents);
......@@ -148,6 +155,7 @@ UStaticMeshComponent * AOptiXVRPawn::GetNearestMeshComponent(UPrimitiveComponent
AActor * AOptiXVRPawn::GetActorNearHand(UPrimitiveComponent * Hand)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("AOptiXVRPawn::GetActorNearHand"))
TArray<AActor*> OverlappingActors;
Hand->GetOverlappingActors(OverlappingActors);
......
......@@ -376,6 +376,7 @@ void ASelectableActorBase::BeginPlay()
void ASelectableActorBase::Tick(float DeltaTime)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("ASelectableActorBase::Tick"))
Super::Tick(DeltaTime);
......@@ -483,6 +484,7 @@ void ASelectableActorBase::DeleteActor()
void ASelectableActorBase::SetRodPosition(FVector TablePosition)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("ASelectableActorBase::SetRodPosition"))
// Flip socket?
if (Socket->GetComponentLocation().Z > GetActorLocation().Z)
......
......@@ -248,6 +248,8 @@ private:
void InitOptiXComponents(FRHICommandListImmediate & RHICmdList)
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::InitOptiXComponents"))
// Possibly dangerous? Use limited for instead of while in case something goes wrong and we deadlock
for (uint32 i = 0; i < 100 && !ComponentsToInitializeQueue.IsEmpty(); i++)
{
......@@ -261,6 +263,8 @@ private:
void UpdateOptiXComponentVariables()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::UpdateOptiXComponentVariables"))
for (uint32 i = 0; i < 100 && !ComponentsToUpdateQueue.IsEmpty(); i++)
{
IOptiXComponentInterface* Component;
......@@ -277,6 +281,8 @@ private:
void RemovePendingChildrenFromGroups()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::RemovePendingChildrenFromGroups"))
for (uint32 i = 0; i < 100 && !GroupChildrenToRemoveQueue.IsEmpty(); i++)
{
TPair<optix::Group, uint32> Pair;
......@@ -311,6 +317,8 @@ private:
void DestroyOptiXObjects()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::DestroyOptiXObjects"))
for (uint32 i = 0; i < 100 && !AccelerationsToDeleteQueue.IsEmpty(); i++)
{
optix::Acceleration NativeObj;
......@@ -489,6 +497,7 @@ private:
void UpdateRequestedCubemaps(FRHICommandListImmediate & RHICmdList)
{
// update only the first for now, shouldn't be more than 1 in queue anyway:
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::UpdateRequestedCubemaps"))
if (!CubemapComponentsToUpdateQueue.IsEmpty())
{
......@@ -504,6 +513,7 @@ private:
void CleanupOptiXOnEnd()
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("FOptiXContextManager::CleanupOptiXOnEnd"))
UE_LOG(LogTemp, Display, TEXT("Starting Cleanup in Context Manager"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment