Enqueue order grouped on the GM
This commit is contained in:
parent
d7cb538b60
commit
dc9a3fd1aa
|
@ -196,7 +196,7 @@ void ACarlaGameModeBase::BeginPlay()
|
|||
// OnBeginFrame
|
||||
// OnEndFrame
|
||||
CaptureAtlasDelegate = FCoreDelegates::OnEndFrame.AddUObject(this, &ACarlaGameModeBase::CaptureAtlas);
|
||||
SendAtlasDelegate = FCoreDelegates::OnEndFrame.AddUObject(this, &ACarlaGameModeBase::SendAtlas);
|
||||
// SendAtlasDelegate = FCoreDelegates::OnEndFrame.AddUObject(this, &ACarlaGameModeBase::SendAtlas);
|
||||
|
||||
}
|
||||
|
||||
|
@ -433,11 +433,18 @@ void ACarlaGameModeBase::CaptureAtlas()
|
|||
|
||||
if(!SceneCaptureSensors.Num()) return;
|
||||
|
||||
// Be sure that the atlas texture is ready
|
||||
if(!IsAtlasTextureValid)
|
||||
{
|
||||
CreateAtlasTextures();
|
||||
}
|
||||
|
||||
// Enqueue the commands to copy the captures to the atlas
|
||||
for(ASceneCaptureSensor* Sensor : SceneCaptureSensors)
|
||||
{
|
||||
Sensor->CopyTextureToAtlas();
|
||||
}
|
||||
|
||||
//if (!AtlasCopyRequestQueue.IsEmpty())
|
||||
//{
|
||||
// UE_LOG(LogCarla, Error, TEXT("ACarlaGameModeBase::CaptureAtlas: request full"));
|
||||
|
@ -448,12 +455,12 @@ void ACarlaGameModeBase::CaptureAtlas()
|
|||
FAtlasCopyRequest* AtlasCopyRequest = GetAtlasCopyRequest();
|
||||
AtlasCopyRequest->ResizeBuffer(AtlasTextureWidth, AtlasTextureHeight);
|
||||
|
||||
// Download Atlas texture
|
||||
ENQUEUE_RENDER_COMMAND(ACarlaGameModeBase_CaptureAtlas)
|
||||
(
|
||||
[This, &CurrentAtlasPixels = AtlasCopyRequest->AtlasImage](FRHICommandListImmediate& RHICmdList) mutable
|
||||
{
|
||||
FTexture2DRHIRef AtlasTexture = This->CamerasAtlasTexture[This->PreviousAtlas];
|
||||
//TArray<FColor>& CurrentAtlasPixels = This->AtlasPixels[This->CurrentAtlas];
|
||||
|
||||
if (!AtlasTexture)
|
||||
{
|
||||
|
@ -461,8 +468,6 @@ void ACarlaGameModeBase::CaptureAtlas()
|
|||
return;
|
||||
}
|
||||
|
||||
// Download Atlas texture
|
||||
|
||||
FIntRect Rect = FIntRect(0, 0, This->AtlasTextureWidth, This->AtlasTextureHeight);
|
||||
|
||||
#if !UE_BUILD_SHIPPING
|
||||
|
@ -470,7 +475,6 @@ void ACarlaGameModeBase::CaptureAtlas()
|
|||
Rect = FIntRect(0, 0, This->SurfaceW, This->SurfaceH);
|
||||
}
|
||||
#endif
|
||||
|
||||
// GDynamicRHI->RHIReadSurfaceData(AtlasTexture, Rect, CurrentAtlasPixels, FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX));
|
||||
|
||||
#if !UE_BUILD_SHIPPING
|
||||
|
@ -484,16 +488,17 @@ void ACarlaGameModeBase::CaptureAtlas()
|
|||
CurrentAtlasPixels,
|
||||
FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX));
|
||||
|
||||
|
||||
This->PreviousAtlas = This->CurrentAtlas;
|
||||
This->CurrentAtlas = (This->CurrentAtlas + 1) & ~kMaxNumTextures;
|
||||
// This->PreviousAtlas = This->CurrentAtlas;
|
||||
// This->CurrentAtlas = (This->CurrentAtlas + 1) & ~kMaxNumTextures;
|
||||
}
|
||||
);
|
||||
|
||||
// AtlasCopyRequest->Start();
|
||||
AtlasCopyRequest->Start();
|
||||
// AtlasCopyRequest->Wait();
|
||||
AtlasCopyRequestQueue.Enqueue(AtlasCopyRequest);
|
||||
|
||||
SendAtlas();
|
||||
|
||||
}
|
||||
|
||||
void ACarlaGameModeBase::SendAtlas()
|
||||
|
@ -505,7 +510,7 @@ void ACarlaGameModeBase::SendAtlas()
|
|||
|
||||
// Be sure that the request has finished
|
||||
|
||||
if(AtlasCopyRequest /* && AtlasCopyRequest->IsComplete() */ )
|
||||
if( AtlasCopyRequest && AtlasCopyRequest->IsComplete() )
|
||||
{
|
||||
//UE_LOG(LogCarla, Warning, TEXT("ACarlaGameModeBase::SendAtlas: DONE"));
|
||||
#if !UE_BUILD_SHIPPING
|
||||
|
|
|
@ -100,10 +100,6 @@ public:
|
|||
return IsAtlasTextureValid;
|
||||
}
|
||||
|
||||
const TArray<FColor>& GetCurrentAtlasPixels() const{
|
||||
return AtlasPixels[CurrentAtlas];
|
||||
}
|
||||
|
||||
FTexture2DRHIRef GetCurrentCamerasAtlasTexture() const{
|
||||
return CamerasAtlasTexture[CurrentAtlas];
|
||||
}
|
||||
|
@ -229,7 +225,6 @@ private:
|
|||
TQueue<FAtlasCopyRequest*> AtlasCopyRequestsQueuePool;
|
||||
|
||||
static const uint32 kMaxNumTextures = 2u; // This has to be POT
|
||||
TArray<FColor> AtlasPixels[kMaxNumTextures]; // TODO: remove
|
||||
TArray<ASceneCaptureSensor*> SceneCaptureSensors;
|
||||
FTexture2DRHIRef CamerasAtlasTexture[kMaxNumTextures];
|
||||
uint32 AtlasTextureWidth = 0u;
|
||||
|
|
|
@ -484,7 +484,7 @@ void ASceneCaptureSensor::BeginPlay()
|
|||
|
||||
Super::BeginPlay();
|
||||
|
||||
CopyTextureDelegate = FCoreDelegates::OnEndFrameRT.AddUObject(this, &ASceneCaptureCamera::CopyTextureToAtlas);
|
||||
//CopyTextureDelegate = FCoreDelegates::OnEndFrame.AddUObject(this, &ASceneCaptureCamera::CopyTextureToAtlas);
|
||||
|
||||
ACarlaGameModeBase* GameMode = Cast<ACarlaGameModeBase>(GetWorld()->GetAuthGameMode());
|
||||
GameMode->AddSceneCaptureSensor(this);
|
||||
|
@ -513,24 +513,11 @@ void ASceneCaptureSensor::EndPlay(const EEndPlayReason::Type EndPlayReason)
|
|||
Super::EndPlay(EndPlayReason);
|
||||
SCENE_CAPTURE_COUNTER = 0u;
|
||||
|
||||
FCoreDelegates::OnEndFrameRT.Remove(CopyTextureDelegate);
|
||||
FCoreDelegates::OnEndFrame.Remove(CopyTextureDelegate);
|
||||
ACarlaGameModeBase* GameMode = Cast<ACarlaGameModeBase>(GetWorld()->GetAuthGameMode());
|
||||
GameMode->RemoveSceneCaptureSensor(this);
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::CopyTextureFromAtlas(const TArray<FColor>& AtlasImage)
|
||||
{
|
||||
|
||||
if(AtlasImage.Num() > 0 && ImageToSend.Num() > 0)
|
||||
{
|
||||
SCOPE_CYCLE_COUNTER(STAT_CarlaSensorBufferCopy);
|
||||
|
||||
const FColor* Source = &AtlasImage[0] + PositionInAtlas.Y;
|
||||
|
||||
ImageToSend = TArray<FColor>(Source, ImageWidth * ImageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::CopyTextureToAtlas()
|
||||
{
|
||||
|
||||
|
@ -570,20 +557,24 @@ void ASceneCaptureSensor::CopyTextureToAtlas()
|
|||
CopyInfo.DestPosition = This->PositionInAtlas; // Where to copy the texture
|
||||
|
||||
RHICmdList.CopyTexture(Texture, AtlasTexture, CopyInfo);
|
||||
|
||||
/*
|
||||
ASceneCaptureSensor& CameraRef = *Camera;
|
||||
FPixelReader::WritePixelsToArray(
|
||||
*(CameraRef.CaptureRenderTarget),
|
||||
CameraRef.Pixels[CameraRef.PreviousTexture],
|
||||
RHICmdList);
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ASceneCaptureSensor::CopyTextureFromAtlas(const TArray<FColor>& AtlasImage)
|
||||
{
|
||||
|
||||
if(AtlasImage.Num() > 0 && ImageToSend.Num() > 0)
|
||||
{
|
||||
SCOPE_CYCLE_COUNTER(STAT_CarlaSensorBufferCopy);
|
||||
|
||||
const FColor* Source = &AtlasImage[0] + PositionInAtlas.Y;
|
||||
|
||||
ImageToSend = TArray<FColor>(Source, ImageWidth * ImageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// -- Local static functions implementations -----------------------------------
|
||||
// =============================================================================
|
||||
|
|
|
@ -270,6 +270,8 @@ public:
|
|||
FPixelReader::SavePixelsToDisk(*CaptureRenderTarget, FilePath);
|
||||
}
|
||||
|
||||
void CopyTextureToAtlas();
|
||||
|
||||
void CopyTextureFromAtlas(const TArray<FColor>& AtlasImage);
|
||||
|
||||
template <typename TSensor>
|
||||
|
@ -297,8 +299,6 @@ protected:
|
|||
|
||||
virtual void SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture) {}
|
||||
|
||||
void CopyTextureToAtlas();
|
||||
|
||||
FDelegateHandle CopyTextureDelegate;
|
||||
|
||||
TArray<FColor> ImageToSend;
|
||||
|
|
Loading…
Reference in New Issue