40 #if defined(RIF_USE_METAL)
41 #define BACKEND_TYPE RIF_BACKEND_API_METAL
43 #define BACKEND_TYPE RIF_BACKEND_API_OPENCL
57 static constexpr
UT_StringLit theDefaultModelPath(
"./models");
62 #if defined(TRACE_CALLS)
63 #define DEBUG_PRINT(...) do { \
65 tmp.format(__VA_ARGS__); \
66 fprintf(stderr, "%s(%d): %s\n", __FILE__, __LINE__, tmp.buffer()); \
70 #define DEBUG_PRINT(...) ((void)0)
87 static constexpr
inline bool
88 isError(rif_int status)
90 return status != RIF_SUCCESS;
93 #define RIF_CALL(status, msg, call) \
95 DEBUG_PRINT("CALL: {} = {}", int(status), #call); \
96 if (status != RIF_SUCCESS) { \
97 error(msg, "RadeonPro Error: %s\n %s\n", \
98 rifGetErrorCodeString(status), \
99 rifGetErrorCodeDescription(status)); \
105 #define RIF_CALL_FAIL(status, msg, call) \
106 { RIF_CALL(status, msg, call) \
107 if (isError(status)) return false; } \
113 rif_int status = RIF_SUCCESS;
116 if (!ndev || isError(status))
121 devnum,
nullptr, &context));
146 myModelPath = theDefaultModelPath.asHolder();
162 template <
typename DT,
typename ST, u
int DNC, u
int SNC, u
int32 ISCALE,
bool INVERT>
164 copyPixels(DT *dest,
const ST *
src,
exint npixels)
167 constexpr
uint NC = DNC < SNC ? DNC : SNC;
169 scale = INVERT ? 1.0/ISCALE : ISCALE;
173 exint n = r.end() - r.begin();
174 DT *d = dest + r.begin() * DNC;
175 const ST *
s = src + r.begin() * SNC;
176 if (!ISCALE && DNC == SNC)
182 for (
exint i = 0; i <
n; ++i, d += DNC, s += SNC)
188 for (
int ch = 0; ch < NC; ++ch)
189 d[ch] = s[ch] * scale;
197 template <
typename DT,
typename ST, u
int32 ISCALE,
bool INVERT>
199 doCopyRaster(
void *d,
int dnc,
const void *s,
int snc,
exint npix)
204 copyPixels<DT, ST, 3, 3, ISCALE, INVERT>((DT *)d, (
const ST *)s, npix);
206 copyPixels<DT, ST, 3, 4, ISCALE, INVERT>((DT *)d, (
const ST *)s, npix);
211 copyPixels<DT, ST, 4, 3, ISCALE, INVERT>((DT *)d, (
const ST *)s, npix);
213 copyPixels<DT, ST, 4, 4, ISCALE, INVERT>((DT *)d, (
const ST *)s, npix);
225 storage.setRes(src.getXres(), src.getYres());
228 float *
f = (
float *)storage.getPixels();
229 const void *s = src.getPixels();
230 exint npix = src.getNumPixels();
233 switch (src.getFormat())
236 doCopyRaster<float, uint8, 0xff, true>(
f, nchan,
s, nchan, npix);
239 doCopyRaster<float, uint16, 0xffff, true>(
f, nchan,
s, nchan, npix);
242 doCopyRaster<float, uint32, 0xffffffff, true>(
f, nchan,
s, nchan, npix);
245 doCopyRaster<float, fpreal16, 0, false>(
f, nchan,
s, nchan, npix);
248 doCopyRaster<float, fpreal32, 0, false>(
f, nchan,
s, nchan, npix);
258 TIL_RadeonFilter::downloadRaster(
PXL_Raster &dest,
const RIFImage &src)
265 sizeof(desc), &desc, &rsize));
272 int devSize = desc.num_components;
280 doCopyRaster<uint8, float, 0xff, false>(
284 doCopyRaster<uint16, float, 0xffff, false>(
288 doCopyRaster<uint32, float, 0xffffffff, false>(
292 doCopyRaster<fpreal16, float, 0, false>(
296 doCopyRaster<fpreal32, float, 0, false>(
308 TIL_RadeonFilter::uploadRaster(RIFContext &ctx,
314 const PXL_Raster &rp = makeFloatRaster(src, storage);
320 memset(&desc, 0,
sizeof(desc));
321 desc.type = RIF_COMPONENT_TYPE_FLOAT32;
322 desc.image_width = rp.
getXres();
323 desc.image_height = rp.
getYres();
326 if (img && status != RIF_SUCCESS)
328 return img.isValid();
342 if (nchan != 3 && nchan != 4)
349 rifContextCreateCommandQueue(*ctx, queue.
ptr()));
356 ?
"color" :
"colorImg";
357 if (!uploadRaster(ctx, rgb, colorName, *raster, storage))
361 rif_image_desc out_desc;
362 rifImageGetInfo(*rgb, RIF_IMAGE_DESC,
sizeof(out_desc), &out_desc, &out_size);
369 out_desc.num_components = 3;
370 out_desc.type = RIF_COMPONENT_TYPE_FLOAT32;
372 &out_desc,
nullptr, out.
ptr()));
378 RIF_IMAGE_FILTER_EAW_DENOISE, filter.
ptr()));
382 if (uploadRaster(ctx, normalsImg,
"normalsImg",
383 *it->second, normalsImg_store))
386 rifImageFilterSetParameterImage(*filter,
"normalsImg", *normalsImg));
392 if (uploadRaster(ctx, depthImg,
"depthImg",
393 *it->second, depthImg_store))
396 rifImageFilterSetParameterImage(*filter,
"depthImg", *depthImg));
400 *filter, *rgb, *out));
405 RIF_IMAGE_FILTER_AI_DENOISE, filter.
ptr()));
408 *filter, theUseHDR.c_str(), 1));
410 *filter, theModelPath.c_str(), myModelPath.
c_str()));
412 *filter, colorName, *rgb));
414 *filter, *rgb, *out));
419 RIF_IMAGE_FILTER_BLOOM, filter.
ptr()));
421 *filter, theRadius.c_str(), myRadius));
423 *filter, theThreshold.c_str(), myThreshold));
425 *filter, theWeight.c_str(), myWeight));
427 *filter, *rgb, *out));
430 *ctx, *queue,
nullptr,
nullptr,
nullptr));
433 downloadRaster(*raster, out);
435 rifCommandQueueDetachImageFilter(*queue, *filter);
450 static constexpr
UT_StringLit theBloom (
"radeon_bloom");
451 static constexpr
UT_StringLit theDenoise(
"radeon_denoise");
452 static constexpr
UT_StringLit theAIDenoise(
"radeon_aidenoise");
456 return theBloom.asHolder();
458 return theDenoise.asHolder();
460 return theAIDenoise.asHolder();
466 static constexpr
UT_StringLit theBloom (
"AMD Radeon Bloom");
467 static constexpr
UT_StringLit theDenoise(
"AMD Radeon Denoise");
468 static constexpr
UT_StringLit theAIDenoise(
"AMD Radeon AI Denoise");
472 return theBloom.asHolder();
474 return theDenoise.asHolder();
476 return theAIDenoise.asHolder();
482 return UTmakeUnique<TIL_RadeonFilter>(myType);
virtual const UT_StringHolder & name() const =0
UT_StringHolder myErrorString
int PXLpackingComponents(PXL_Packing p)
UT_StringArray myAuxPlaneNames
GLenum GLenum GLenum GLenum GLenum scale
int int int vsprintf(const char *fmt, va_list ap)
virtual const UT_StringHolder & label() const =0
PXL_DataFormat getFormat() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
#define RIF_CALL(status, msg, call)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
bool setOptions(const UT_Options &argstr) override
PXL_Packing getPacking() const
void setPacking(PXL_Packing p)
GLint GLenum GLsizei GLint GLsizei const void * data
exint getNumPixels() const
static const UT_StringHolder theEmptyString
#define SYS_PRINTF_CHECK_ATTRIBUTE(string_index, first_to_check)
virtual ~TIL_RadeonFilter()
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the queue
SYS_FORCE_INLINE const char * c_str() const
static void registerFactory(UT_UniquePtr< Factory > factory)
GLuint GLuint GLsizei GLenum type
virtual TIL_RasterFilterPtr newFilter() const =0
GLuint GLsizei GLsizei GLchar * label
bool apply(PXL_Raster *raster) override
A map of string to various well defined value types.
The factory to define a filter.
basic_printf_context_t< buffer >::type context
TIL_RadeonFilter(RADEON_FILTER_TYPE type)
GLdouble GLdouble GLdouble r
OIIO_API bool copy(string_view from, string_view to, std::string &err)
#define RIF_CALL_FAIL(status, msg, call)
getOption("OpenEXR.storage") storage
UT_StringMap< const PXL_Raster * > myAuxPlanes
bool importOption(const UT_StringRef &name, int &value) const
void UTparallelFor(const Range &range, const Body &body, const int subscribe_ratio=2, const int min_grain_size=1)