diff --git a/LibCarla/source/carla/multigpu/listener.cpp b/LibCarla/source/carla/multigpu/listener.cpp index a2e709668..751b06835 100644 --- a/LibCarla/source/carla/multigpu/listener.cpp +++ b/LibCarla/source/carla/multigpu/listener.cpp @@ -46,7 +46,7 @@ namespace multigpu { } else { log_error("tcp accept error:", ec.message()); } - + self->OpenSession(timeout, on_opened, on_closed, on_response); }); } diff --git a/LibCarla/source/carla/multigpu/primaryCommands.cpp b/LibCarla/source/carla/multigpu/primaryCommands.cpp index 71f5b5498..c237f90f0 100644 --- a/LibCarla/source/carla/multigpu/primaryCommands.cpp +++ b/LibCarla/source/carla/multigpu/primaryCommands.cpp @@ -39,7 +39,8 @@ void PrimaryCommands::SendLoadMap(std::string map) { // send to who the router wants the request for a token token_type PrimaryCommands::SendGetToken(carla::streaming::detail::stream_id_type sensor_id) { log_info("asking for a token"); - carla::Buffer buf((carla::Buffer::value_type *) &sensor_id, (size_t) sizeof(carla::streaming::detail::stream_id_type)); + carla::Buffer buf((carla::Buffer::value_type *) &sensor_id, + (size_t) sizeof(carla::streaming::detail::stream_id_type)); auto fut = _router->WriteToNext(MultiGPUCommand::GET_TOKEN, std::move(buf)); auto response = fut.get(); diff --git a/LibCarla/source/carla/multigpu/router.cpp b/LibCarla/source/carla/multigpu/router.cpp index a7db4759c..6ea700903 100644 --- a/LibCarla/source/carla/multigpu/router.cpp +++ b/LibCarla/source/carla/multigpu/router.cpp @@ -44,19 +44,20 @@ void Router::SetCallbacks() { self->DisconnectSession(session); }; - carla::multigpu::Listener::callback_function_type_response on_response = [=](std::shared_ptr session, carla::Buffer buffer) { - auto self = weak.lock(); - if (!self) return; - std::lock_guard lock(self->_mutex); - auto prom =self-> _promises.find(session.get()); - if (prom != self->_promises.end()) { - log_info("Got data from secondary (with promise): ", buffer.size()); - prom->second->set_value({session, std::move(buffer)}); - self->_promises.erase(prom); - } else { - log_info("Got data from secondary (without promise): ", buffer.size()); - } - }; + carla::multigpu::Listener::callback_function_type_response on_response = + [=](std::shared_ptr session, carla::Buffer buffer) { + auto self = weak.lock(); + if (!self) return; + std::lock_guard lock(self->_mutex); + auto prom =self-> _promises.find(session.get()); + if (prom != self->_promises.end()) { + log_info("Got data from secondary (with promise): ", buffer.size()); + prom->second->set_value({session, std::move(buffer)}); + self->_promises.erase(prom); + } else { + log_info("Got data from secondary (without promise): ", buffer.size()); + } + }; _commander.set_router(shared_from_this()); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.cpp index 2a691c99c..02e1008c8 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.cpp @@ -103,11 +103,6 @@ void FFrameData::PlayFrameData( MappedId.erase(EventDel.DatabaseId); } - for (const CarlaRecorderEventParent &EventParent : EventsParent.GetEvents()) - { - // ProcessReplayerEventParent(MappedId[EventParent.DatabaseId], MappedId[EventParent.DatabaseIdParent]); - } - for (const CarlaRecorderPosition &Position : Positions.GetPositions()) { CarlaRecorderPosition Pos = Position; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.h index b3578ffa5..013697aa8 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/FrameData.h @@ -128,7 +128,8 @@ private: // replay event for parenting actors bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId); // reposition actors - bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime); + bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, + CarlaRecorderPosition Pos2, double Per, double DeltaTime); // replay event for traffic light state bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State); // set the animation for Vehicles @@ -140,7 +141,8 @@ private: // set scene lights void ProcessReplayerLightScene(CarlaRecorderLightScene LightScene); // replay finish - bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, std::unordered_map &IsHero); + bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero, + std::unordered_map &IsHero); // set the camera position to follow an actor bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation); // set the velocity of the actor diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp index b48b60820..df67c5f30 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.cpp @@ -59,7 +59,9 @@ void FPixelReader::WritePixelsToBuffer( EPixelFormat BackBufferPixelFormat = Texture->GetFormat(); { TRACE_CPUPROFILER_EVENT_SCOPE_STR("EnqueueCopy"); - BackBufferReadback->EnqueueCopy(RHICmdList, Texture, FResolveRect(0, 0, BackBufferSize.X, BackBufferSize.Y)); + BackBufferReadback->EnqueueCopy(RHICmdList, + Texture, + FResolveRect(0, 0, BackBufferSize.X, BackBufferSize.Y)); } // workaround to force RHI with Vulkan to refresh the fences state in the middle of frame @@ -147,20 +149,3 @@ TFuture FPixelReader::SavePixelsToDisk( FHighResScreenshotConfig &HighResScreenshotConfig = GetHighResScreenshotConfig(); return HighResScreenshotConfig.ImageWriteQueue->Enqueue(MoveTemp(ImageTask)); } - -// void FPixelReader::WritePixelsToBuffer( -// UTextureRenderTarget2D &RenderTarget, -// uint32 Offset, -// FRHICommandListImmediate &InRHICmdList, -// FPixelReader::Payload FuncForSending, -// bool use16BitFormat) -// { -// TRACE_CPUPROFILER_EVENT_SCOPE_STR("WritePixelsToBuffer"); -// check(IsInRenderingThread()); - -// if (IsVulkanPlatform(GMaxRHIShaderPlatform) || IsD3DPlatform(GMaxRHIShaderPlatform, false)) -// { -// WritePixelsToBuffer(RenderTarget, Offset, InRHICmdList, std::move(FuncForSending)); -// return; -// } -// } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h index bb4684976..0a9b2005a 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/PixelReader.h @@ -110,48 +110,49 @@ void FPixelReader::SendPixelsInRenderThread(TSensor &Sensor, bool use16BitFormat /// @todo Can we make sure the sensor is not going to be destroyed? if (!Sensor.IsPendingKill()) { - FPixelReader::Payload FuncForSending = [&Sensor, Conversor = std::move(Conversor)](void *LockedData, uint32 Size, uint32 Offset) - { - if (Sensor.IsPendingKill()) return; + FPixelReader::Payload FuncForSending = + [&Sensor, Conversor = std::move(Conversor)](void *LockedData, uint32 Size, uint32 Offset) + { + if (Sensor.IsPendingKill()) return; - TArray Converted; - - // optional conversion of data - if (Conversor) - { - TRACE_CPUPROFILER_EVENT_SCOPE_STR("Data conversion"); - Converted = Conversor(LockedData, Size); - LockedData = reinterpret_cast(Converted.GetData()); - Size = Converted.Num() * Converted.GetTypeSize(); - } - - auto Stream = Sensor.GetDataStream(Sensor); - auto Buffer = Stream.PopBufferFromPool(); + TArray Converted; - { - TRACE_CPUPROFILER_EVENT_SCOPE_STR("Buffer Copy"); - Buffer.copy_from(Offset, boost::asio::buffer(LockedData, Size)); - } - { - // send - TRACE_CPUPROFILER_EVENT_SCOPE_STR("Sending buffer"); - if(Buffer.data()) + // optional conversion of data + if (Conversor) { - SCOPE_CYCLE_COUNTER(STAT_CarlaSensorStreamSend); - TRACE_CPUPROFILER_EVENT_SCOPE_STR("Stream Send"); - Stream.Send(Sensor, std::move(Buffer)); + TRACE_CPUPROFILER_EVENT_SCOPE_STR("Data conversion"); + Converted = Conversor(LockedData, Size); + LockedData = reinterpret_cast(Converted.GetData()); + Size = Converted.Num() * Converted.GetTypeSize(); } - } - }; - - WritePixelsToBuffer( - *Sensor.CaptureRenderTarget, - carla::sensor::SensorRegistry::get::type::header_offset, - InRHICmdList, - std::move(FuncForSending)); + + auto Stream = Sensor.GetDataStream(Sensor); + auto Buffer = Stream.PopBufferFromPool(); + + { + TRACE_CPUPROFILER_EVENT_SCOPE_STR("Buffer Copy"); + Buffer.copy_from(Offset, boost::asio::buffer(LockedData, Size)); + } + { + // send + TRACE_CPUPROFILER_EVENT_SCOPE_STR("Sending buffer"); + if(Buffer.data()) + { + SCOPE_CYCLE_COUNTER(STAT_CarlaSensorStreamSend); + TRACE_CPUPROFILER_EVENT_SCOPE_STR("Stream Send"); + Stream.Send(Sensor, std::move(Buffer)); + } + } + }; + + WritePixelsToBuffer( + *Sensor.CaptureRenderTarget, + carla::sensor::SensorRegistry::get::type::header_offset, + InRHICmdList, + std::move(FuncForSending)); + } } - } - ); + ); // Blocks until the render thread has finished all it's tasks Sensor.WaitForRenderThreadToFinish(); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index b7e882dfb..4c10a4385 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -767,7 +767,8 @@ void FCarlaServer::FPimpl::BindActions() return GEngine->Exec(Episode->GetWorld(), UTF8_TO_TCHAR(cmd.c_str())); }; - BIND_SYNC(get_sensor_token) << [this](carla::streaming::detail::stream_id_type sensor_id) -> R + BIND_SYNC(get_sensor_token) << [this](carla::streaming::detail::stream_id_type sensor_id) -> + R { REQUIRE_CARLA_EPISODE(); if (SecondaryServer->HasClientsConnected() && sensor_id > 1)