From d528243112a373269e8e93ecf0c68c8118882ead Mon Sep 17 00:00:00 2001 From: codeffee Date: Thu, 16 Jul 2020 13:07:35 +0200 Subject: [PATCH] Changed measure scope. --- .../Carla/Source/Carla/Sensor/PixelReader.cpp | 11 ++++++++--- .../Source/Carla/Sensor/SceneCaptureSensor.cpp | 18 ++++++++++++++---- .../Source/Carla/Sensor/SceneCaptureSensor.h | 2 ++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp index f36797311..9506be0c0 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp @@ -194,8 +194,9 @@ void FPixelReader::WritePixelsToArray( { check(IsInRenderingThread()); - auto RenderResource = - static_cast(RenderTarget.Resource); + + const FTextureRenderTarget2DResource* RenderResource = + static_cast(RenderTarget.Resource); FTexture2DRHIRef Texture = RenderResource->GetRenderTargetTexture(); if (!Texture) { @@ -205,9 +206,13 @@ void FPixelReader::WritePixelsToArray( FIntPoint Rect = RenderResource->GetSizeXY(); - InRHICmdList.ReadSurfaceData( + { + + SCOPE_CYCLE_COUNTER(STAT_CarlaSensorReadRT); + InRHICmdList.ReadSurfaceData( Texture, FIntRect(0, 0, Rect.X, Rect.Y), Pixels, FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)); + } } \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp index 14b356b4e..e01cea198 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.cpp @@ -493,7 +493,8 @@ void ASceneCaptureSensor::BeginPlay() Pixels[i].Init(FColor(), ImageWidth * ImageHeight); } - CaptureDelegate = FCoreDelegates::OnEndFrame.AddUObject(this, &ASceneCaptureCamera::Capture); + //CaptureDelegate = FCoreDelegates::OnBeginFrame.AddUObject(this, &ASceneCaptureCamera::SetViewport); + CaptureDelegate = FCoreDelegates::OnEndFrameRT.AddUObject(this, &ASceneCaptureCamera::Capture); } void ASceneCaptureSensor::Tick(float DeltaTime) @@ -520,17 +521,28 @@ void ASceneCaptureSensor::EndPlay(const EEndPlayReason::Type EndPlayReason) FCoreDelegates::OnEndFrame.Remove(CaptureDelegate); } +void ASceneCaptureSensor::SetViewport() +{ + ENQUEUE_RENDER_COMMAND(ASceneCaptureSensor_SetViewport) + ( + [](FRHICommandListImmediate& RHICmdList) mutable + { + RHICmdList.SetViewport(0, 0, 0.0f, 800, 600, 0.0f); + } + ); +} + void ASceneCaptureSensor::Capture() { check(CaptureRenderTarget != nullptr); + check(IsInRenderingThread()); ASceneCaptureSensor* This = this; ENQUEUE_RENDER_COMMAND(ASceneCaptureSensor_SendPixelsInRenderThread) ( [This, Sensors=CaptureSensors](FRHICommandListImmediate& RHICmdList) mutable { - NumCaptureSensors++; if( NumCaptureSensors < Sensors.Num() ) @@ -542,8 +554,6 @@ void ASceneCaptureSensor::Capture() { if (Camera && Camera-> HasActorBegunPlay() && !Camera->IsPendingKill()) { - SCOPE_CYCLE_COUNTER(STAT_CarlaSensorReadRT); - ASceneCaptureSensor& CameraRef = *Camera; FPixelReader::WritePixelsToArray( *(CameraRef.CaptureRenderTarget), diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.h index fd1f0a8d0..d177423ff 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/SceneCaptureSensor.h @@ -281,6 +281,8 @@ protected: uint32 Offset = 0u; + void SetViewport(); + void Capture(); template