My Project
ClientReceiverFb.h
Go to the documentation of this file.
1 // Copyright 2023 DreamWorks Animation LLC
2 // SPDX-License-Identifier: Apache-2.0
3 
15 #pragma once
16 
17 #include <mcrt_messages/ProgressiveFrame.h>
18 #include <scene_rdl2/common/grid_util/Fb.h>
19 #include <scene_rdl2/common/grid_util/LatencyLog.h>
20 #include <scene_rdl2/common/grid_util/Parser.h>
21 #include <scene_rdl2/common/math/Viewport.h>
22 #include <scene_rdl2/common/rec_time/RecTime.h>
23 
24 namespace mcrt_dataio {
25 
26 class ClientReceiverConsoleDriver;
27 class TimingRecorderHydra;
28 
30 {
31 public:
32  using CallBackStartedCondition = std::function<void()>;
33  using CallBackGenericComment = std::function<void(const std::string &comment)>;
34  using CallBackSendMessage = std::function<bool(const arras4::api::MessageContentConstPtr msg)>;
35  using Parser = scene_rdl2::grid_util::Parser;
36 
37  enum class DenoiseEngine : int {
38  OPTIX,
39  OPEN_IMAGE_DENOISE
40  };
41 
42  enum class DenoiseMode : int {
43  DISABLE, // disable denoise
44  ENABLE, // enable denoise but does not use any additional input
45  ENABLE_W_ALBEDO, // enable denoise with ALBEDO input if available
46  ENABLE_W_NORMAL, // enable denoise with NORMAL input if available
47  ENABLE_W_ALBEDO_NORMAL // enable denoise with ALBEDO and NORMAL input if available
48  };
49 
50  enum class BackendStat : int {
51  IDLE, // idle mode
52  RENDER_PREP_RUN, // executing renderPrep phase
53  RENDER_PREP_CANCEL, // middle of canceling renderPrep
54  MCRT, // executing MCRT phase
55  UNKNOWN
56  };
57 
58  enum class SenderMachineId : int {
59  DISPATCH = -1,
60  MERGE = -2,
61  UNKNOWN = -3
62  };
63 
66 
69  ClientReceiverFb(const ClientReceiverFb&) = delete;
70 
71  //------------------------------
72 
88  bool decodeProgressiveFrame(const mcrt::ProgressiveFrame& message,
89  const bool doParallel,
90  const CallBackStartedCondition& callBackFuncAtStartedCondition,
91  const CallBackGenericComment& callBackForGenericComment = nullptr);
92 
93  //------------------------------
94 
100  size_t getViewId() const;
101 
108  uint32_t getFrameId() const;
109 
141  mcrt::BaseFrame::Status getStatus() const;
142 
170  BackendStat getBackendStat() const;
171 
189  float getRenderPrepProgress() const;
190 
193  float getProgress() const;
194 
197  bool isCoarsePass() const;
198 
201  uint64_t getSnapshotStartTime() const;
202 
207  float getElapsedSecFromStart(); // return sec
208 
211  uint64_t getRecvMsgSize() const; // return last message size as byte
212 
215  unsigned getWidth() const;
216 
219  unsigned getHeight() const;
220 
223  const scene_rdl2::math::Viewport& getRezedViewport() const; // closed viewport
224 
227  bool getRoiViewportStatus() const;
228 
231  const scene_rdl2::math::Viewport& getRoiViewport() const; // closed viewport
232 
235  bool getPixelInfoStatus() const;
236 
240  const std::string& getPixelInfoName() const;
241 
244  int getPixelInfoNumChan() const;
245 
248  bool getHeatMapStatus() const;
249 
253  const std::string& getHeatMapName() const;
254 
257  int getHeatMapNumChan() const;
258 
261  bool getWeightBufferStatus() const;
262 
266  const std::string& getWeightBufferName() const;
267 
270  int getWeightBufferNumChan() const;
271 
274  bool getRenderBufferOddStatus() const;
275 
278  int getRenderBufferOddNumChan() const;
279 
282  unsigned getTotalRenderOutput() const;
283 
287  const std::string& getRenderOutputName(const unsigned id) const;
288 
292  int getRenderOutputNumChan(const unsigned id) const;
293 
297  int getRenderOutputNumChan(const std::string& aovName) const;
298 
302  bool getRenderOutputClosestFilter(const unsigned id) const;
303 
307  bool getRenderOutputClosestFilter(const std::string& aovName) const;
308 
309  //------------------------------
310 
313  void setDenoiseEngine(DenoiseEngine engine);
314 
317  DenoiseEngine getDenoiseEngine() const;
318 
346  void setBeautyDenoiseMode(DenoiseMode mode);
347 
350  DenoiseMode getBeautyDenoiseMode() const;
351 
359  const std::string& getErrorMsg() const;
360 
361  //------------------------------
362 
383  bool getBeautyRgb888(std::vector<unsigned char>& rgbFrame,
384  const bool top2bottom = false,
385  const bool isSrgb = false);
386 
406  bool getPixelInfoRgb888(std::vector<unsigned char>& rgbFrame,
407  const bool top2bottom = false,
408  const bool isSrgb = false);
409 
429  bool getHeatMapRgb888(std::vector<unsigned char>& rgbFrame,
430  const bool top2bottom = false,
431  const bool isSrgb = false);
432 
453  bool getWeightBufferRgb888(std::vector<unsigned char>& rgbFrame,
454  const bool top2bottom = false,
455  const bool isSrgb = false);
456 
474  bool getBeautyAuxRgb888(std::vector<unsigned char>& rgbFrame,
475  const bool top2bottom = false,
476  const bool isSrgb = false);
477 
581  bool getRenderOutputRgb888(const unsigned id,
582  std::vector<unsigned char>& rgbFrame,
583  const bool top2bottom = false,
584  const bool isSrgb = false,
585  const bool closestFilterDepthOutput = false);
586 
614  bool getRenderOutputRgb888(const std::string& aovName,
615  std::vector<unsigned char>& rgbFrame,
616  const bool top2bottom = false,
617  const bool isSrgb = false,
618  const bool closestFilterDepthOutput = false);
619 
620  //------------------------------
621 
639  bool getBeauty(std::vector<float>& rgba,
640  const bool top2bottom = false); // 4 channels per pixel
641 
659  bool getPixelInfo(std::vector<float>& data, const bool top2bottom = false); // 1 channel per pixel
660 
677  bool getHeatMap(std::vector<float>& data, const bool top2bottom = false); // 1 channel per pixel
678 
694  bool getWeightBuffer(std::vector<float>& data, const bool top2bottom = false); // 1 channel per pixel
695 
711  bool getBeautyOdd(std::vector<float>& rgba, const bool top2bottom = false); // 4 channels per pixel
712 
785  int getRenderOutput(const unsigned id,
786  std::vector<float>& data,
787  const bool top2bottom = false,
788  const bool closestFilterDepthOutput = false);
789 
817  int getRenderOutput(const std::string& aovName,
818  std::vector<float>& data,
819  const bool top2bottom = false,
820  const bool closestFilterDepthOutput = false);
821 
822  //------------------------------
823 
831  // Return value is Vec4f and [0]=R, [1]=G, [2]=B and [3]=A
832  scene_rdl2::math::Vec4f getPixBeauty(const int sx, const int sy) const;
833 
841  float getPixPixelInfo(const int sx, const int sy) const;
842 
850  float getPixHeatMap(const int sx, const int sy) const;
851 
859  float getPixWeightBuffer(const int sx, const int sy) const;
860 
868  // Return value is Vec4f and [0]=R, [1]=G, [2]=B and [3]=A
869  scene_rdl2::math::Vec4f getPixBeautyOdd(const int sx, const int sy) const;
870 
883  int getPixRenderOutput(const unsigned id, const int sx, const int sy,
884  std::vector<float>& out) const; // return numChan
885 
898  int getPixRenderOutput(const std::string& aovName, const int sx, const int sy,
899  std::vector<float>& out) const; // return numChan
900 
934  std::string showPix(const int sx, const int sy, const std::string& aovName) const;
935 
936  //------------------------------
937 
964  const scene_rdl2::grid_util::LatencyLog &getLatencyLog() const;
965 
979  const scene_rdl2::grid_util::LatencyLogUpstream& getLatencyLogUpstream() const;
980 
981  //------------------------------
982 
999  void setInfoRecInterval(const float sec); // 0.0 = disable infoRec logic
1000 
1011  void setInfoRecDisplayInterval(const float sec);
1012 
1044  void setInfoRecFileName(const std::string& fileName);
1045 
1052  void updateStatsMsgInterval(); // update message interval info
1053 
1060  void updateStatsProgressiveFrame(); // update progressiveFrame message info
1061 
1077  bool getStats(const float intervalSec, std::string& outMsg);
1078 
1086  float getRecvImageDataFps();
1087 
1098  unsigned getFbActivityCounter();
1099 
1100  //------------------------------
1101 
1110  void consoleAutoSetup(const CallBackSendMessage& sendMessage);
1111 
1121  void consoleEnable(const unsigned short port,
1122  const CallBackSendMessage& sendMessage);
1123 
1132 
1138  Parser& getParser();
1139 
1145  static std::string showDenoiseEngine(const DenoiseEngine& engine);
1146 
1152  static std::string showDenoiseMode(const DenoiseMode& mode);
1153 
1159  static std::string showBackendStat(const BackendStat& stat);
1160 
1161  //------------------------------
1162 
1173  void setTimingRecorderHydra(std::shared_ptr<TimingRecorderHydra> ptr);
1174 
1202  int getReceivedImageSenderMachineId() const;
1203 
1212  static std::string showSenderMachineId(int machineId);
1213 
1214  //------------------------------
1215 
1224  void setTelemetryOverlayReso(unsigned width, unsigned height);
1225 
1231  void setTelemetryOverlayActive(bool sw);
1232 
1238  bool getTelemetryOverlayActive() const;
1239 
1246 
1247 protected:
1248  class Impl;
1249  std::unique_ptr<Impl> mImpl;
1250 }; // ClientReceiverFb
1251 
1252 } // namespace mcrt_dataio
void setTimingRecorderHydra(std::shared_ptr< TimingRecorderHydra > ptr)
Set TimingRecorderHydra data point for performance analysis for hdMoonray.
Definition: ClientReceiverFb.cc:3024
DenoiseMode getBeautyDenoiseMode() const
Get denoise mode for the beauty data.
Definition: ClientReceiverFb.cc:2709
void setTelemetryOverlayReso(unsigned width, unsigned height)
Set telemetry overlay information display resolution.
Definition: ClientReceiverFb.cc:3051
void consoleAutoSetup(const CallBackSendMessage &sendMessage)
This API enables ClientReceiverFb&#39;s debug console functionality by the environment variable...
Definition: ClientReceiverFb.cc:2951
float getElapsedSecFromStart()
Get elapsed time from snapshot was executed on MCRT computation to current.
Definition: ClientReceiverFb.cc:2545
int getPixelInfoNumChan() const
Get PixelInfo data&#39;s total channel number.
Definition: ClientReceiverFb.cc:2599
void setInfoRecFileName(const std::string &fileName)
Set filename of infoRec dump.
Definition: ClientReceiverFb.cc:2915
bool getRenderOutputRgb888(const unsigned id, std::vector< unsigned char > &rgbFrame, const bool top2bottom=false, const bool isSrgb=false, const bool closestFilterDepthOutput=false)
Get current RenderOutput(=AOV) buffer data as 8bit RGB 3 channels.
Definition: ClientReceiverFb.cc:2763
float getProgress() const
Get current image&#39;s progress fraction value.
Definition: ClientReceiverFb.cc:2527
void updateStatsProgressiveFrame()
This API updates progressiveFrame related internal information.
Definition: ClientReceiverFb.cc:2927
int getReceivedImageSenderMachineId() const
integer representation of machineId that originally sent last received image.
Definition: ClientReceiverFb.cc:3030
float getRenderPrepProgress() const
Get current image&#39;s renderPrep stage progress fraction value.
Definition: ClientReceiverFb.cc:2521
bool decodeProgressiveFrame(const mcrt::ProgressiveFrame &message, const bool doParallel, const CallBackStartedCondition &callBackFuncAtStartedCondition, const CallBackGenericComment &callBackForGenericComment=nullptr)
decode ProgressiveFrame message and update internal fb data accordingly.
Definition: ClientReceiverFb.cc:2487
scene_rdl2::math::Vec4f getPixBeautyOdd(const int sx, const int sy) const
Get pixel value of beauty odd buffer.
Definition: ClientReceiverFb.cc:2861
bool getHeatMapStatus() const
Get HeatMap data condition.
Definition: ClientReceiverFb.cc:2605
bool getWeightBufferStatus() const
Get Weight buffer data condition.
Definition: ClientReceiverFb.cc:2623
bool getHeatMap(std::vector< float > &data, const bool top2bottom=false)
Get current HeatMap buffer data as float (=32bit single float) 1 channel data.
Definition: ClientReceiverFb.cc:2798
size_t getViewId() const
Get View id of current image.
Definition: ClientReceiverFb.cc:2497
Definition: ClientReceiverConsoleDriver.h:22
int getHeatMapNumChan() const
Get HeatMap data&#39;s total channel number.
Definition: ClientReceiverFb.cc:2617
void setBeautyDenoiseMode(DenoiseMode mode)
Setup denoise mode for the beauty data.
Definition: ClientReceiverFb.cc:2703
bool getRenderOutputClosestFilter(const unsigned id) const
Get AOV buffer&#39;s closestFilter use status.
Definition: ClientReceiverFb.cc:2677
void setInfoRecInterval(const float sec)
Set infoRec info snapshot minimum interval. Snapshot is never executed less than this interval...
Definition: ClientReceiverFb.cc:2903
bool getRenderBufferOddStatus() const
Get RenderBufferOdd data condition.
Definition: ClientReceiverFb.cc:2641
static std::string showDenoiseEngine(const DenoiseEngine &engine)
String replasentation of DenoiseMode.
Definition: ClientReceiverFb.cc:2983
int getRenderOutputNumChan(const unsigned id) const
Get AOV buffer&#39;s channel total.
Definition: ClientReceiverFb.cc:2665
Parser & getParser()
Returns Parser object reference.
Definition: ClientReceiverFb.cc:2976
const std::string & getHeatMapName() const
Get HeatMap data AOV buffer name if image has HeatMap data.
Definition: ClientReceiverFb.cc:2611
bool getBeautyRgb888(std::vector< unsigned char > &rgbFrame, const bool top2bottom=false, const bool isSrgb=false)
Get current beauty buffer data as 8bit RGB 3 channels w/ gamma2.2 or sRGB conversion.
Definition: ClientReceiverFb.cc:2723
const std::string & getRenderOutputName(const unsigned id) const
Get AOV buffer name.
Definition: ClientReceiverFb.cc:2659
void updateStatsMsgInterval()
This API records message receive timing in order to get statistical information.
Definition: ClientReceiverFb.cc:2921
BackendStat getBackendStat() const
Definition: ClientReceiverFb.cc:2515
bool getWeightBuffer(std::vector< float > &data, const bool top2bottom=false)
Get current weight buffer data as float (=32bit single float) 1 channel data.
Definition: ClientReceiverFb.cc:2805
void setInfoRecDisplayInterval(const float sec)
Set minimum interval of showing infoRec information.
Definition: ClientReceiverFb.cc:2909
void switchTelemetryLayoutNext()
switch telemetry overlay layout to the next
Definition: ClientReceiverFb.cc:3069
int getPixRenderOutput(const unsigned id, const int sx, const int sy, std::vector< float > &out) const
Get pixel value of renderOutput (AOV) buffer.
Definition: ClientReceiverFb.cc:2867
ClientReceiverFb & operator=(const ClientReceiverFb &)=delete
This class is Non-copyable.
static std::string showBackendStat(const BackendStat &stat)
String reprasentation of BackendStat.
Definition: ClientReceiverFb.cc:3010
int getRenderOutput(const unsigned id, std::vector< float > &data, const bool top2bottom=false, const bool closestFilterDepthOutput=false)
Get current RenderOutput(=AOV) buffer data.
Definition: ClientReceiverFb.cc:2819
int getRenderBufferOddNumChan() const
Get RenderBufferOdd data&#39;s total channel number.
Definition: ClientReceiverFb.cc:2647
unsigned getTotalRenderOutput() const
Get total number of RenderOutput (AOV) of this image.
Definition: ClientReceiverFb.cc:2653
bool getPixelInfo(std::vector< float > &data, const bool top2bottom=false)
Get current PixelInfo buffer data as float (=32bit single float) 1 channel data.
Definition: ClientReceiverFb.cc:2791
std::string showPix(const int sx, const int sy, const std::string &aovName) const
Return pixel value detailed information by string.
Definition: ClientReceiverFb.cc:2885
bool getBeautyOdd(std::vector< float > &rgba, const bool top2bottom=false)
Get current RenderBufferOdd data as float (=32bit single float) RGBA 4 channels.
Definition: ClientReceiverFb.cc:2812
bool getPixelInfoRgb888(std::vector< unsigned char > &rgbFrame, const bool top2bottom=false, const bool isSrgb=false)
Get current PixelInfo buffer data as 8bit monochrome color RGB 3 channels.
Definition: ClientReceiverFb.cc:2731
bool getHeatMapRgb888(std::vector< unsigned char > &rgbFrame, const bool top2bottom=false, const bool isSrgb=false)
Get current HeatMap buffer data as 8bit RGB 3 channels.
Definition: ClientReceiverFb.cc:2739
const scene_rdl2::math::Viewport & getRezedViewport() const
Get rezed viewport.
Definition: ClientReceiverFb.cc:2569
scene_rdl2::math::Vec4f getPixBeauty(const int sx, const int sy) const
Get pixel value of beauty buffer.
Definition: ClientReceiverFb.cc:2837
bool getBeautyAuxRgb888(std::vector< unsigned char > &rgbFrame, const bool top2bottom=false, const bool isSrgb=false)
Get current RenderBufferOdd (aka BeautyAux) data as 8bit RGB 3 channels.
Definition: ClientReceiverFb.cc:2755
float getPixWeightBuffer(const int sx, const int sy) const
Get pixel value of weight buffer.
Definition: ClientReceiverFb.cc:2855
void consoleEnable(const unsigned short port, const CallBackSendMessage &sendMessage)
This API enables ClientReceiverFb&#39;s debug console functionality.
Definition: ClientReceiverFb.cc:2963
const scene_rdl2::grid_util::LatencyLogUpstream & getLatencyLogUpstream() const
Get current LatencyLogUpstream information.
Definition: ClientReceiverFb.cc:2897
bool isCoarsePass() const
Make sure current image is coarse pass or not.
Definition: ClientReceiverFb.cc:2533
bool getBeauty(std::vector< float > &rgba, const bool top2bottom=false)
Get current beauty buffer data as float (=32bit single float) RGBA 4 channels.
Definition: ClientReceiverFb.cc:2783
Definition: ClientReceiverFb.cc:36
Definition: ClientReceiverConsoleDriver.cc:9
const std::string & getWeightBufferName() const
Get Weight buffer data AOV buffer name if image has Weight buffer data.
Definition: ClientReceiverFb.cc:2629
uint32_t getFrameId() const
Get frame id of current image.
Definition: ClientReceiverFb.cc:2503
void setTelemetryOverlayActive(bool sw)
Set telemetry overlay enable/disable condition.
Definition: ClientReceiverFb.cc:3057
bool getPixelInfoStatus() const
Get PixelInfo data condition.
Definition: ClientReceiverFb.cc:2587
const scene_rdl2::grid_util::LatencyLog & getLatencyLog() const
Get current LatencyLog information.
Definition: ClientReceiverFb.cc:2891
float getPixHeatMap(const int sx, const int sy) const
Get pixel value of heatMap buffer.
Definition: ClientReceiverFb.cc:2849
uint64_t getRecvMsgSize() const
Return last received ProgressiveFrame message size.
Definition: ClientReceiverFb.cc:2551
uint64_t getSnapshotStartTime() const
Get time of snapshot was executed on MCRT computation.
Definition: ClientReceiverFb.cc:2539
unsigned getWidth() const
Get rezed viewport width.
Definition: ClientReceiverFb.cc:2557
bool getStats(const float intervalSec, std::string &outMsg)
This API creates a string for displaying statistical information at client side.
Definition: ClientReceiverFb.cc:2933
static std::string showDenoiseMode(const DenoiseMode &mode)
String replasentation of DenoiseMode.
Definition: ClientReceiverFb.cc:2995
ClientReceiverConsoleDriver & consoleDriver()
Returns console driver.
Definition: ClientReceiverFb.cc:2970
bool getWeightBufferRgb888(std::vector< unsigned char > &rgbFrame, const bool top2bottom=false, const bool isSrgb=false)
Get current Weight buffer data as 8bit RGB 3 channels.
Definition: ClientReceiverFb.cc:2747
unsigned getFbActivityCounter()
This API returns total update operation count regarding internal frame buffer.
Definition: ClientReceiverFb.cc:2945
Definition: ClientReceiverFb.h:29
bool getRoiViewportStatus() const
Get ROI viewport condition.
Definition: ClientReceiverFb.cc:2575
const std::string & getPixelInfoName() const
Get PixelInfo data AOV buffer name if image has PixelInfo data.
Definition: ClientReceiverFb.cc:2593
unsigned getHeight() const
Get rezed viewport height.
Definition: ClientReceiverFb.cc:2563
float getRecvImageDataFps()
This API returns how frequently received and decoded image data (as progressiveFrame message)...
Definition: ClientReceiverFb.cc:2939
float getPixPixelInfo(const int sx, const int sy) const
Get pixel value of pixelInfo (depth) buffer.
Definition: ClientReceiverFb.cc:2843
void setDenoiseEngine(DenoiseEngine engine)
Setup denoise engine mode for denoise operation.
Definition: ClientReceiverFb.cc:2691
DenoiseEngine getDenoiseEngine() const
Get current denoise engine mode for denoise operation.
Definition: ClientReceiverFb.cc:2697
const std::string & getErrorMsg() const
Get error message.
Definition: ClientReceiverFb.cc:2715
mcrt::BaseFrame::Status getStatus() const
Get current image&#39;s status.
Definition: ClientReceiverFb.cc:2509
static std::string showSenderMachineId(int machineId)
string representation of sender&#39;s machineId
Definition: ClientReceiverFb.cc:3037
bool getTelemetryOverlayActive() const
Get telemetry overlay enable/disable condition.
Definition: ClientReceiverFb.cc:3063
const scene_rdl2::math::Viewport & getRoiViewport() const
Get ROI viewport if it&#39;s set. If there is no ROI viewport, return useless info.
Definition: ClientReceiverFb.cc:2581
int getWeightBufferNumChan() const
Get Weight buffer data&#39;s total channel number.
Definition: ClientReceiverFb.cc:2635