2014-07-08 03:11:14 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "EmberCLPch.h"
|
|
|
|
#include "OpenCLWrapper.h"
|
|
|
|
#include "IterOpenCLKernelCreator.h"
|
|
|
|
#include "DEOpenCLKernelCreator.h"
|
|
|
|
#include "FinalAccumOpenCLKernelCreator.h"
|
|
|
|
|
|
|
|
/// <summary>
|
2014-10-27 17:21:06 -04:00
|
|
|
/// RendererCLBase and RendererCL classes.
|
2014-07-08 03:11:14 -04:00
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
namespace EmberCLns
|
|
|
|
{
|
2014-10-27 17:21:06 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Serves only as an interface for OpenCL specific rendering functions.
|
|
|
|
/// </summary>
|
2014-07-08 03:11:14 -04:00
|
|
|
class EMBERCL_API RendererCLBase
|
|
|
|
{
|
|
|
|
public:
|
2014-10-14 11:53:15 -04:00
|
|
|
virtual bool ReadFinal(unsigned char* pixels) = 0;
|
|
|
|
virtual bool ClearFinal() = 0;
|
2014-07-08 03:11:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// RendererCL is a derivation of the basic CPU renderer which
|
|
|
|
/// overrides various functions to render on the GPU using OpenCL.
|
|
|
|
/// Since this class derives from EmberReport and also contains an
|
|
|
|
/// OpenCLWrapper member which also derives from EmberReport, the
|
|
|
|
/// reporting functions are overridden to aggregate the errors from
|
|
|
|
/// both sources.
|
|
|
|
/// It does not support different types for T and bucketT, so it only has one template argument
|
|
|
|
/// and uses both for the base.
|
|
|
|
/// </summary>
|
|
|
|
template <typename T>
|
|
|
|
class EMBERCL_API RendererCL : public RendererCLBase, public Renderer<T, T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RendererCL(unsigned int platform = 0, unsigned int device = 0, bool shared = false, GLuint outputTexID = 0);
|
|
|
|
~RendererCL();
|
|
|
|
|
2014-10-14 11:53:15 -04:00
|
|
|
//Non-virtual member functions for OpenCL specific tasks.
|
2014-07-08 03:11:14 -04:00
|
|
|
bool Init(unsigned int platform, unsigned int device, bool shared, GLuint outputTexID);
|
2014-10-14 11:53:15 -04:00
|
|
|
bool SetOutputTexture(GLuint outputTexID);
|
Numerous fixes
0.4.0.5 Beta 07/18/2014
--User Changes
Allow for vibrancy values > 1.
Add flatten and unflatten menu items.
Automatically flatten like Apophysis does.
Add plugin and new_linear tags to Xml to be compatible with Apophysis.
--Bug Fixes
Fix blur, blur3d, bubble, cropn, cross, curl, curl3d, epispiral, ho,
julia3d, julia3dz, loonie, mirror_x, mirror_y, mirror_z, rotate_x,
sinusoidal, spherical, spherical3d, stripes.
Unique filename on final render was completely broken.
Two severe OpenCL bugs. Random seeds were biased and fusing was being
reset too often leading to results that differ from the CPU.
Subtle, but sometimes severe bug in the setup of the xaos weights.
Use properly defined epsilon by getting the value from
std::numeric_limits, rather than hard coding 1e-6 or 1e-10.
Omit incorrect usage of epsilon everywhere. It should not be
automatically added to denominators. Rather, it should only be used if
the denominator is zero.
Force final render progress bars to 100 on completion. Sometimes they
didn't seem to make it there.
Make variation name and params comparisons be case insensitive.
--Code Changes
Make ForEach and FindIf wrappers around std::for_each and std::find_if.
2014-07-19 02:33:18 -04:00
|
|
|
inline unsigned int IterCountPerKernel();
|
2014-07-08 03:11:14 -04:00
|
|
|
inline unsigned int IterBlocksWide();
|
|
|
|
inline unsigned int IterBlocksHigh();
|
|
|
|
inline unsigned int IterBlockWidth();
|
|
|
|
inline unsigned int IterBlockHeight();
|
|
|
|
inline unsigned int IterGridWidth();
|
|
|
|
inline unsigned int IterGridHeight();
|
|
|
|
inline unsigned int TotalIterKernelCount();
|
|
|
|
unsigned int PlatformIndex();
|
|
|
|
unsigned int DeviceIndex();
|
|
|
|
bool ReadHist();
|
|
|
|
bool ReadAccum();
|
|
|
|
bool ReadPoints(vector<PointCL<T>>& vec);
|
|
|
|
bool ClearHist();
|
|
|
|
bool ClearAccum();
|
|
|
|
bool WritePoints(vector<PointCL<T>>& vec);
|
|
|
|
string IterKernel();
|
|
|
|
|
2014-10-14 11:53:15 -04:00
|
|
|
//Virtual functions overridden from RendererCLBase.
|
|
|
|
virtual bool ReadFinal(unsigned char* pixels);
|
|
|
|
virtual bool ClearFinal();
|
|
|
|
|
|
|
|
//Public virtual functions overridden from Renderer or RendererBase.
|
|
|
|
virtual size_t MemoryAvailable() override;
|
|
|
|
virtual bool Ok() const override;
|
|
|
|
virtual void NumChannels(size_t numChannels) override;
|
|
|
|
virtual void DumpErrorReport() override;
|
|
|
|
virtual void ClearErrorReport() override;
|
|
|
|
virtual size_t SubBatchSize() const override;
|
|
|
|
virtual size_t ThreadCount() const override;
|
|
|
|
virtual bool CreateDEFilter(bool& newAlloc) override;
|
|
|
|
virtual bool CreateSpatialFilter(bool& newAlloc) override;
|
|
|
|
virtual eRendererType RendererType() const override;
|
|
|
|
virtual string ErrorReportString() override;
|
|
|
|
virtual vector<string> ErrorReport() override;
|
2014-07-08 03:11:14 -04:00
|
|
|
|
|
|
|
#ifndef TEST_CL
|
|
|
|
protected:
|
|
|
|
#endif
|
2014-10-14 11:53:15 -04:00
|
|
|
//Protected virtual functions overridden from Renderer.
|
|
|
|
virtual void MakeDmap(T colorScalar) override;
|
|
|
|
virtual bool Alloc() override;
|
|
|
|
virtual bool ResetBuckets(bool resetHist = true, bool resetAccum = true) override;
|
|
|
|
virtual eRenderStatus LogScaleDensityFilter() override;
|
|
|
|
virtual eRenderStatus GaussianDensityFilter() override;
|
|
|
|
virtual eRenderStatus AccumulatorToFinalImage(unsigned char* pixels, size_t finalOffset) override;
|
|
|
|
virtual EmberStats Iterate(size_t iterCount, size_t pass, size_t temporalSample) override;
|
2014-07-08 03:11:14 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
//Private functions for making and running OpenCL programs.
|
|
|
|
bool BuildIterProgramForEmber(bool doAccum = true);
|
2014-10-14 11:53:15 -04:00
|
|
|
bool RunIter(size_t iterCount, size_t pass, size_t temporalSample, size_t& itersRan);
|
2014-07-08 03:11:14 -04:00
|
|
|
eRenderStatus RunLogScaleFilter();
|
|
|
|
eRenderStatus RunDensityFilter();
|
|
|
|
eRenderStatus RunFinalAccum();
|
2014-10-14 11:53:15 -04:00
|
|
|
bool ClearBuffer(const string& bufferName, unsigned int width, unsigned int height, unsigned int elementSize);
|
2014-07-08 03:11:14 -04:00
|
|
|
bool RunDensityFilterPrivate(unsigned int kernelIndex, unsigned int gridW, unsigned int gridH, unsigned int blockW, unsigned int blockH, unsigned int chunkSizeW, unsigned int chunkSizeH, unsigned int rowParity, unsigned int colParity);
|
2014-10-14 11:53:15 -04:00
|
|
|
int MakeAndGetDensityFilterProgram(size_t ss, unsigned int filterWidth);
|
2014-07-08 03:11:14 -04:00
|
|
|
int MakeAndGetFinalAccumProgram(T& alphaBase, T& alphaScale);
|
|
|
|
int MakeAndGetGammaCorrectionProgram();
|
|
|
|
|
|
|
|
//Private functions passing data to OpenCL programs.
|
|
|
|
DensityFilterCL<T> ConvertDensityFilter();
|
|
|
|
SpatialFilterCL<T> ConvertSpatialFilter();
|
|
|
|
EmberCL<T> ConvertEmber(Ember<T>& ember);
|
|
|
|
static CarToRasCL<T> ConvertCarToRas(const CarToRas<T>& carToRas);
|
|
|
|
|
|
|
|
bool m_Init;
|
|
|
|
bool m_NVidia;
|
|
|
|
bool m_DoublePrecision;
|
Numerous fixes
0.4.0.5 Beta 07/18/2014
--User Changes
Allow for vibrancy values > 1.
Add flatten and unflatten menu items.
Automatically flatten like Apophysis does.
Add plugin and new_linear tags to Xml to be compatible with Apophysis.
--Bug Fixes
Fix blur, blur3d, bubble, cropn, cross, curl, curl3d, epispiral, ho,
julia3d, julia3dz, loonie, mirror_x, mirror_y, mirror_z, rotate_x,
sinusoidal, spherical, spherical3d, stripes.
Unique filename on final render was completely broken.
Two severe OpenCL bugs. Random seeds were biased and fusing was being
reset too often leading to results that differ from the CPU.
Subtle, but sometimes severe bug in the setup of the xaos weights.
Use properly defined epsilon by getting the value from
std::numeric_limits, rather than hard coding 1e-6 or 1e-10.
Omit incorrect usage of epsilon everywhere. It should not be
automatically added to denominators. Rather, it should only be used if
the denominator is zero.
Force final render progress bars to 100 on completion. Sometimes they
didn't seem to make it there.
Make variation name and params comparisons be case insensitive.
--Code Changes
Make ForEach and FindIf wrappers around std::for_each and std::find_if.
2014-07-19 02:33:18 -04:00
|
|
|
unsigned int m_IterCountPerKernel;
|
2014-07-08 03:11:14 -04:00
|
|
|
unsigned int m_IterBlocksWide, m_IterBlockWidth;
|
|
|
|
unsigned int m_IterBlocksHigh, m_IterBlockHeight;
|
|
|
|
unsigned int m_MaxDEBlockSizeW;
|
|
|
|
unsigned int m_MaxDEBlockSizeH;
|
|
|
|
unsigned int m_WarpSize;
|
2014-10-14 11:53:15 -04:00
|
|
|
size_t m_Calls;
|
2014-07-08 03:11:14 -04:00
|
|
|
|
2014-10-14 11:53:15 -04:00
|
|
|
//Buffer names.
|
2014-07-08 03:11:14 -04:00
|
|
|
string m_EmberBufferName;
|
|
|
|
string m_ParVarsBufferName;
|
|
|
|
string m_DistBufferName;
|
|
|
|
string m_CarToRasBufferName;
|
|
|
|
string m_DEFilterParamsBufferName;
|
|
|
|
string m_SpatialFilterParamsBufferName;
|
|
|
|
string m_DECoefsBufferName;
|
|
|
|
string m_DEWidthsBufferName;
|
|
|
|
string m_DECoefIndicesBufferName;
|
|
|
|
string m_SpatialFilterCoefsBufferName;
|
|
|
|
string m_HistBufferName;
|
|
|
|
string m_AccumBufferName;
|
|
|
|
string m_FinalImageName;
|
|
|
|
string m_PointsBufferName;
|
|
|
|
|
2014-10-14 11:53:15 -04:00
|
|
|
//Kernels.
|
2014-07-08 03:11:14 -04:00
|
|
|
string m_IterKernel;
|
|
|
|
|
|
|
|
OpenCLWrapper m_Wrapper;
|
|
|
|
cl::ImageFormat m_PaletteFormat;
|
|
|
|
cl::ImageFormat m_FinalFormat;
|
|
|
|
cl::Image2D m_Palette;
|
|
|
|
IMAGEGL2D m_AccumImage;
|
|
|
|
GLuint m_OutputTexID;
|
|
|
|
EmberCL<T> m_EmberCL;
|
|
|
|
Palette<float> m_Dmap;//Used instead of the base class' m_Dmap because OpenCL only supports float textures.
|
|
|
|
CarToRasCL<T> m_CarToRasCL;
|
|
|
|
DensityFilterCL<T> m_DensityFilterCL;
|
|
|
|
SpatialFilterCL<T> m_SpatialFilterCL;
|
|
|
|
IterOpenCLKernelCreator<T> m_IterOpenCLKernelCreator;
|
|
|
|
DEOpenCLKernelCreator<T> m_DEOpenCLKernelCreator;
|
|
|
|
FinalAccumOpenCLKernelCreator<T> m_FinalAccumOpenCLKernelCreator;
|
|
|
|
pair<string, vector<T>> m_Params;
|
|
|
|
Ember<T> m_LastBuiltEmber;
|
|
|
|
};
|
|
|
|
|
|
|
|
template EMBERCL_API class RendererCL<float>;
|
|
|
|
|
|
|
|
#ifdef DO_DOUBLE
|
|
|
|
template EMBERCL_API class RendererCL<double>;
|
|
|
|
#endif
|
|
|
|
}
|