HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_RasterFilter.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: TIL_MiscHelper.h (TIL Library, C++)
7  *
8  * COMMENTS: A generic interface to provide filters for rasters with
9  * multiple raster planes. Examples of this might include
10  * denoisers which read from multiple input planes and write to
11  * multiple output planes.
12  *
13  */
14 
15 #ifndef TIL_MiscHelper_H
16 #define TIL_MiscHelper_H
17 
18 #include "TIL_API.h"
19 #include "TIL_Defines.h"
20 
21 #include <UT/UT_NonCopyable.h>
22 #include <UT/UT_Options.h>
23 #include <UT/UT_StringArray.h>
24 #include <UT/UT_StringHolder.h>
25 #include <UT/UT_StringMap.h>
26 #include <UT/UT_UniquePtr.h>
27 #include <UT/UT_VectorTypes.h>
28 #include <SYS/SYS_Handle.h>
29 #include <SYS/SYS_Visibility.h>
30 
31 class PXL_Raster;
32 class UT_Options;
33 class RV_VKMemory;
34 
35 /// Apply arbitrary filters to PXL_Raster image(s).
36 ///
37 /// The DSO must implement "newRasterFilter" function which should create new
38 /// filters by calling TIL_RasterFilter::registerFactory(). Image filters will
39 /// be searched for in $HOUDINI_DSO_PATH/img_filter.
40 ///
41 /// When the filter is instantiated, the caller will initialize the filter
42 /// calling @c setOptions. This is only called one time, though the filter may
43 /// be invoked multiple times.
44 ///
45 /// Prior to invoking the filter, the @c reset() method will be called. This
46 /// lets the filter reset any information that changes from run to run.
47 ///
48 /// The caller will then set up any optional read-only auxilliary rasters the
49 /// filter may need for processing. That is, the caller will call @c
50 /// setAuxPlane zero or more times.
51 ///
52 /// After the filter is reset and auxilliary planes are added, the @c apply()
53 /// method will finally be called. This should modify the raster passed in to
54 /// create the resulting image. It's possible the apply() method may be called
55 /// multiple times before reset() is called again.
57 {
58 public:
60 
61  /// The factory to define a filter
63  {
64  Factory() = default;
65  virtual ~Factory();
67  virtual const UT_StringHolder &name() const = 0;
68  virtual const UT_StringHolder &label() const = 0;
69  virtual TIL_RasterFilterPtr newFilter() const = 0;
70  };
71 
72  /// @{
73  /// Constructor/Destructor
75  virtual ~TIL_RasterFilter() {};
76  /// @}
77 
79 
80  /// @{
81  /// Get tokens that are used to store auxilliary planes
82  static const UT_StringHolder &albedoToken();
83  static const UT_StringHolder &normalToken();
84  static const UT_StringHolder &mvectorToken();
85  static const UT_StringHolder &prevfrToken();
86  /// @}
87 
88  enum AOVType
89  {
90  AT_NONE = 0,
91 
96  AT_DIFFUSE
97  };
98 
100  {
103  RDT_RAW_CUDA
104  };
105 
107  {
108  public:
109  virtual SYS_Handle exportRaster(RV_VKMemory* mem) = 0;
110  virtual exint rasterSize(RV_VKMemory* mem) = 0;
111  virtual ~VulkanResolver() = default;
112  };
113  static void setVulkanResolver(UT_UniquePtr<VulkanResolver>);
114  static VulkanResolver *getVulkanResolver();
115 
116  struct RasterData
117  {
118  RasterData() = default;
119 
121  : myDataType(RDT_PXL_RASTER)
122  , myRaster(rp) { }
123 
124  RasterData(PXL_Raster *rp, RV_VKMemory *h)
125  : myDataType(RDT_VK_BUFFER)
126  , myRaster(rp)
127  , myVKHandle(h){ }
128 
129  RasterData(PXL_Raster *rp, void *cuda)
130  : myDataType(RDT_RAW_CUDA)
131  , myRaster(rp)
132  , myCudaHandle(cuda) { }
133 
134  RasterDataTypes myDataType = RDT_PXL_RASTER;
135  PXL_Raster* myRaster = nullptr;
136  void* myCudaHandle = nullptr;
137  RV_VKMemory* myVKHandle = nullptr;
138  };
139 
140  struct LayerData
141  {
144  AOVType myType = AT_NONE;
145  };
146 
147  static AOVType stringToAOVType(const UT_StringHolder &type);
148 
149  /// Register a new factory. Set HOUDINI_DSO_ERROR=1 to get information on
150  /// why the filter might not be installed.
151  static void registerFactory(UT_UniquePtr<Factory> factory);
152 
153  /// Remove a factory from the list
154  static void removeFactory(const UT_StringRef &name);
155 
156  /// Get a list of all the filters
157  static void getFilters(UT_Array<const Factory *> &filters);
158 
159  // Allocate a filter of a given name
160  static TIL_RasterFilterPtr allocFilter(const UT_StringRef &name);
161 
162  /// For debugging
163  virtual const char *className() const = 0;
164 
165  /// Initiaze the filter with user specified options. This method is only
166  /// called once. If the filter isn't valid, the @c myErrorString member
167  /// should be set to a meaningful error and the function should return
168  /// false.
169  ///
170  /// Aside from setting any specific options, this is also the time you
171  /// should build myAuxPlaneNames. This lets the caller know which extra
172  /// AOVs you can read from. Not all of them may exist, but this lets the
173  /// caller know which planes you can look at.
174  virtual bool setOptions(const UT_Options &options) { return true; }
175 
176  /// Set up an auxilliary plane. This is a raster which isn't actually
177  /// modified, but is used in the filtering (for example a mask). The
178  /// caller looks at the @c myAuxPlaneNames list to see which rasters you
179  /// might require. If they are available, they will be stashed in this
180  /// array.
181  void setAuxPlane(const UT_StringHolder &planename,
182  const PXL_Raster* raster)
183  {
184  RasterData rd(SYSconst_cast(raster));
185  myAuxPlanes[planename] = rd;
186  }
187  /// Set up an auxiliary plane using RasterData.
188  /// If the RasterData provides a Cuda or Vulkan device handle,
189  /// it will be used directly, avoiding internal device memory allocation.
190  /// Otherwise, the filter may allocate its own buffer.
191  /// The caller looks at the @c myAuxPlaneNames list to determine
192  /// which planes are required.
193  void setAuxPlane(const UT_StringHolder &planename,
194  const RasterData &aux)
195  {
196  myAuxPlanes[planename] = aux;
197  }
198 
199  /// Returns false if fail
200  virtual bool apply(PXL_Raster *raster) = 0;
201 
202  /// Returns false if fail
203  virtual bool apply(UT_Array<LayerData>& layersdata, bool upscale, bool firstframe) = 0;
204 
205  /// Reset and get ready for a new filter. If you subclass this method,
206  /// please make sure to call the base class method.
207  virtual void reset()
208  {
209  myAuxPlanes.clear();
210  }
211 
212  /// Get the list of aux plane names
214  { return myAuxPlaneNames; }
215 
216  /// Get stored error msg in case apply() fails. Sub-classes can set @c
217  /// myErrorString to something meaningful for the caller.
219  { return myErrorString; }
220 
221  /// If the filter can run in a few milliseconds, you can try returning
222  /// true.
223  virtual bool isInteractive() const { return false; }
224 
225  /// Returns true if this filter can use device pointers from
226  /// the device represented by `uuid` a RasterData struct
227  virtual bool matchesDevice(uint8 (&uuid)[16]) const { return false; }
228 
229 protected:
233 };
234 
236 
237 extern "C" {
238  /// DSO function called. This function can register one or more filters.
239  /// Only filters which are supported should be registered.
241 }
242 
243 #endif
RasterData(PXL_Raster *rp, void *cuda)
UT_StringHolder myErrorString
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
SYS_VISIBILITY_EXPORT void newRasterFilter()
UT_StringArray myAuxPlaneNames
UT_StringMap< RasterData > myAuxPlanes
#define SYS_VISIBILITY_EXPORT
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:136
int64 exint
Definition: SYS_Types.h:125
void setAuxPlane(const UT_StringHolder &planename, const PXL_Raster *raster)
RasterData(PXL_Raster *rp, RV_VKMemory *h)
const UT_StringHolder & getErrorString() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
unsigned char uint8
Definition: SYS_Types.h:36
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
const UT_StringArray & getAuxPlaneNames() const
Get the list of aux plane names.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
virtual bool isInteractive() const
HUSD_API const char * raster()
virtual void reset()
GLuint const GLchar * name
Definition: glcorearb.h:786
void setAuxPlane(const UT_StringHolder &planename, const RasterData &aux)
TIL_RasterFilter::TIL_RasterFilterPtr TIL_RasterFilterPtr
virtual bool setOptions(const UT_Options &options)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
A map of string to various well defined value types.
Definition: UT_Options.h:87
The factory to define a filter.
virtual bool matchesDevice(uint8(&uuid)[16]) const
#define TIL_API
Definition: TIL_API.h:10
UT_UniquePtr< TIL_RasterFilter > TIL_RasterFilterPtr
virtual ~TIL_RasterFilter()