My Project
ClientReceiverDenoiser.h
1 // Copyright 2023 DreamWorks Animation LLC
2 // SPDX-License-Identifier: Apache-2.0
3 #include "ClientReceiverFb.h"
4 
5 #include <mcrt_denoise/denoiser/Denoiser.h>
6 #include <scene_rdl2/common/grid_util/FloatValueTracker.h>
7 #include <scene_rdl2/common/math/Viewport.h>
8 #include <scene_rdl2/common/rec_time/RecTime.h>
9 
10 #include <functional>
11 #include <vector>
12 
13 namespace mcrt_dataio {
14 
16 {
17 public:
18  using DenoiseEngine = ClientReceiverFb::DenoiseEngine;
19  using SnapshotBuffCallBack = std::function<void(std::vector<float>& buff)>;
20 
22  : mDenoiseEngine(ClientReceiverFb::DenoiseEngine::OPTIX)
23  , mDenoiseReady(true)
24  , mDenoiseWidth(0)
25  , mDenoiseHeight(0)
26  , mDenoiseUseAlbedo(false)
27  , mDenoiseUseNormals(false)
28  , mLatencyTracker(sKeepMaxItems)
29  , mDenoiseTimeTracker(sKeepMaxItems)
30  , mDenoiseMinInterval(0.0f)
31  , mPrevEvalTimingResult(0.0f)
32  {}
33 
34  void resetTimingInfo();
35 
36  bool denoiseBeauty(const DenoiseEngine engine,
37  const float latencySec,
38  const int width,
39  const int height,
40  const scene_rdl2::math::Viewport* roi,
41  const SnapshotBuffCallBack& beautyInputSnapshot,
42  const SnapshotBuffCallBack& albedoInputSnapshot,
43  const SnapshotBuffCallBack& normalInputSnapshot,
44  const int outputNumChan,
45  std::vector<float>& beautyOutput,
46  bool& fallback);
47 
48  bool denoiseBeauty888(const DenoiseEngine engine,
49  const float latencySec,
50  const int width,
51  const int height,
52  const scene_rdl2::math::Viewport* roi,
53  const SnapshotBuffCallBack& beautyInputSnapshot,
54  const SnapshotBuffCallBack& albedoInputSnapshot,
55  const SnapshotBuffCallBack& normalInputSnapshot,
56  std::vector<unsigned char>& beautyOutput, // rgb : apply gamma22 or sRGB
57  bool isSrgb, // true=sRGB, false=gamma22
58  bool& fallback);
59 
60  const std::string& getErrorMsg() const { return mErrorMsg; }
61 
62  std::string showStatus() const;
63 
64 protected:
65  bool setupDenoiser(const DenoiseEngine engine,
66  const int width, const int height, const scene_rdl2::math::Viewport* roi,
67  const SnapshotBuffCallBack& albedoInputCallBack,
68  const SnapshotBuffCallBack& normalInputCallBack);
69 
70  const float* inputBuff(const SnapshotBuffCallBack& callBack, std::vector<float>& buff) const;
71  float* outputBuff(std::vector<float>& buff, int numChan) const;
72  void copyDenoisedResultToOut(const int outputNumChan, std::vector<float>& beautyOutput) const;
73 
74  void denoiseActionTimingTrackStart(const float latencySec);
75  bool denoiseActionIntervalTest();
76  void denoiseActionTimingUpdate();
77 
78  //------------------------------
79 
80  DenoiseEngine mDenoiseEngine;
81 
82  std::vector<float> mBeautyInput;
83  std::vector<float> mAlbedoInput;
84  std::vector<float> mNormalInput;
85  std::vector<float> mDenoisedResult; // We always keep the denoise action result.
86 
87  bool mDenoiseReady;
88  int mDenoiseWidth;
89  int mDenoiseHeight;
90  bool mDenoiseUseAlbedo;
91  bool mDenoiseUseNormals;
92  std::unique_ptr<moonray::denoiser::Denoiser> mDenoiser;
93 
94  std::string mErrorMsg;
95 
96  scene_rdl2::rec_time::RecTime mDenoiseActionInterval;
97  scene_rdl2::rec_time::RecTime mDenoiseAction;
98 
99  static constexpr int sKeepMaxItems = 10;
100  scene_rdl2::grid_util::FloatValueTracker mLatencyTracker;
101  scene_rdl2::grid_util::FloatValueTracker mDenoiseTimeTracker;
102 
103  float mDenoiseMinInterval; // sec
104  float mPrevEvalTimingResult;
105 };
106 
107 } // namespace mcrt_dataio
Definition: ClientReceiverConsoleDriver.cc:9
Definition: ClientReceiverDenoiser.h:15
– ProgressiveFrame message decoder for frontend client –