From 1733b5c785ae631ca28d2731a8557e055a1bc99a Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Wed, 16 Oct 2019 09:35:53 +0300 Subject: [PATCH] Do frame copy instead of swap --- components/renderers/cpp/include/ftl/cuda/mask.hpp | 1 + components/renderers/cpp/src/splat_render.cpp | 2 +- components/rgbd-sources/include/ftl/rgbd/frame.hpp | 5 +++++ components/rgbd-sources/src/frame.cpp | 13 +++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/renderers/cpp/include/ftl/cuda/mask.hpp b/components/renderers/cpp/include/ftl/cuda/mask.hpp index 4e359e504..3f49f3bfc 100644 --- a/components/renderers/cpp/include/ftl/cuda/mask.hpp +++ b/components/renderers/cpp/include/ftl/cuda/mask.hpp @@ -9,6 +9,7 @@ namespace cuda { */ class Mask { public: + __device__ inline Mask() : v_(0) {} __device__ explicit inline Mask(int v) : v_(v) {} #ifdef __CUDACC__ __device__ inline Mask(const ftl::cuda::TextureObject<int> &m, int x, int y) : v_(m.tex2D(x,y)) {} diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp index 5829ff055..80a6f2a1b 100644 --- a/components/renderers/cpp/src/splat_render.cpp +++ b/components/renderers/cpp/src/splat_render.cpp @@ -399,7 +399,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out) { if (aligned_source >= 0 && aligned_source < scene_->frames.size()) { // FIXME: Output may not be same resolution as source! cudaSafeCall(cudaStreamSynchronize(stream_)); - scene_->frames[aligned_source].swapTo(Channel::Depth + Channel::Colour, out); + scene_->frames[aligned_source].copyTo(Channel::Depth + Channel::Colour, out); return true; } diff --git a/components/rgbd-sources/include/ftl/rgbd/frame.hpp b/components/rgbd-sources/include/ftl/rgbd/frame.hpp index 5e38fe5cc..b08673c97 100644 --- a/components/rgbd-sources/include/ftl/rgbd/frame.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/frame.hpp @@ -59,6 +59,11 @@ public: void swapChannels(ftl::codecs::Channel, ftl::codecs::Channel); + /** + * Does a host or device memory copy into the given frame. + */ + void copyTo(ftl::codecs::Channels, Frame &); + /** * Create a channel with a given format. This will discard any existing * data associated with the channel and ensure all data structures and diff --git a/components/rgbd-sources/src/frame.cpp b/components/rgbd-sources/src/frame.cpp index 851e75af7..212ca5537 100644 --- a/components/rgbd-sources/src/frame.cpp +++ b/components/rgbd-sources/src/frame.cpp @@ -85,6 +85,19 @@ void Frame::swapChannels(ftl::codecs::Channel a, ftl::codecs::Channel b) { m1.tex = std::move(temptex); } +void Frame::copyTo(ftl::codecs::Channels channels, Frame &f) { + f.reset(); + + // For all channels in this frame object + for (auto c : channels_) { + // Should we copy this channel? + if (channels.has(c)) { + if (isCPU(c)) get<cv::Mat>(c).copyTo(f.create<cv::Mat>(c)); + else get<cv::cuda::GpuMat>(c).copyTo(f.create<cv::cuda::GpuMat>(c)); + } + } +} + template<> cv::Mat& Frame::get(ftl::codecs::Channel channel) { if (channel == Channel::None) { DLOG(WARNING) << "Cannot get the None channel from a Frame"; -- GitLab