HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMG/TIL_RadeonFilter.h
/*
* Copyright (c) 2021
* Side Effects Software Inc. All rights reserved.
*
* Redistribution and use of Houdini Development Kit samples in source and
* binary forms, with or without modification, are permitted provided that the
* following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __TIL_RadeonFilter__
#define __TIL_RadeonFilter__
#include <PXL/PXL_Raster.h>
#include <UT/UT_Debug.h>
#include <RadeonImageFilters.h>
#ifdef _WIN32
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include<windows.h>
#endif
{
};
/// Sample code to install the Radeon Image Filters into Houdini
///
/// These filters can be used in:
/// - Karma Image Filters
/// - The AI Denoise COP
/// - The @c idenoise application
/// For example, after the code is build, the filters should appear when
/// running <tt>idenoise -l</tt>.
///
/// To make this example, you'll need to have the latest Radeon Image Filter
/// development kit. You should be able to compile using: @code
/// export AMD = path_to_development_kit
/// export AMD_PLATFORM = Ubuntu18
/// hcustom -i ~/houdini18.5/dso/img_filter
/// -I $AMD/include
/// -L $AMD/$AMD_PLATFORM
/// -l RadeonImageFilters
/// -l RadeonML-MIOpen
/// -l MIOpen
/// TIL_RadeonFilter.C
/// @endcode
class TIL_RadeonFilter final : public TIL_RasterFilter
{
public:
// Simple wrapper around RIF objects to manage automatic cleanup of objects
template <typename T>
class RIFObject
{
public:
using this_type = RIFObject<T>;
RIFObject(T o=nullptr)
: myObject(o)
{
}
{
clear();
}
void clear()
{
if (myObject)
{
#if 0
UTformat(stderr, "Delete {} {}\n", typeid(T).name(), myObject);
#endif
rifObjectDelete(myObject);
myObject = nullptr;
}
}
bool isValid() const { return myObject != nullptr; }
SYS_SAFE_BOOL operator bool() const { return myObject != nullptr; }
{
clear();
myObject = obj;
return *this;
}
T *ptr() { return &myObject; }
T operator*() const { UT_ASSERT(myObject); return myObject; }
T operator->() const { UT_ASSERT(myObject); return myObject; }
private:
T myObject;
};
// Mapping of raw rif types to RIFObjects
using RIFContext = RIFObject<rif_context>;
using RIFImage = RIFObject<rif_image>;
using RIFCommandQueue = RIFObject<rif_command_queue>;
using RIFImageFilter = RIFObject<rif_image_filter>;
virtual ~TIL_RadeonFilter();
/// @{
/// Overridden methods from the base class
const char *className() const final { return "TIL_RadeonFilter"; }
bool setOptions(const UT_Options &argstr) override;
bool apply(PXL_Raster *raster) override;
/// @}
/// Since the filters run in a few milliseconds, they can be considered
/// interactive.
bool isInteractive() const override { return true; }
private:
bool uploadRaster(RIFContext &ctx,
const char *label,
const PXL_Raster &rp,
bool downloadRaster(PXL_Raster &dest,
const RIFImage &src);
// Filter type
RADEON_FILTER_TYPE myFilterType;
// Device number
int myDeviceNum;
// Parameters for Bloom
float myRadius;
float myThreshold;
float myWeight;
// Parameters for AI denoiser
UT_StringHolder myModelPath;
};
#endif