mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-01-22 05:30:06 -05:00
330074cfb2
-Add new variations: bubbleT3D, crob, hexaplay3D, hexcrop, hexes, hexnix3D, loonie2, loonie3, nBlur, octapol and synth. -Allow for pre/post versions of dc_bubble, dc_cylinder and dc_linear whereas before they were omitted. -When saving a file with multiple embers in it, detect if time values are all the same and if so, start them at zero and increment by 1 for each ember. -Allow for numerous quality increases to be coalesced into one. It will pick up at the end of the current render. -Show selection highlight on variations tree in response to mouse hover. This makes it easier to see for which variation or param the current mouse wheel action will apply. -Make default temporal samples be 100, whereas before it was 1000 which was overkill. -Require the shift key to be held with delete for deleting an ember to prevent it from triggering when the user enters delete in the edit box. -This wasn't otherwise fixable without writing a lot more code. --Bug fixes -EmberGenome was crashing when generating a sequence from a source file with more than 2 embers in it. -EmberGenome was improperly handling the first frame of a merge after the last frame of the loop. -These bugs were due to a previous commit. Revert parts of that commit. -Prevent a zoom value of less than 0 when reading from xml. -Slight optimization of the crescents, and mask variations, if the compiler wasn't doing it already. -Unique file naming was broken because it was looking for _# and the default names ended with -#. -Disallow renaming of an ember in the library tree to an empty string. -Severe bug that prevented some variations from being read correctly from params generated outside this program. -Severe OpenCL randomization bug. The first x coordinates of the first points in the first kernel call of the first ember of a render since the OpenCL renderer object was created were not random and were mostly -1. -Severe bug when populating xform selection distributions that could sometimes cause a crash due to roundoff error. Fix by using double. -Limit the max number of variations in a random ember to MAX_CL_VARS, which is 8. This ensures they'll look the same on CPU and GPU. -Prevent user from saving stylesheet to default.qss, it's a special reserved filename. --Code changes -Generalize using the running sum output point inside of a variation for all cases: pre, reg and post. -Allow for array variables in variations where the address of each element is stored in m_Params. -Qualify all math functions with std:: -No longer use our own Clamp() in OpenCL, instead use the standard clamp(). -Redesign how functions are used in the variations OpenCL code. -Add tests to EmberTester to verify some of the new functionality. -Place more const and override qualifiers on functions where appropriate. -Add a global rand with a lock to be used very sparingly. -Use a map instead of a vector for bad param names in Xml parsing. -Prefix affine interpolation mode defines with "AFFINE_" to make their purpose more clear. -Allow for variations that change state during iteration by sending a separate copy of the ember to each rendering thread. -Implement this same functionality with a local struct in OpenCL. It's members are the total of all variables that need to change state within an ember. -Add Contains() function to Utils.h. -EmberRender: print names of kernels being printed with --dump_kernel option. -Clean up EmberTester to handle some of the recent changes. -Fix various casts. -Replace % 2 with & 1, even though the compiler was likely doing this already. -Add new file Variations06.h to accommodate new variations. -General cleanup.
240 lines
9.5 KiB
C++
240 lines
9.5 KiB
C++
#pragma once
|
|
|
|
#include "EmberCLPch.h"
|
|
#include "OpenCLWrapper.h"
|
|
#include "DEOpenCLKernelCreator.h"
|
|
#include "FinalAccumOpenCLKernelCreator.h"
|
|
#include "RendererClDevice.h"
|
|
|
|
/// <summary>
|
|
/// RendererCLBase and RendererCL classes.
|
|
/// </summary>
|
|
|
|
namespace EmberCLns
|
|
{
|
|
/// <summary>
|
|
/// Serves only as an interface for OpenCL specific rendering functions.
|
|
/// </summary>
|
|
class EMBERCL_API RendererCLBase
|
|
{
|
|
public:
|
|
virtual ~RendererCLBase() { }
|
|
virtual bool ReadFinal(byte* pixels) = 0;
|
|
virtual bool ClearFinal() = 0;
|
|
};
|
|
|
|
/// <summary>
|
|
/// RendererCL is a derivation of the basic CPU renderer which
|
|
/// overrides various functions to render on the GPU using OpenCL.
|
|
/// This supports multi-GPU rendering and is done in the following manner:
|
|
/// -When rendering a single image, the iterations will be split between devices in sub batches.
|
|
/// -When animating, a renderer for each device will be created by the calling code,
|
|
/// and the frames will each be rendered by a single device as available.
|
|
/// The synchronization across devices is done through a single atomic counter.
|
|
/// 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.
|
|
/// Template argument T expected to be float or double.
|
|
/// Template argument bucketT must always be float.
|
|
/// </summary>
|
|
template <typename T, typename bucketT>
|
|
class EMBERCL_API RendererCL : public Renderer<T, bucketT>, public RendererCLBase
|
|
{
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::Abort;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::EarlyClip;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::Transparency;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::EnterResize;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::LeaveResize;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::FinalRasW;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::FinalRasH;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::SuperRasW;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::SuperRasH;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::SuperSize;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::BytesPerChannel;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::TemporalSamples;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::ItersPerTemporalSample;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::FuseCount;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::DensityFilterOffset;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_ProgressParameter;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_YAxisUp;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_LockAccum;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_Abort;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_NumChannels;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_LastIter;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_LastIterPercent;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_Stats;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_Callback;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_Rand;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_RenderTimer;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_IterTimer;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_ProgressTimer;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::EmberReport::m_ErrorReport;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_ResizeCs;
|
|
using EmberNs::Renderer<T, bucketT>::RendererBase::m_ProcessAction;
|
|
using EmberNs::Renderer<T, bucketT>::m_RotMat;
|
|
using EmberNs::Renderer<T, bucketT>::m_Ember;
|
|
using EmberNs::Renderer<T, bucketT>::m_Csa;
|
|
using EmberNs::Renderer<T, bucketT>::m_CurvesSet;
|
|
using EmberNs::Renderer<T, bucketT>::CenterX;
|
|
using EmberNs::Renderer<T, bucketT>::CenterY;
|
|
using EmberNs::Renderer<T, bucketT>::K1;
|
|
using EmberNs::Renderer<T, bucketT>::K2;
|
|
using EmberNs::Renderer<T, bucketT>::Supersample;
|
|
using EmberNs::Renderer<T, bucketT>::HighlightPower;
|
|
using EmberNs::Renderer<T, bucketT>::HistBuckets;
|
|
using EmberNs::Renderer<T, bucketT>::AccumulatorBuckets;
|
|
using EmberNs::Renderer<T, bucketT>::GetDensityFilter;
|
|
using EmberNs::Renderer<T, bucketT>::GetSpatialFilter;
|
|
using EmberNs::Renderer<T, bucketT>::CoordMap;
|
|
using EmberNs::Renderer<T, bucketT>::XformDistributions;
|
|
using EmberNs::Renderer<T, bucketT>::XformDistributionsSize;
|
|
using EmberNs::Renderer<T, bucketT>::m_Dmap;
|
|
using EmberNs::Renderer<T, bucketT>::m_DensityFilter;
|
|
using EmberNs::Renderer<T, bucketT>::m_SpatialFilter;
|
|
|
|
public:
|
|
RendererCL(const vector<pair<size_t, size_t>>& devices, bool shared = false, GLuint outputTexID = 0);
|
|
~RendererCL();
|
|
|
|
//Non-virtual member functions for OpenCL specific tasks.
|
|
bool Init(const vector<pair<size_t, size_t>>& devices, bool shared, GLuint outputTexID);
|
|
bool SetOutputTexture(GLuint outputTexID);
|
|
|
|
//Iters per kernel/block/grid.
|
|
inline size_t IterCountPerKernel() const;
|
|
inline size_t IterCountPerBlock() const;
|
|
inline size_t IterCountPerGrid() const;
|
|
|
|
//Kernels per block.
|
|
inline size_t IterBlockKernelWidth() const;
|
|
inline size_t IterBlockKernelHeight() const;
|
|
inline size_t IterBlockKernelCount() const;
|
|
|
|
//Kernels per grid.
|
|
inline size_t IterGridKernelWidth() const;
|
|
inline size_t IterGridKernelHeight() const;
|
|
inline size_t IterGridKernelCount() const;
|
|
|
|
//Blocks per grid.
|
|
inline size_t IterGridBlockWidth() const;
|
|
inline size_t IterGridBlockHeight() const;
|
|
inline size_t IterGridBlockCount() const;
|
|
|
|
bool ReadHist(size_t device);
|
|
bool ReadAccum();
|
|
bool ReadPoints(size_t device, vector<PointCL<T>>& vec);
|
|
bool ClearHist();
|
|
bool ClearHist(size_t device);
|
|
bool ClearAccum();
|
|
bool WritePoints(size_t device, vector<PointCL<T>>& vec);
|
|
#ifdef TEST_CL
|
|
bool WriteRandomPoints(size_t device);
|
|
#endif
|
|
const string& IterKernel() const;
|
|
const string& DEKernel() const;
|
|
const string& FinalAccumKernel() const;
|
|
|
|
//Virtual functions overridden from RendererCLBase.
|
|
virtual bool ReadFinal(byte* 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 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;
|
|
virtual bool RandVec(vector<QTIsaac<ISAAC_SIZE, ISAAC_INT>>& randVec) override;
|
|
|
|
#ifndef TEST_CL
|
|
protected:
|
|
#endif
|
|
//Protected virtual functions overridden from Renderer.
|
|
virtual bool Alloc(bool histOnly = false) override;
|
|
virtual bool ResetBuckets(bool resetHist = true, bool resetAccum = true) override;
|
|
virtual eRenderStatus LogScaleDensityFilter(bool forceOutput = false) override;
|
|
virtual eRenderStatus GaussianDensityFilter() override;
|
|
virtual eRenderStatus AccumulatorToFinalImage(byte* pixels, size_t finalOffset) override;
|
|
virtual EmberStats Iterate(size_t iterCount, size_t temporalSample) override;
|
|
|
|
#ifndef TEST_CL
|
|
private:
|
|
#endif
|
|
void Init();
|
|
//Private functions for making and running OpenCL programs.
|
|
bool BuildIterProgramForEmber(bool doAccum = true);
|
|
bool RunIter(size_t iterCount, size_t temporalSample, size_t& itersRan);
|
|
eRenderStatus RunLogScaleFilter();
|
|
eRenderStatus RunDensityFilter();
|
|
eRenderStatus RunFinalAccum();
|
|
bool ClearBuffer(size_t device, const string& bufferName, uint width, uint height, uint elementSize);
|
|
bool RunDensityFilterPrivate(size_t kernelIndex, size_t gridW, size_t gridH, size_t blockW, size_t blockH, uint chunkSizeW, uint chunkSizeH, uint chunkW, uint chunkH);
|
|
int MakeAndGetDensityFilterProgram(size_t ss, uint filterWidth);
|
|
int MakeAndGetFinalAccumProgram(double& alphaBase, double& alphaScale);
|
|
int MakeAndGetGammaCorrectionProgram();
|
|
bool SumDeviceHist();
|
|
void FillSeeds();
|
|
|
|
//Private functions passing data to OpenCL programs.
|
|
void ConvertDensityFilter();
|
|
void ConvertSpatialFilter();
|
|
void ConvertEmber(Ember<T>& ember, EmberCL<T>& emberCL, vector<XformCL<T>>& xformsCL);
|
|
void ConvertCarToRas(const CarToRas<T>& carToRas);
|
|
|
|
bool m_Init;
|
|
bool m_DoublePrecision;
|
|
size_t m_IterCountPerKernel;
|
|
size_t m_IterBlocksWide, m_IterBlockWidth;
|
|
size_t m_IterBlocksHigh, m_IterBlockHeight;
|
|
size_t m_MaxDEBlockSizeW;
|
|
size_t m_MaxDEBlockSizeH;
|
|
|
|
//Buffer names.
|
|
string m_EmberBufferName;
|
|
string m_XformsBufferName;
|
|
string m_ParVarsBufferName;
|
|
string m_SeedsBufferName;
|
|
string m_DistBufferName;
|
|
string m_CarToRasBufferName;
|
|
string m_DEFilterParamsBufferName;
|
|
string m_SpatialFilterParamsBufferName;
|
|
string m_CurvesCsaName;
|
|
string m_DECoefsBufferName;
|
|
string m_DEWidthsBufferName;
|
|
string m_DECoefIndicesBufferName;
|
|
string m_SpatialFilterCoefsBufferName;
|
|
string m_HistBufferName;
|
|
string m_AccumBufferName;
|
|
string m_FinalImageName;
|
|
string m_PointsBufferName;
|
|
|
|
//Kernels.
|
|
string m_IterKernel;
|
|
|
|
cl::ImageFormat m_PaletteFormat;
|
|
cl::ImageFormat m_FinalFormat;
|
|
cl::Image2D m_Palette;
|
|
IMAGEGL2D m_AccumImage;
|
|
GLuint m_OutputTexID;
|
|
EmberCL<T> m_EmberCL;
|
|
vector<XformCL<T>> m_XformsCL;
|
|
vector<vector<glm::highp_uvec2>> m_Seeds;
|
|
CarToRasCL<T> m_CarToRasCL;
|
|
DensityFilterCL<bucketT> m_DensityFilterCL;
|
|
SpatialFilterCL<bucketT> m_SpatialFilterCL;
|
|
IterOpenCLKernelCreator<T> m_IterOpenCLKernelCreator;
|
|
DEOpenCLKernelCreator m_DEOpenCLKernelCreator;
|
|
FinalAccumOpenCLKernelCreator m_FinalAccumOpenCLKernelCreator;
|
|
pair<string, vector<T>> m_Params;
|
|
vector<unique_ptr<RendererClDevice>> m_Devices;
|
|
Ember<T> m_LastBuiltEmber;
|
|
};
|
|
}
|