Little fixes from review

This commit is contained in:
bernatx 2022-07-19 11:19:21 +02:00 committed by bernat
parent feb5a572e2
commit 76e96af6c3
8 changed files with 64 additions and 78 deletions

View File

@ -46,7 +46,7 @@ namespace multigpu {
} else {
log_error("tcp accept error:", ec.message());
}
self->OpenSession(timeout, on_opened, on_closed, on_response);
});
}

View File

@ -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();

View File

@ -44,19 +44,20 @@ void Router::SetCallbacks() {
self->DisconnectSession(session);
};
carla::multigpu::Listener::callback_function_type_response on_response = [=](std::shared_ptr<carla::multigpu::Primary> session, carla::Buffer buffer) {
auto self = weak.lock();
if (!self) return;
std::lock_guard<std::mutex> 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<carla::multigpu::Primary> session, carla::Buffer buffer) {
auto self = weak.lock();
if (!self) return;
std::lock_guard<std::mutex> 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());

View File

@ -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;

View File

@ -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<uint32_t, bool> &IsHero);
bool ProcessReplayerFinish(bool bApplyAutopilot, bool bIgnoreHero,
std::unordered_map<uint32_t, bool> &IsHero);
// set the camera position to follow an actor
bool SetCameraPosition(uint32_t Id, FVector Offset, FQuat Rotation);
// set the velocity of the actor

View File

@ -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<bool> 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;
// }
// }

View File

@ -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<TPixel> Converted;
// optional conversion of data
if (Conversor)
{
TRACE_CPUPROFILER_EVENT_SCOPE_STR("Data conversion");
Converted = Conversor(LockedData, Size);
LockedData = reinterpret_cast<void *>(Converted.GetData());
Size = Converted.Num() * Converted.GetTypeSize();
}
auto Stream = Sensor.GetDataStream(Sensor);
auto Buffer = Stream.PopBufferFromPool();
TArray<TPixel> 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<void *>(Converted.GetData());
Size = Converted.Num() * Converted.GetTypeSize();
}
}
};
WritePixelsToBuffer(
*Sensor.CaptureRenderTarget,
carla::sensor::SensorRegistry::get<TSensor *>::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<TSensor *>::type::header_offset,
InRHICmdList,
std::move(FuncForSending));
}
}
}
);
);
// Blocks until the render thread has finished all it's tasks
Sensor.WaitForRenderThreadToFinish();

View File

@ -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<carla::streaming::Token>
BIND_SYNC(get_sensor_token) << [this](carla::streaming::detail::stream_id_type sensor_id) ->
R<carla::streaming::Token>
{
REQUIRE_CARLA_EPISODE();
if (SecondaryServer->HasClientsConnected() && sensor_id > 1)