From 47dd9fe35c74ec90bde905da71643429be8f5372 Mon Sep 17 00:00:00 2001 From: mfeemster Date: Fri, 5 Dec 2014 21:05:09 -0800 Subject: [PATCH] Replace unsigned int, and char with uint and uchar. --- Source/Ember/DensityFilter.h | 6 +- Source/Ember/EmberDefines.h | 24 +- Source/Ember/EmberPch.h | 3 + Source/Ember/Isaac.h | 5 +- Source/Ember/Iterator.h | 6 +- Source/Ember/Palette.h | 26 +- Source/Ember/PaletteList.h | 4 +- Source/Ember/Renderer.cpp | 38 +- Source/Ember/Renderer.h | 8 +- Source/Ember/RendererBase.cpp | 4 +- Source/Ember/RendererBase.h | 4 +- Source/Ember/SheepTools.h | 12 +- Source/Ember/Utils.h | 14 +- Source/Ember/VariationList.h | 10 +- Source/Ember/Variations02.h | 2 +- Source/Ember/Variations03.h | 4 +- Source/Ember/VariationsDC.h | 4 +- Source/Ember/XmlToEmber.h | 26 +- Source/EmberAnimate/EmberAnimate.cpp | 12 +- Source/EmberCL/DEOpenCLKernelCreator.cpp | 16 +- Source/EmberCL/DEOpenCLKernelCreator.h | 10 +- Source/EmberCL/EmberCLFunctions.h | 4 +- Source/EmberCL/EmberCLStructs.h | 42 +- .../EmberCL/FinalAccumOpenCLKernelCreator.cpp | 10 +- Source/EmberCL/IterOpenCLKernelCreator.h | 14 +- Source/EmberCL/OpenCLWrapper.cpp | 58 +- Source/EmberCL/OpenCLWrapper.h | 44 +- Source/EmberCL/RendererCL.cpp | 2956 ++++++++--------- Source/EmberCL/RendererCL.h | 56 +- Source/EmberCommon/EmberCommon.h | 14 +- Source/EmberCommon/EmberOptions.h | 50 +- Source/EmberCommon/JpegUtils.h | 40 +- Source/EmberCommon/SimpleGlob.h | 20 +- Source/EmberGenome/EmberGenome.cpp | 16 +- Source/EmberRender/EmberRender.cpp | 8 +- Source/EmberTester/EmberTester.cpp | 48 +- Source/Fractorium/EmberFile.h | 2 +- Source/Fractorium/EmberTreeWidgetItem.h | 2 +- Source/Fractorium/FinalRenderDialog.cpp | 16 +- Source/Fractorium/FinalRenderDialog.h | 14 +- .../Fractorium/FinalRenderEmberController.cpp | 12 +- .../Fractorium/FinalRenderEmberController.h | 20 +- Source/Fractorium/Fractorium.cpp | 2 +- Source/Fractorium/Fractorium.h | 4 +- .../Fractorium/FractoriumEmberController.cpp | 10 +- Source/Fractorium/FractoriumEmberController.h | 76 +- Source/Fractorium/FractoriumInfo.cpp | 2 +- Source/Fractorium/FractoriumLibrary.cpp | 14 +- Source/Fractorium/FractoriumMenus.cpp | 20 +- Source/Fractorium/FractoriumPalette.cpp | 10 +- Source/Fractorium/FractoriumParams.cpp | 6 +- Source/Fractorium/FractoriumRender.cpp | 14 +- Source/Fractorium/FractoriumSettings.cpp | 64 +- Source/Fractorium/FractoriumSettings.h | 64 +- Source/Fractorium/FractoriumXforms.cpp | 2 +- Source/Fractorium/FractoriumXformsColor.cpp | 2 +- .../Fractorium/FractoriumXformsVariations.cpp | 10 +- Source/Fractorium/FractoriumXformsXaos.cpp | 2 +- Source/Fractorium/GLEmberController.cpp | 4 +- Source/Fractorium/GLEmberController.h | 4 +- Source/Fractorium/GLWidget.cpp | 12 +- Source/Fractorium/OptionsDialog.cpp | 8 +- Source/Fractorium/OptionsDialog.h | 6 +- 63 files changed, 2013 insertions(+), 2007 deletions(-) diff --git a/Source/Ember/DensityFilter.h b/Source/Ember/DensityFilter.h index d0a006e..2757a37 100644 --- a/Source/Ember/DensityFilter.h +++ b/Source/Ember/DensityFilter.h @@ -110,7 +110,7 @@ public: int rowSize; size_t filterLoop; int keepThresh = 100; - unsigned int filterCoefIndex = 0; + uint filterCoefIndex = 0; T decFilterCount; T finalMinRad = m_MinRad * m_Supersample + 1;//Should scale the filter width by the oversample. T finalMaxRad = m_MaxRad * m_Supersample + 1;//The '+1' comes from the assumed distance to the first pixel. @@ -329,7 +329,7 @@ public: inline size_t CoefsIndicesSizeBytes() const { return (m_CoefIndices.size() * sizeof(m_CoefIndices[0])); } inline const T* Coefs() const { return m_Coefs.data(); } inline const T* Widths() const { return m_Widths.data(); } - inline const unsigned int* CoefIndices() const { return m_CoefIndices.data(); } + inline const uint* CoefIndices() const { return m_CoefIndices.data(); } private: T m_MinRad; @@ -342,6 +342,6 @@ private: intmax_t m_FilterWidth;//The new radius after scaling for super sample and rounding. This is what's actually used. vector m_Coefs; vector m_Widths; - vector m_CoefIndices; + vector m_CoefIndices; }; } \ No newline at end of file diff --git a/Source/Ember/EmberDefines.h b/Source/Ember/EmberDefines.h index 6dccb5a..cc0d6fc 100644 --- a/Source/Ember/EmberDefines.h +++ b/Source/Ember/EmberDefines.h @@ -73,6 +73,10 @@ namespace EmberNs #define FLOAT_MIN_TAN -FLOAT_MAX_TAN typedef std::chrono::high_resolution_clock Clock; +#ifndef byte + typedef unsigned char byte; +#endif + #define DO_DOUBLE 1//Comment this out for shorter build times during development. Always uncomment for release. //#define ISAAC_FLAM3_DEBUG 1//This is almost never needed, but is very useful when troubleshooting difficult bugs. Enable it to do a side by side comparison with flam3. @@ -84,14 +88,14 @@ typedef std::chrono::high_resolution_clock Clock; #define m4T glm::detail::tmat4x4 #define m23T glm::detail::tmat2x3 -enum eInterp : unsigned int { EMBER_INTERP_LINEAR = 0, EMBER_INTERP_SMOOTH = 1 }; -enum eAffineInterp : unsigned int { INTERP_LINEAR = 0, INTERP_LOG = 1, INTERP_COMPAT = 2, INTERP_OLDER = 3 }; -enum ePaletteMode : unsigned int { PALETTE_STEP = 0, PALETTE_LINEAR = 1 }; -enum ePaletteInterp : unsigned int { INTERP_HSV = 0, INTERP_SWEEP = 1 }; -enum eMotion : unsigned int { MOTION_SIN = 1, MOTION_TRIANGLE = 2, MOTION_HILL = 3 }; -enum eProcessAction : unsigned int { NOTHING = 0, ACCUM_ONLY = 1, FILTER_AND_ACCUM = 2, KEEP_ITERATING = 3, FULL_RENDER = 4 }; -enum eProcessState : unsigned int { NONE = 0, ITER_STARTED = 1, ITER_DONE = 2, FILTER_DONE = 3, ACCUM_DONE = 4 }; -enum eInteractiveFilter : unsigned int { FILTER_LOG = 0, FILTER_DE = 1 }; -enum eScaleType : unsigned int { SCALE_NONE = 0, SCALE_WIDTH = 1, SCALE_HEIGHT = 2 }; -enum eRenderStatus : unsigned int { RENDER_OK = 0, RENDER_ERROR = 1, RENDER_ABORT = 2 }; +enum eInterp : uint { EMBER_INTERP_LINEAR = 0, EMBER_INTERP_SMOOTH = 1 }; +enum eAffineInterp : uint { INTERP_LINEAR = 0, INTERP_LOG = 1, INTERP_COMPAT = 2, INTERP_OLDER = 3 }; +enum ePaletteMode : uint { PALETTE_STEP = 0, PALETTE_LINEAR = 1 }; +enum ePaletteInterp : uint { INTERP_HSV = 0, INTERP_SWEEP = 1 }; +enum eMotion : uint { MOTION_SIN = 1, MOTION_TRIANGLE = 2, MOTION_HILL = 3 }; +enum eProcessAction : uint { NOTHING = 0, ACCUM_ONLY = 1, FILTER_AND_ACCUM = 2, KEEP_ITERATING = 3, FULL_RENDER = 4 }; +enum eProcessState : uint { NONE = 0, ITER_STARTED = 1, ITER_DONE = 2, FILTER_DONE = 3, ACCUM_DONE = 4 }; +enum eInteractiveFilter : uint { FILTER_LOG = 0, FILTER_DE = 1 }; +enum eScaleType : uint { SCALE_NONE = 0, SCALE_WIDTH = 1, SCALE_HEIGHT = 2 }; +enum eRenderStatus : uint { RENDER_OK = 0, RENDER_ERROR = 1, RENDER_ABORT = 2 }; } diff --git a/Source/Ember/EmberPch.h b/Source/Ember/EmberPch.h index 739c56a..4701895 100644 --- a/Source/Ember/EmberPch.h +++ b/Source/Ember/EmberPch.h @@ -63,6 +63,7 @@ //glm is what's used for matrix math. #include "glm/glm.hpp" +#include "glm/detail/type_int.hpp" #include "glm/gtc/matrix_transform.hpp" #include "glm/gtc/type_ptr.hpp" #include "glm/gtx/string_cast.hpp" @@ -70,3 +71,5 @@ using namespace tbb; using namespace std; using namespace std::chrono; +using glm::uint; +using glm::uint16; diff --git a/Source/Ember/Isaac.h b/Source/Ember/Isaac.h index 56e8060..680cfbb 100644 --- a/Source/Ember/Isaac.h +++ b/Source/Ember/Isaac.h @@ -32,7 +32,7 @@ /// #ifndef __ISAAC64 - typedef unsigned int ISAAC_INT; + typedef uint ISAAC_INT; const ISAAC_INT GOLDEN_RATIO = ISAAC_INT(0x9e3779b9); #else typedef size_t ISAAC_INT; @@ -48,7 +48,6 @@ template class EMBER_API QTIsaac { public: - typedef unsigned char byte; enum { N = (1 << ALPHA) }; /// @@ -167,7 +166,7 @@ public: /// Returns a random 0 or 1. /// /// A random 0 or 1 - inline unsigned int RandBit() + inline uint RandBit() { return Rand() & 1; } diff --git a/Source/Ember/Iterator.h b/Source/Ember/Iterator.h index 29bd4e7..bd66f3e 100644 --- a/Source/Ember/Iterator.h +++ b/Source/Ember/Iterator.h @@ -68,7 +68,7 @@ public: /// /// Accessors. /// - const unsigned char* XformDistributions() const { return m_XformDistributions.empty() ? nullptr : &m_XformDistributions[0]; } + const byte* XformDistributions() const { return m_XformDistributions.empty() ? nullptr : &m_XformDistributions[0]; } const size_t XformDistributionsSize() const { return m_XformDistributions.size(); } /// @@ -146,7 +146,7 @@ public: while (tempDensity < currentDensityLimit && j < CHOOSE_XFORM_GRAIN) { //printf("offset = %d, xform = %d, running sum = %f\n", j, i, tempDensity); - m_XformDistributions[(distrib * CHOOSE_XFORM_GRAIN) + j] = (unsigned char)i; + m_XformDistributions[(distrib * CHOOSE_XFORM_GRAIN) + j] = (byte)i; tempDensity += densityPerElement; j++; } @@ -262,7 +262,7 @@ protected: return (size_t)m_XformDistributions[(index % CHOOSE_XFORM_GRAIN) + (CHOOSE_XFORM_GRAIN * distribOffset)]; } - vector m_XformDistributions; + vector m_XformDistributions; }; /// diff --git a/Source/Ember/Palette.h b/Source/Ember/Palette.h index 9345a47..3917c0b 100644 --- a/Source/Ember/Palette.h +++ b/Source/Ember/Palette.h @@ -39,7 +39,7 @@ public: /// The index in the palette file /// The size of the palette which should be 256 /// A pointer to 256 color entries - Palette(const string& name, int index, unsigned int size, v4T* xmlPaletteEntries) + Palette(const string& name, int index, uint size, v4T* xmlPaletteEntries) { m_Name = name; m_Index = index; @@ -52,7 +52,7 @@ public: else//They passed in null, so just fill with hard coded values so they at least have something. { //Palette 15 used in the test ember file. - unsigned char palette15[COLORMAP_LENGTH * 4] = { + byte palette15[COLORMAP_LENGTH * 4] = { 0x00, 0xda, 0xde, 0xbc, 0x00, 0xee, 0xe6, 0xc5, 0x00, 0xee, 0xf2, 0xce, 0x00, 0xee, 0xf2, 0xcf, 0x00, 0xe6, 0xee, 0xe1, 0x00, 0xea, 0xee, 0xd8, 0x00, 0xf2, 0xf1, 0xeb, 0x00, 0xf2, 0xf5, 0xd8, 0x00, 0xe6, 0xf2, 0xce, 0x00, 0xde, 0xea, 0xc5, 0x00, 0xd6, 0xda, 0xc6, 0x00, 0xce, 0xd2, 0xbc, 0x00, 0xc2, 0xca, 0xa9, 0x00, 0xbe, 0xca, 0xa0, 0x00, 0xce, 0xd6, 0xaa, 0x00, 0xde, 0xe2, 0xc5, 0x00, 0xea, 0xed, 0xce, 0x00, 0xea, 0xf2, 0xc5, 0x00, 0xde, 0xe2, 0xc5, 0x00, 0xc2, 0xca, 0xaa, 0x00, 0xae, 0xbe, 0xaa, 0x00, 0xa5, 0xb2, 0x96, 0x00, 0xa2, 0xa9, 0x8d, 0x00, 0x96, 0xa2, 0x84, @@ -86,7 +86,7 @@ public: 0x00, 0x81, 0x96, 0x8d, 0x00, 0x81, 0x9a, 0x8d, 0x00, 0x85, 0x9a, 0x8d, 0x00, 0x89, 0x9e, 0x8d, 0x00, 0x89, 0x9e, 0x8d, 0x00, 0x8d, 0xa2, 0x97, 0x00, 0x95, 0xa2, 0x97, 0x00, 0x8d, 0xa2, 0x97, 0x00, 0x96, 0xa6, 0x8d, 0x00, 0x9a, 0xa1, 0x8d, 0x00, 0x9e, 0xa9, 0x84, 0x00, 0x9e, 0xa6, 0x7a, 0x00, 0xa2, 0xa5, 0x71, 0x00, 0x9e, 0xa6, 0x71, 0x00, 0x9a, 0xa6, 0x71, 0x00, 0x95, 0x9d, 0x71 }; - for (unsigned int i = 0; i < size; i++) + for (uint i = 0; i < size; i++) { m_Entries[i].a = (T)palette15[i * 4 + 0]; m_Entries[i].r = (T)palette15[i * 4 + 1]; @@ -206,7 +206,7 @@ public: palette.m_Name = m_Name; palette.m_Entries.resize(Size()); - for (unsigned int i = 0; i < Size(); i++) + for (uint i = 0; i < Size(); i++) { size_t ii = (i * 256) / COLORMAP_LENGTH; T rgb[3], hsv[3]; @@ -241,7 +241,7 @@ public: /// Contrast -1 - 2 /// Blur 0 - 127 /// Frequency 1 - 10 - void MakeAdjustedPalette(Palette& palette, int rot, T hue, T sat, T bright, T cont, unsigned int blur, unsigned int freq) + void MakeAdjustedPalette(Palette& palette, int rot, T hue, T sat, T bright, T cont, uint blur, uint freq) { T rgb[3], hsv[3]; @@ -344,7 +344,7 @@ public: if (palette.Size() != Size()) palette.m_Entries.resize(Size()); - for (unsigned int j = 0; j < palette.Size(); j++) + for (uint j = 0; j < palette.Size(); j++) { palette.m_Entries[j] = m_Entries[j] * colorScalar; palette.m_Entries[j].a = 1; @@ -358,20 +358,20 @@ public: /// /// The height of the output block /// A vector holding the color values - vector MakeRgbPaletteBlock(unsigned int height) + vector MakeRgbPaletteBlock(uint height) { size_t width = Size(); - vector v(height * width * 3); + vector v(height * width * 3); if (v.size() == (height * Size() * 3)) { - for (unsigned int i = 0; i < height; i++) + for (uint i = 0; i < height; i++) { - for (unsigned int j = 0; j < width; j++) + for (uint j = 0; j < width; j++) { - v[(width * 3 * i) + (j * 3)] = (unsigned char)(m_Entries[j][0] * T(255));//Palettes are as [0..1], so convert to [0..255] here since it's for GUI display. - v[(width * 3 * i) + (j * 3) + 1] = (unsigned char)(m_Entries[j][1] * T(255)); - v[(width * 3 * i) + (j * 3) + 2] = (unsigned char)(m_Entries[j][2] * T(255)); + v[(width * 3 * i) + (j * 3)] = (byte)(m_Entries[j][0] * T(255));//Palettes are as [0..1], so convert to [0..255] here since it's for GUI display. + v[(width * 3 * i) + (j * 3) + 1] = (byte)(m_Entries[j][1] * T(255)); + v[(width * 3 * i) + (j * 3) + 2] = (byte)(m_Entries[j][2] * T(255)); } } } diff --git a/Source/Ember/PaletteList.h b/Source/Ember/PaletteList.h index f17c320..b882845 100644 --- a/Source/Ember/PaletteList.h +++ b/Source/Ember/PaletteList.h @@ -95,7 +95,7 @@ public: /// A pointer to the palette if found, else nullptr Palette* GetPaletteByName(const string&& name) { - for (unsigned int i = 0; i < Size(); i++) + for (uint i = 0; i < Size(); i++) if (m_Palettes[i].m_Name == name) return &m_Palettes[i]; @@ -166,7 +166,7 @@ private: if (!Compare(attr->name, "data")) { int colorIndex = 0; - unsigned int r, g, b; + uint r, g, b; int colorCount = 0; hexError = false; diff --git a/Source/Ember/Renderer.cpp b/Source/Ember/Renderer.cpp index 2e9b89f..47c40c6 100644 --- a/Source/Ember/Renderer.cpp +++ b/Source/Ember/Renderer.cpp @@ -318,7 +318,7 @@ bool Renderer::CreateTemporalFilter(bool& newAlloc) /// Offset in finalImage to store the pixels to. Default: 0. /// True if nothing went wrong, else false. template -eRenderStatus Renderer::Run(vector& finalImage, double time, size_t subBatchCountOverride, bool forceOutput, size_t finalOffset) +eRenderStatus Renderer::Run(vector& finalImage, double time, size_t subBatchCountOverride, bool forceOutput, size_t finalOffset) { m_InRender = true; EnterRender(); @@ -988,7 +988,7 @@ eRenderStatus Renderer::GaussianDensityFilter() /// Offset in the buffer to store the pixels to /// True if not prematurely aborted, else false. template -eRenderStatus Renderer::AccumulatorToFinalImage(vector& pixels, size_t finalOffset) +eRenderStatus Renderer::AccumulatorToFinalImage(vector& pixels, size_t finalOffset) { if (PrepFinalAccumVector(pixels)) return AccumulatorToFinalImage(pixels.data(), finalOffset); @@ -1004,7 +1004,7 @@ eRenderStatus Renderer::AccumulatorToFinalImage(vectorOffset in the buffer to store the pixels to. Default: 0. /// True if not prematurely aborted, else false. template -eRenderStatus Renderer::AccumulatorToFinalImage(unsigned char* pixels, size_t finalOffset) +eRenderStatus Renderer::AccumulatorToFinalImage(byte* pixels, size_t finalOffset) { if (!pixels) return RENDER_ERROR; @@ -1048,7 +1048,7 @@ eRenderStatus Renderer::AccumulatorToFinalImage(unsigned char* pixel Color newBucket; size_t pixelsRowStart = (m_YAxisUp ? ((FinalRasH() - j) - 1) : j) * FinalRowSize();//Pull out of inner loop for optimization. size_t y = m_DensityFilterOffset + (j * Supersample());//Start at the beginning row of each super sample block. - unsigned short* p16; + uint16* p16; for (size_t i = 0; i < FinalRasW(); i++, pixelsRowStart += PixelSize()) { @@ -1074,18 +1074,18 @@ eRenderStatus Renderer::AccumulatorToFinalImage(unsigned char* pixel if (BytesPerChannel() == 2) { - p16 = (unsigned short*)(pixels + pixelsRowStart); + p16 = (uint16*)(pixels + pixelsRowStart); if (EarlyClip()) { - p16[0] = (unsigned short)(Clamp(newBucket.r, 0, 255) * bucketT(256)); - p16[1] = (unsigned short)(Clamp(newBucket.g, 0, 255) * bucketT(256)); - p16[2] = (unsigned short)(Clamp(newBucket.b, 0, 255) * bucketT(256)); + p16[0] = (uint16)(Clamp(newBucket.r, 0, 255) * bucketT(256)); + p16[1] = (uint16)(Clamp(newBucket.g, 0, 255) * bucketT(256)); + p16[2] = (uint16)(Clamp(newBucket.b, 0, 255) * bucketT(256)); if (NumChannels() > 3) { if (Transparency()) - p16[3] = (unsigned char)(Clamp(newBucket.a, 0, 1) * bucketT(65535.0)); + p16[3] = (byte)(Clamp(newBucket.a, 0, 1) * bucketT(65535.0)); else p16[3] = 65535; } @@ -1099,14 +1099,14 @@ eRenderStatus Renderer::AccumulatorToFinalImage(unsigned char* pixel { if (EarlyClip()) { - pixels[pixelsRowStart] = (unsigned char)Clamp(newBucket.r, 0, 255); - pixels[pixelsRowStart + 1] = (unsigned char)Clamp(newBucket.g, 0, 255); - pixels[pixelsRowStart + 2] = (unsigned char)Clamp(newBucket.b, 0, 255); + pixels[pixelsRowStart] = (byte)Clamp(newBucket.r, 0, 255); + pixels[pixelsRowStart + 1] = (byte)Clamp(newBucket.g, 0, 255); + pixels[pixelsRowStart + 2] = (byte)Clamp(newBucket.b, 0, 255); if (NumChannels() > 3) { if (Transparency()) - pixels[pixelsRowStart + 3] = (unsigned char)(Clamp(newBucket.a, 0, 1) * bucketT(255.0)); + pixels[pixelsRowStart + 3] = (byte)(Clamp(newBucket.a, 0, 1) * bucketT(255.0)); else pixels[pixelsRowStart + 3] = 255; } @@ -1131,11 +1131,11 @@ eRenderStatus Renderer::AccumulatorToFinalImage(unsigned char* pixel { for (i = 0; i < FinalRasW(); i++) { - unsigned char* p = pixels + (NumChannels() * (i + j * FinalRasW())); + byte* p = pixels + (NumChannels() * (i + j * FinalRasW())); - p[0] = (unsigned char)(m_TempEmber.m_Palette[i * 256 / FinalRasW()][0] * WHITE);//The palette is [0..1], output image is [0..255]. - p[1] = (unsigned char)(m_TempEmber.m_Palette[i * 256 / FinalRasW()][1] * WHITE); - p[2] = (unsigned char)(m_TempEmber.m_Palette[i * 256 / FinalRasW()][2] * WHITE); + p[0] = (byte)(m_TempEmber.m_Palette[i * 256 / FinalRasW()][0] * WHITE);//The palette is [0..1], output image is [0..255]. + p[1] = (byte)(m_TempEmber.m_Palette[i * 256 / FinalRasW()][1] * WHITE); + p[2] = (byte)(m_TempEmber.m_Palette[i * 256 / FinalRasW()][2] * WHITE); } } } @@ -1357,7 +1357,7 @@ template size_t Renderer::FuseCount() /// Non-virtual iterator wrappers. /// -template const unsigned char* Renderer::XformDistributions() const { return m_Iterator != nullptr ? m_Iterator->XformDistributions() : nullptr; } +template const byte* Renderer::XformDistributions() const { return m_Iterator != nullptr ? m_Iterator->XformDistributions() : nullptr; } template const size_t Renderer::XformDistributionsSize() const { return m_Iterator != nullptr ? m_Iterator->XformDistributionsSize() : 0; } template Point* Renderer::Samples(size_t threadIndex) const { return threadIndex < m_Samples.size() ? (Point*)m_Samples[threadIndex].data() : nullptr; } @@ -1523,7 +1523,7 @@ void Renderer::AddToAccum(const glm::detail::tvec4 /// The pixel to correct diff --git a/Source/Ember/Renderer.h b/Source/Ember/Renderer.h index bd8f09f..345ef40 100644 --- a/Source/Ember/Renderer.h +++ b/Source/Ember/Renderer.h @@ -63,7 +63,7 @@ public: virtual bool CreateSpatialFilter(bool& newAlloc) override; virtual bool CreateTemporalFilter(bool& newAlloc) override; virtual size_t HistBucketSize() const override { return sizeof(glm::detail::tvec4); } - virtual eRenderStatus Run(vector& finalImage, double time = 0, size_t subBatchCountOverride = 0, bool forceOutput = false, size_t finalOffset = 0) override; + virtual eRenderStatus Run(vector& finalImage, double time = 0, size_t subBatchCountOverride = 0, bool forceOutput = false, size_t finalOffset = 0) override; virtual EmberImageComments ImageComments(EmberStats& stats, size_t printEditDepth = 0, bool intPalette = false, bool hexPalette = true) override; protected: @@ -73,8 +73,8 @@ protected: virtual bool ResetBuckets(bool resetHist = true, bool resetAccum = true); virtual eRenderStatus LogScaleDensityFilter(); virtual eRenderStatus GaussianDensityFilter(); - virtual eRenderStatus AccumulatorToFinalImage(vector& pixels, size_t finalOffset); - virtual eRenderStatus AccumulatorToFinalImage(unsigned char* pixels, size_t finalOffset); + virtual eRenderStatus AccumulatorToFinalImage(vector& pixels, size_t finalOffset); + virtual eRenderStatus AccumulatorToFinalImage(byte* pixels, size_t finalOffset); virtual EmberStats Iterate(size_t iterCount, size_t temporalSample); public: @@ -139,7 +139,7 @@ public: virtual size_t FuseCount() const override; //Non-virtual iterator wrappers. - const unsigned char* XformDistributions() const; + const byte* XformDistributions() const; const size_t XformDistributionsSize() const; Point* Samples(size_t threadIndex) const; diff --git a/Source/Ember/RendererBase.cpp b/Source/Ember/RendererBase.cpp index 0110d3f..e15358a 100644 --- a/Source/Ember/RendererBase.cpp +++ b/Source/Ember/RendererBase.cpp @@ -176,7 +176,7 @@ bool RendererBase::RandVec(vector>& randVec) /// /// The vector to allocate /// True if the vector contains enough space to hold the output image -bool RendererBase::PrepFinalAccumVector(vector& pixels) +bool RendererBase::PrepFinalAccumVector(vector& pixels) { EnterResize(); size_t size = FinalBufferSize(); @@ -470,7 +470,7 @@ void RendererBase::ThreadCount(size_t threads, const char* seedString) m_Rand.push_back(isaac); for (i = 0; i < (isaacSize * sizeof(ISAAC_INT)); i++) - ((unsigned char*)seeds)[i]++; + ((byte*)seeds)[i]++; } else { diff --git a/Source/Ember/RendererBase.h b/Source/Ember/RendererBase.h index cb0eb47..eb81bf7 100644 --- a/Source/Ember/RendererBase.h +++ b/Source/Ember/RendererBase.h @@ -100,7 +100,7 @@ public: void ChangeVal(std::function func, eProcessAction action); size_t MemoryRequired(size_t strips, bool includeFinal); vector> RandVec(); - bool PrepFinalAccumVector(vector& pixels); + bool PrepFinalAccumVector(vector& pixels); //Virtual processing functions. virtual bool Ok() const; @@ -117,7 +117,7 @@ public: virtual bool CreateTemporalFilter(bool& newAlloc) = 0; virtual void ComputeBounds() = 0; virtual void ComputeCamera() = 0; - virtual eRenderStatus Run(vector& finalImage, double time = 0, size_t subBatchCountOverride = 0, bool forceOutput = false, size_t finalOffset = 0) = 0; + virtual eRenderStatus Run(vector& finalImage, double time = 0, size_t subBatchCountOverride = 0, bool forceOutput = false, size_t finalOffset = 0) = 0; virtual EmberImageComments ImageComments(EmberStats& stats, size_t printEditDepth = 0, bool intPalette = false, bool hexPalette = true) = 0; virtual DensityFilterBase* GetDensityFilter() = 0; diff --git a/Source/Ember/SheepTools.h b/Source/Ember/SheepTools.h index cdc83ab..7ccbf47 100644 --- a/Source/Ember/SheepTools.h +++ b/Source/Ember/SheepTools.h @@ -285,7 +285,7 @@ public: else if (mode == MUTATE_POST_XFORMS) { bool same = (m_Rand.Rand() & 3) > 0;//25% chance of using the same post for all of them. - unsigned int b = 1 + m_Rand.Rand() % 6; + uint b = 1 + m_Rand.Rand() % 6; sprintf_s(ministr, 32, "(%d%s)", b, same ? " same" : ""); os << "mutate post xforms " << ministr; @@ -444,7 +444,7 @@ public: /// A string describing what was done string Cross(Ember& ember0, Ember& ember1, Ember& emberOut, int crossMode) { - unsigned int rb; + uint rb; size_t i; T t; ostringstream os; @@ -582,7 +582,7 @@ public: { //Select the starting parent. size_t ci; - unsigned int startParent = m_Rand.RandBit(); + uint startParent = m_Rand.RandBit(); os << " cmap_cross " << startParent << ":"; @@ -856,7 +856,7 @@ public: /// The number of histogram cells that weren't black T TryColors(Ember& ember, int colorResolution) { - unsigned char* p; + byte* p; size_t i, hits = 0, res = colorResolution; size_t pixTotal, res3 = res * res * res; T scalar; @@ -1389,8 +1389,8 @@ private: string m_Comment; vector> m_Samples; - vector m_FinalImage; - vector m_Hist; + vector m_FinalImage; + vector m_Hist; EmberToXml m_EmberToXml; Iterator* m_Iterator; unique_ptr> m_StandardIterator; diff --git a/Source/Ember/Utils.h b/Source/Ember/Utils.h index aeb927d..b52c1ef 100644 --- a/Source/Ember/Utils.h +++ b/Source/Ember/Utils.h @@ -159,7 +159,7 @@ protected: }; /// -/// Open a file in binary mode and read its entire contents into a vector of unsigned chars. Optionally null terminate. +/// Open a file in binary mode and read its entire contents into a vector of bytes. Optionally null terminate. /// /// The full path to the file to read /// The vector which will be populated with the file's contents @@ -262,7 +262,7 @@ static void CopyVec(vector& dest, const vector& source, std::function static void ClearVec(vector& vec, bool arrayDelete = false) { - for (unsigned int i = 0; i < vec.size(); i++) + for (uint i = 0; i < vec.size(); i++) { if (vec[i] != nullptr) { @@ -451,7 +451,7 @@ static inline float LRint(float x) /// The rounded value static inline double LRint(double x) { - int64_t temp = (x >= 0 ? (int64_t)(x + 0.5) : (int64_t)(x - 0.5)); + glm::int64_t temp = (x >= 0 ? (int64_t)(x + 0.5) : (int64_t)(x - 0.5)); return (double)temp; } @@ -893,7 +893,7 @@ int Arg(char* name, int def) } /// -/// Template specialization for Arg<>() with a type of unsigned int. +/// Template specialization for Arg<>() with a type of uint. /// /// The name of the environment variable to query /// The default value to return if the environment variable was not present @@ -902,7 +902,7 @@ template <> #ifdef _WIN32 static #endif -unsigned int Arg(char* name, unsigned int def) +uint Arg(char* name, uint def) { return Arg(name, (int)def); } @@ -1003,9 +1003,9 @@ string Arg(char* name, string def) /// The value to replace with /// The number of instances replaced template -static unsigned int FindAndReplace(T& source, const T& find, const T& replace) +static uint FindAndReplace(T& source, const T& find, const T& replace) { - unsigned int replaceCount = 0; + uint replaceCount = 0; typename T::size_type fLen = find.size(); typename T::size_type rLen = replace.size(); diff --git a/Source/Ember/VariationList.h b/Source/Ember/VariationList.h index fdde0fe..85aa6e3 100644 --- a/Source/Ember/VariationList.h +++ b/Source/Ember/VariationList.h @@ -355,7 +355,7 @@ public: //Keep a list of which variations derive from ParametricVariation. //Note that these are not new copies, rather just pointers to the original instances in m_Variations. - for (unsigned int i = 0; i < m_Variations.size(); i++) + for (uint i = 0; i < m_Variations.size(); i++) { if (ParametricVariation* parVar = dynamic_cast*>(m_Variations[i])) m_ParametricVariations.push_back(parVar); @@ -412,7 +412,7 @@ public: /// A pointer to the variation if found, else nullptr. Variation* GetVariation(eVariationId id) { - for (unsigned int i = 0; i < m_Variations.size() && m_Variations[i] != nullptr; i++) + for (uint i = 0; i < m_Variations.size() && m_Variations[i] != nullptr; i++) if (id == m_Variations[i]->VariationId()) return m_Variations[i]; @@ -435,7 +435,7 @@ public: /// A pointer to the variation if found, else nullptr. Variation* GetVariation(const string& name) { - for (unsigned int i = 0; i < m_Variations.size() && m_Variations[i] != nullptr; i++) + for (uint i = 0; i < m_Variations.size() && m_Variations[i] != nullptr; i++) if (!_stricmp(name.c_str(), m_Variations[i]->Name().c_str())) return m_Variations[i]; @@ -466,7 +466,7 @@ public: /// The parametric variation with a matching name, else nullptr. ParametricVariation* GetParametricVariation(const string& name) { - for (unsigned int i = 0; i < m_ParametricVariations.size() && m_ParametricVariations[i] != nullptr; i++) + for (uint i = 0; i < m_ParametricVariations.size() && m_ParametricVariations[i] != nullptr; i++) if (!_stricmp(name.c_str(), m_ParametricVariations[i]->Name().c_str())) return m_ParametricVariations[i]; @@ -480,7 +480,7 @@ public: /// The index of the variation with the matching name, else -1 int GetVariationIndex(const string& name) { - for (unsigned int i = 0; i < m_Variations.size() && m_Variations[i] != nullptr; i++) + for (uint i = 0; i < m_Variations.size() && m_Variations[i] != nullptr; i++) if (!_stricmp(name.c_str(), m_Variations[i]->Name().c_str())) return i; diff --git a/Source/Ember/Variations02.h b/Source/Ember/Variations02.h index 3fc825f..2febec8 100644 --- a/Source/Ember/Variations02.h +++ b/Source/Ember/Variations02.h @@ -5594,7 +5594,7 @@ public: virtual void Func(IteratorHelper& helper, Point& outPoint, QTIsaac& rand) override { T a = helper.m_PrecalcAtanyx; - int n = rand.Rand((unsigned int)m_Spread); + int n = rand.Rand((uint)m_Spread); if (a < 0) n++; diff --git a/Source/Ember/Variations03.h b/Source/Ember/Variations03.h index 5c92a90..e672cec 100644 --- a/Source/Ember/Variations03.h +++ b/Source/Ember/Variations03.h @@ -1495,7 +1495,7 @@ public: T z = helper.In.z / m_AbsN; T r = m_Weight * pow(helper.m_PrecalcSumSquares + SQR(z), m_Cn); T tmp = r * helper.m_PrecalcSqrtSumSquares; - T ang = (helper.m_PrecalcAtanyx + M_2PI * rand.Rand((unsigned int)m_AbsN)) / m_N; + T ang = (helper.m_PrecalcAtanyx + M_2PI * rand.Rand((uint)m_AbsN)) / m_N; helper.Out.x = tmp * cos(ang); helper.Out.y = tmp * sin(ang); @@ -1574,7 +1574,7 @@ public: virtual void Func(IteratorHelper& helper, Point& outPoint, QTIsaac& rand) override { T r = m_Weight * pow(helper.m_PrecalcSumSquares, m_Cn); - T temp = (helper.m_PrecalcAtanyx + M_2PI * rand.Rand((unsigned int)m_AbsN)) / m_N; + T temp = (helper.m_PrecalcAtanyx + M_2PI * rand.Rand((uint)m_AbsN)) / m_N; helper.Out.x = r * cos(temp); helper.Out.y = r * sin(temp); diff --git a/Source/Ember/VariationsDC.h b/Source/Ember/VariationsDC.h index c65fb18..8308537 100644 --- a/Source/Ember/VariationsDC.h +++ b/Source/Ember/VariationsDC.h @@ -183,8 +183,8 @@ public: T x, y, z; T p = 2 * rand.Frand01() - 1; T q = 2 * rand.Frand01() - 1; - unsigned int i = rand.Rand(3); - unsigned int j = rand.RandBit(); + uint i = rand.Rand(3); + uint j = rand.RandBit(); switch (i) { diff --git a/Source/Ember/XmlToEmber.h b/Source/Ember/XmlToEmber.h index 755a638..b3d0573 100644 --- a/Source/Ember/XmlToEmber.h +++ b/Source/Ember/XmlToEmber.h @@ -250,7 +250,7 @@ public: /// Full path and filename, optionally empty /// The newly constructed embers based on what was parsed /// True if there were no errors, else false. - bool Parse(unsigned char* buf, const char* filename, vector>& embers) + bool Parse(byte* buf, const char* filename, vector>& embers) { char* bn; const char* xmlPtr; @@ -310,7 +310,7 @@ public: //An adjustment of +/- 360 degrees is made until this is true. if (emberSize > 1) { - for (unsigned int i = 1; i < emberSize; i++) + for (uint i = 1; i < emberSize; i++) { //Only do this adjustment if not in compat mode.. if (embers[i - 1].m_AffineInterp != INTERP_COMPAT && embers[i - 1].m_AffineInterp != INTERP_OLDER) @@ -349,7 +349,7 @@ public: if (ReadFile(filename, buf)) { std::replace(buf.begin(), buf.end(), '&', '+'); - return Parse((unsigned char*)buf.data(), filename, embers); + return Parse((byte*)buf.data(), filename, embers); } else return false; @@ -395,19 +395,19 @@ public: /// See error report for errors. /// /// The string to convert - /// The converted unsigned integer value + /// The converted uinteger value /// True if success, else false. - bool Atoi(const char* str, unsigned int& val) + bool Atoi(const char* str, uint& val) { return Atoi(str, (int&)val); } /// - /// Convert the string to an unsigned integer value and return a bool indicating success. + /// Convert the string to an uinteger value and return a bool indicating success. /// See error report for errors. /// /// The string to convert - /// The converted unsigned integer value + /// The converted uinteger value /// True if success, else false. bool Atoi(const char* str, int& val) { @@ -542,11 +542,11 @@ private: bool ParseEmberElement(xmlNode* emberNode, Ember& currentEmber) { bool ret = true; - unsigned int newLinear = 0; + uint newLinear = 0; char* attStr; const char* loc = __FUNCTION__; int soloXform = -1; - unsigned int i, count, index = 0; + uint i, count, index = 0; double vals[10]; xmlAttrPtr att, curAtt; xmlNodePtr editNode, childNode, motionNode; @@ -1041,7 +1041,7 @@ private: bool success = true; char* attStr; const char* loc = __FUNCTION__; - unsigned int j; + uint j; T temp; double a, b, c, d, e, f; double vals[10]; @@ -1203,7 +1203,7 @@ private: if (Atof(attStr, temp)) { - unsigned int iTemp = (unsigned int)temp; + uint iTemp = (uint)temp; if (iTemp < xform.TotalVariationCount()) { @@ -1246,7 +1246,7 @@ private: } //Now that all xforms have been parsed, go through and try to find params for the parametric variations. - for (unsigned int i = 0; i < xform.TotalVariationCount(); i++) + for (uint i = 0; i < xform.TotalVariationCount(); i++) { if (ParametricVariation* parVar = dynamic_cast*>(xform.GetVariation(i))) { @@ -1361,7 +1361,7 @@ private: { int colorIndex = 0; int colorCount = 0; - unsigned int r, g, b, a; + uint r, g, b, a; int ret; char tmps[2]; int skip = (int)abs(chan); diff --git a/Source/EmberAnimate/EmberAnimate.cpp b/Source/EmberAnimate/EmberAnimate.cpp index adf668a..fed5fe9 100644 --- a/Source/EmberAnimate/EmberAnimate.cpp +++ b/Source/EmberAnimate/EmberAnimate.cpp @@ -32,11 +32,11 @@ bool EmberAnimate(EmberOptions& opt) bool startXml = false; bool finishXml = false; bool appendXml = false; - unsigned char* finalImagep; - unsigned int i, channels, ftime; + byte* finalImagep; + uint i, channels, ftime; string s, flameName, filename, inputPath = GetPath(opt.Input()); ostringstream os; - vector finalImage, vecRgb; + vector finalImage, vecRgb; vector> embers; EmberStats stats; EmberReport emberReport; @@ -190,8 +190,8 @@ bool EmberAnimate(EmberOptions& opt) embers[i].m_SubBatchSize = opt.SubBatchSize(); embers[i].m_Quality *= T(opt.QualityScale()); - embers[i].m_FinalRasW = (unsigned int)((T)embers[i].m_FinalRasW * opt.SizeScale()); - embers[i].m_FinalRasH = (unsigned int)((T)embers[i].m_FinalRasH * opt.SizeScale()); + embers[i].m_FinalRasW = (uint)((T)embers[i].m_FinalRasW * opt.SizeScale()); + embers[i].m_FinalRasH = (uint)((T)embers[i].m_FinalRasH * opt.SizeScale()); embers[i].m_PixelsPerUnit *= T(opt.SizeScale()); //Cast to double in case the value exceeds 2^32. @@ -236,7 +236,7 @@ bool EmberAnimate(EmberOptions& opt) opt.FirstFrame((int)embers[0].m_Time); if (opt.LastFrame() == UINT_MAX) - opt.LastFrame(ClampGte((unsigned int)embers.back().m_Time - 1, opt.FirstFrame())); + opt.LastFrame(ClampGte((uint)embers.back().m_Time - 1, opt.FirstFrame())); } if (!opt.Out().empty()) diff --git a/Source/EmberCL/DEOpenCLKernelCreator.cpp b/Source/EmberCL/DEOpenCLKernelCreator.cpp index 0fdeb32..2863210 100644 --- a/Source/EmberCL/DEOpenCLKernelCreator.cpp +++ b/Source/EmberCL/DEOpenCLKernelCreator.cpp @@ -97,7 +97,7 @@ template string DEOpenCLKernelCreator::LogScaleAssignDEEntryPoin /// Filter width /// The kernel source template -string DEOpenCLKernelCreator::GaussianDEKernel(size_t ss, unsigned int filterWidth) +string DEOpenCLKernelCreator::GaussianDEKernel(size_t ss, uint filterWidth) { #ifndef ROW_ONLY_DE if ((typeid(T) == typeid(double)) || (filterWidth > MaxDEFilterSize()))//Type double does not use cache. @@ -134,7 +134,7 @@ string DEOpenCLKernelCreator::GaussianDEKernel(size_t ss, unsigned int filter /// Filter width /// The name of the density estimation filtering entry point kernel function template -string DEOpenCLKernelCreator::GaussianDEEntryPoint(size_t ss, unsigned int filterWidth) +string DEOpenCLKernelCreator::GaussianDEEntryPoint(size_t ss, uint filterWidth) { #ifndef ROW_ONLY_DE if ((typeid(T) == typeid(double)) || (filterWidth > MaxDEFilterSize()))//Type double does not use cache. @@ -170,11 +170,11 @@ string DEOpenCLKernelCreator::GaussianDEEntryPoint(size_t ss, unsigned int fi /// /// The maximum filter size allowed for running the local memory version of density filtering template -unsigned int DEOpenCLKernelCreator::MaxDEFilterSize() { return 9; }//The true max would be (maxBoxSize - 1) / 2, but that's impractical because it can give us a tiny block size. +uint DEOpenCLKernelCreator::MaxDEFilterSize() { return 9; }//The true max would be (maxBoxSize - 1) / 2, but that's impractical because it can give us a tiny block size. /// /// Solve for the maximum filter radius. -/// The final filter width is calculated by: (unsigned int)(ceil(m_MaxRad) * (T)m_Supersample) + (m_Supersample - 1); +/// The final filter width is calculated by: (uint)(ceil(m_MaxRad) * (T)m_Supersample) + (m_Supersample - 1); /// Must solve for what max rad should be in order to give a maximum final width of (maxBoxSize - 1) / 2, assuming /// a minimum block size of 1 which processes 1 pixel. /// Example: If a box size of 20 was allowed, a filter @@ -186,9 +186,9 @@ unsigned int DEOpenCLKernelCreator::MaxDEFilterSize() { return 9; }//The true /// The supersample being used /// The maximum filter radius allowed template -T DEOpenCLKernelCreator::SolveMaxDERad(unsigned int maxBoxSize, T desiredFilterSize, T ss) +T DEOpenCLKernelCreator::SolveMaxDERad(uint maxBoxSize, T desiredFilterSize, T ss) { - unsigned int finalFilterSize = (unsigned int)((ceil(desiredFilterSize) * ss) + (ss - 1.0)); + uint finalFilterSize = (uint)((ceil(desiredFilterSize) * ss) + (ss - 1.0)); //Return the desired size if the final size of it will fit. if (finalFilterSize <= MaxDEFilterSize()) @@ -205,9 +205,9 @@ T DEOpenCLKernelCreator::SolveMaxDERad(unsigned int maxBoxSize, T desiredFilt /// The local memory available to a block /// The maximum filter box size allowed template -unsigned int DEOpenCLKernelCreator::SolveMaxBoxSize(unsigned int localMem) +uint DEOpenCLKernelCreator::SolveMaxBoxSize(uint localMem) { - return (unsigned int)floor(sqrt(floor((T)localMem / 16.0)));//Divide by 16 because each element is float4. + return (uint)floor(sqrt(floor((T)localMem / 16.0)));//Divide by 16 because each element is float4. } /// diff --git a/Source/EmberCL/DEOpenCLKernelCreator.h b/Source/EmberCL/DEOpenCLKernelCreator.h index 7461781..075fd3b 100644 --- a/Source/EmberCL/DEOpenCLKernelCreator.h +++ b/Source/EmberCL/DEOpenCLKernelCreator.h @@ -39,13 +39,13 @@ public: //Accessors. string LogScaleAssignDEKernel(); string LogScaleAssignDEEntryPoint(); - string GaussianDEKernel(size_t ss, unsigned int filterWidth); - string GaussianDEEntryPoint(size_t ss, unsigned int filterWidth); + string GaussianDEKernel(size_t ss, uint filterWidth); + string GaussianDEEntryPoint(size_t ss, uint filterWidth); //Miscellaneous static functions. - static unsigned int MaxDEFilterSize(); - static T SolveMaxDERad(unsigned int maxBoxSize, T desiredFilterSize, T ss); - static unsigned int SolveMaxBoxSize(unsigned int localMem); + static uint MaxDEFilterSize(); + static T SolveMaxDERad(uint maxBoxSize, T desiredFilterSize, T ss); + static uint SolveMaxBoxSize(uint localMem); private: //Kernel creators. diff --git a/Source/EmberCL/EmberCLFunctions.h b/Source/EmberCL/EmberCLFunctions.h index f98ed31..657f16f 100644 --- a/Source/EmberCL/EmberCLFunctions.h +++ b/Source/EmberCL/EmberCLFunctions.h @@ -322,9 +322,9 @@ static const char* AddToAccumWithCheckFunctionString = /// OpenCL equivalent various CarToRas member functions. /// static const char* CarToRasFunctionString = - "inline void CarToRasConvertPointToSingle(__constant CarToRasCL* carToRas, Point* point, unsigned int* singleBufferIndex)\n" + "inline void CarToRasConvertPointToSingle(__constant CarToRasCL* carToRas, Point* point, uint* singleBufferIndex)\n" "{\n" - " *singleBufferIndex = (unsigned int)(carToRas->m_PixPerImageUnitW * point->m_X - carToRas->m_RasLlX) + (carToRas->m_RasWidth * (unsigned int)(carToRas->m_PixPerImageUnitH * point->m_Y - carToRas->m_RasLlY));\n" + " *singleBufferIndex = (uint)(carToRas->m_PixPerImageUnitW * point->m_X - carToRas->m_RasLlX) + (carToRas->m_RasWidth * (uint)(carToRas->m_PixPerImageUnitH * point->m_Y - carToRas->m_RasLlY));\n" "}\n" "\n" "inline bool CarToRasInBounds(__constant CarToRasCL* carToRas, Point* point)\n" diff --git a/Source/EmberCL/EmberCLStructs.h b/Source/EmberCL/EmberCLStructs.h index 74d0149..6409c1c 100644 --- a/Source/EmberCL/EmberCLStructs.h +++ b/Source/EmberCL/EmberCLStructs.h @@ -48,7 +48,7 @@ static string ConstantDefinesString(bool doublePrecision) else { os << "typedef int intPrec;\n" - "typedef unsigned int atomi;\n" + "typedef uint atomi;\n" "typedef float real_t;\n" "typedef float4 real4;\n" "#define EPS (FLT_EPSILON)\n" @@ -131,7 +131,7 @@ struct ALIGN PointCL T m_Y; T m_Z; T m_ColorX; - unsigned int m_LastXfUsed; + uint m_LastXfUsed; }; /// @@ -239,7 +239,7 @@ template struct ALIGN CarToRasCL { T m_PixPerImageUnitW, m_RasLlX; - unsigned int m_RasWidth; + uint m_RasWidth; T m_PixPerImageUnitH, m_RasLlY; T m_CarLlX, m_CarUrX, m_CarUrY, m_CarLlY; }; @@ -268,13 +268,13 @@ struct ALIGN DensityFilterCL T m_Curve; T m_K1; T m_K2; - unsigned int m_Supersample; - unsigned int m_SuperRasW; - unsigned int m_SuperRasH; - unsigned int m_KernelSize; - unsigned int m_MaxFilterIndex; - unsigned int m_MaxFilteredCounts; - unsigned int m_FilterWidth; + uint m_Supersample; + uint m_SuperRasW; + uint m_SuperRasH; + uint m_KernelSize; + uint m_MaxFilterIndex; + uint m_MaxFilteredCounts; + uint m_FilterWidth; }; /// @@ -304,17 +304,17 @@ static const char* DensityFilterCLStructString = template struct ALIGN SpatialFilterCL { - unsigned int m_SuperRasW; - unsigned int m_SuperRasH; - unsigned int m_FinalRasW; - unsigned int m_FinalRasH; - unsigned int m_Supersample; - unsigned int m_FilterWidth; - unsigned int m_NumChannels; - unsigned int m_BytesPerChannel; - unsigned int m_DensityFilterOffset; - unsigned int m_Transparency; - unsigned int m_YAxisUp; + uint m_SuperRasW; + uint m_SuperRasH; + uint m_FinalRasW; + uint m_FinalRasH; + uint m_Supersample; + uint m_FilterWidth; + uint m_NumChannels; + uint m_BytesPerChannel; + uint m_DensityFilterOffset; + uint m_Transparency; + uint m_YAxisUp; T m_Vibrancy; T m_HighlightPower; T m_Gamma; diff --git a/Source/EmberCL/FinalAccumOpenCLKernelCreator.cpp b/Source/EmberCL/FinalAccumOpenCLKernelCreator.cpp index 99506cd..a4650fe 100644 --- a/Source/EmberCL/FinalAccumOpenCLKernelCreator.cpp +++ b/Source/EmberCL/FinalAccumOpenCLKernelCreator.cpp @@ -239,15 +239,15 @@ string FinalAccumOpenCLKernelCreator::CreateFinalAccumKernelString(bool early " if ((GLOBAL_ID_Y >= spatialFilter->m_FinalRasH) || (GLOBAL_ID_X >= spatialFilter->m_FinalRasW))\n" " return;\n" "\n" - " unsigned int accumX = spatialFilter->m_DensityFilterOffset + (GLOBAL_ID_X * spatialFilter->m_Supersample);\n" - " unsigned int accumY = spatialFilter->m_DensityFilterOffset + (GLOBAL_ID_Y * spatialFilter->m_Supersample);\n" + " uint accumX = spatialFilter->m_DensityFilterOffset + (GLOBAL_ID_X * spatialFilter->m_Supersample);\n" + " uint accumY = spatialFilter->m_DensityFilterOffset + (GLOBAL_ID_Y * spatialFilter->m_Supersample);\n" " int2 finalCoord;\n" " finalCoord.x = GLOBAL_ID_X;\n" " finalCoord.y = (int)((spatialFilter->m_YAxisUp == 1) ? ((spatialFilter->m_FinalRasH - GLOBAL_ID_Y) - 1) : GLOBAL_ID_Y);\n" " float4floats finalColor;\n" " real_t alpha, ls;\n" " int ii, jj;\n" - " unsigned int filterKRowIndex;\n" + " uint filterKRowIndex;\n" " const __global real4reals* accumBucket;\n" " real4reals newBucket;\n" " newBucket.m_Real4 = 0;\n" @@ -356,7 +356,7 @@ string FinalAccumOpenCLKernelCreator::CreateGammaCorrectionFunctionString(boo << "\n" << " CalcNewRgb(bucket, ls, highlightPower, &newRgb);\n" << "\n" - << " for (unsigned int rgbi = 0; rgbi < 3; rgbi++)\n" + << " for (uint rgbi = 0; rgbi < 3; rgbi++)\n" << " {\n" << " a = newRgb.m_Reals[rgbi] + ((1.0 - vibrancy) * 256.0 * pow(bucket->m_Reals[rgbi], g));\n" << "\n"; @@ -504,7 +504,7 @@ string FinalAccumOpenCLKernelCreator::CreateGammaCorrectionKernelString(bool " if (GLOBAL_ID_Y >= (spatialFilter->m_SuperRasH - testGutter) || GLOBAL_ID_X >= (spatialFilter->m_SuperRasW - testGutter))\n" " return;\n" "\n" - " unsigned int superIndex = (GLOBAL_ID_Y * spatialFilter->m_SuperRasW) + GLOBAL_ID_X;\n" + " uint superIndex = (GLOBAL_ID_Y * spatialFilter->m_SuperRasW) + GLOBAL_ID_X;\n" " __global real4reals* bucket = accumulator + superIndex;\n" //Pass in an alphaBase and alphaScale of 0, 1 which means to just directly assign the computed alpha value. " GammaCorrectionFloats(bucket, &(spatialFilter->m_Background[0]), spatialFilter->m_Gamma, spatialFilter->m_LinRange, spatialFilter->m_Vibrancy, spatialFilter->m_HighlightPower, 0.0, 1.0, &(bucket->m_Reals[0]));\n" diff --git a/Source/EmberCL/IterOpenCLKernelCreator.h b/Source/EmberCL/IterOpenCLKernelCreator.h index dda34c2..6e641c2 100644 --- a/Source/EmberCL/IterOpenCLKernelCreator.h +++ b/Source/EmberCL/IterOpenCLKernelCreator.h @@ -59,10 +59,10 @@ private: //template EMBERCL_API bool IterOpenCLKernelCreator::IsBuildRequired(Ember& ember1, Ember& ember2); #ifdef OPEN_CL_TEST_AREA -typedef void (*KernelFuncPointer) (unsigned int gridWidth, unsigned int gridHeight, unsigned int blockWidth, unsigned int blockHeight, - unsigned int BLOCK_ID_X, unsigned int BLOCK_ID_Y, unsigned int THREAD_ID_X, unsigned int THREAD_ID_Y); +typedef void (*KernelFuncPointer) (uint gridWidth, uint gridHeight, uint blockWidth, uint blockHeight, + uint BLOCK_ID_X, uint BLOCK_ID_Y, uint THREAD_ID_X, uint THREAD_ID_Y); -static void OpenCLSim(unsigned int gridWidth, unsigned int gridHeight, unsigned int blockWidth, unsigned int blockHeight, KernelFuncPointer func) +static void OpenCLSim(uint gridWidth, uint gridHeight, uint blockWidth, uint blockHeight, KernelFuncPointer func) { cout << "OpenCLSim(): " << endl; cout << " Params: " << endl; @@ -71,13 +71,13 @@ static void OpenCLSim(unsigned int gridWidth, unsigned int gridHeight, unsigned cout << " blockW: " << blockWidth << endl; cout << " blockH: " << blockHeight << endl; - for (unsigned int i = 0; i < gridHeight; i += blockHeight) + for (uint i = 0; i < gridHeight; i += blockHeight) { - for (unsigned int j = 0; j < gridWidth; j += blockWidth) + for (uint j = 0; j < gridWidth; j += blockWidth) { - for (unsigned int k = 0; k < blockHeight; k++) + for (uint k = 0; k < blockHeight; k++) { - for (unsigned int l = 0; l < blockWidth; l++) + for (uint l = 0; l < blockWidth; l++) { func(gridWidth, gridHeight, blockWidth, blockHeight, j / blockWidth, i / blockHeight, l, k); } diff --git a/Source/EmberCL/OpenCLWrapper.cpp b/Source/EmberCL/OpenCLWrapper.cpp index 79ea985..9cd5d69 100644 --- a/Source/EmberCL/OpenCLWrapper.cpp +++ b/Source/EmberCL/OpenCLWrapper.cpp @@ -42,7 +42,7 @@ bool OpenCLWrapper::CheckOpenCL() /// The index device of the device to use /// True if shared with OpenGL, else false. /// True if success, else false. -bool OpenCLWrapper::Init(unsigned int platform, unsigned int device, bool shared) +bool OpenCLWrapper::Init(uint platform, uint device, bool shared) { cl_int err; @@ -70,7 +70,7 @@ bool OpenCLWrapper::Init(unsigned int platform, unsigned int device, bool shared m_Device = m_Devices[m_PlatformIndex][device]; m_DeviceVec.clear(); m_DeviceVec.push_back(m_Device); - m_LocalMemSize = (unsigned int)GetInfo(m_PlatformIndex, m_DeviceIndex, CL_DEVICE_LOCAL_MEM_SIZE); + m_LocalMemSize = (uint)GetInfo(m_PlatformIndex, m_DeviceIndex, CL_DEVICE_LOCAL_MEM_SIZE); m_Shared = shared; m_Init = true;//Command queue is ok, it's now ok to begin building and running programs. } @@ -215,7 +215,7 @@ bool OpenCLWrapper::WriteBuffer(const string& name, void* data, size_t size) /// A pointer to the buffer /// The size in bytes of the buffer /// True if success, else false. -bool OpenCLWrapper::WriteBuffer(unsigned int bufferIndex, void* data, size_t size) +bool OpenCLWrapper::WriteBuffer(uint bufferIndex, void* data, size_t size) { if (m_Init && (bufferIndex < m_Buffers.size()) && (GetBufferSize(bufferIndex) == size)) { @@ -253,7 +253,7 @@ bool OpenCLWrapper::ReadBuffer(const string& name, void* data, size_t size) /// A pointer to a buffer to copy the data to /// The size in bytes of the buffer /// True if success, else false. -bool OpenCLWrapper::ReadBuffer(unsigned int bufferIndex, void* data, size_t size) +bool OpenCLWrapper::ReadBuffer(uint bufferIndex, void* data, size_t size) { if (m_Init && (bufferIndex < m_Buffers.size()) && (GetBufferSize(bufferIndex) == size)) { @@ -277,7 +277,7 @@ bool OpenCLWrapper::ReadBuffer(unsigned int bufferIndex, void* data, size_t size /// The index if found, else -1. int OpenCLWrapper::FindBufferIndex(const string& name) { - for (unsigned int i = 0; i < m_Buffers.size(); i++) + for (uint i = 0; i < m_Buffers.size(); i++) if (m_Buffers[i].m_Name == name) return (int)i; @@ -289,7 +289,7 @@ int OpenCLWrapper::FindBufferIndex(const string& name) /// /// The name of the buffer to search for /// The size of the buffer if found, else 0. -unsigned int OpenCLWrapper::GetBufferSize(const string& name) +uint OpenCLWrapper::GetBufferSize(const string& name) { int bufferIndex = FindBufferIndex(name); @@ -301,10 +301,10 @@ unsigned int OpenCLWrapper::GetBufferSize(const string& name) /// /// The index of the buffer to get the size of /// The size of the buffer if found, else 0. -unsigned int OpenCLWrapper::GetBufferSize(unsigned int bufferIndex) +uint OpenCLWrapper::GetBufferSize(uint bufferIndex) { if (m_Init && bufferIndex < m_Buffers.size()) - return (unsigned int)m_Buffers[bufferIndex].m_Buffer.getInfo(nullptr); + return (uint)m_Buffers[bufferIndex].m_Buffer.getInfo(nullptr); return 0; } @@ -355,7 +355,7 @@ bool OpenCLWrapper::AddAndWriteImage(const string& name, cl_mem_flags flags, con m_GLImages.push_back(namedImageGL); if (data) - return WriteImage2D((unsigned int)m_GLImages.size() - 1, true, width, height, row_pitch, data);//OpenGL images/textures require a separate write. + return WriteImage2D((uint)m_GLImages.size() - 1, true, width, height, row_pitch, data);//OpenGL images/textures require a separate write. else return true; } @@ -430,7 +430,7 @@ bool OpenCLWrapper::AddAndWriteImage(const string& name, cl_mem_flags flags, con /// The row pitch (usually zero) /// The image data /// True if success, else false. -bool OpenCLWrapper::WriteImage2D(unsigned int index, bool shared, ::size_t width, ::size_t height, ::size_t row_pitch, void* data) +bool OpenCLWrapper::WriteImage2D(uint index, bool shared, ::size_t width, ::size_t height, ::size_t row_pitch, void* data) { if (m_Init) { @@ -505,7 +505,7 @@ bool OpenCLWrapper::ReadImage(const string& name, ::size_t width, ::size_t heigh /// True if shared with an OpenGL texture, else false. /// A pointer to a buffer to copy the data to /// True if success, else false. -bool OpenCLWrapper::ReadImage(unsigned int imageIndex, ::size_t width, ::size_t height, ::size_t row_pitch, bool shared, void* data) +bool OpenCLWrapper::ReadImage(uint imageIndex, ::size_t width, ::size_t height, ::size_t row_pitch, bool shared, void* data) { if (m_Init) { @@ -552,13 +552,13 @@ int OpenCLWrapper::FindImageIndex(const string& name, bool shared) { if (shared) { - for (unsigned int i = 0; i < m_GLImages.size(); i++) + for (uint i = 0; i < m_GLImages.size(); i++) if (m_GLImages[i].m_Name == name) return i; } else { - for (unsigned int i = 0; i < m_Images.size(); i++) + for (uint i = 0; i < m_Images.size(); i++) if (m_Images[i].m_Name == name) return i; } @@ -572,7 +572,7 @@ int OpenCLWrapper::FindImageIndex(const string& name, bool shared) /// The name of the image to search for /// True if shared with an OpenGL texture, else false. /// The size of the 2D image if found, else 0. -unsigned int OpenCLWrapper::GetImageSize(const string& name, bool shared) +uint OpenCLWrapper::GetImageSize(const string& name, bool shared) { int imageIndex = FindImageIndex(name, shared); return GetImageSize(imageIndex, shared); @@ -584,7 +584,7 @@ unsigned int OpenCLWrapper::GetImageSize(const string& name, bool shared) /// Index of the image to search for /// True if shared with an OpenGL texture, else false. /// The size of the 2D image if found, else 0. -unsigned int OpenCLWrapper::GetImageSize(unsigned int imageIndex, bool shared) +uint OpenCLWrapper::GetImageSize(uint imageIndex, bool shared) { size_t size = 0; @@ -608,7 +608,7 @@ unsigned int OpenCLWrapper::GetImageSize(unsigned int imageIndex, bool shared) } } - return (unsigned int)size; + return (uint)size; } /// @@ -840,7 +840,7 @@ bool OpenCLWrapper::CreateSampler(cl::Sampler& sampler, cl_bool normalizedCoords /// Index of the argument /// The name of the buffer /// True if success, else false. -bool OpenCLWrapper::SetBufferArg(unsigned int kernelIndex, unsigned int argIndex, const string& name) +bool OpenCLWrapper::SetBufferArg(uint kernelIndex, uint argIndex, const string& name) { int bufferIndex = OpenCLWrapper::FindBufferIndex(name); @@ -855,7 +855,7 @@ bool OpenCLWrapper::SetBufferArg(unsigned int kernelIndex, unsigned int argIndex /// Index of the argument /// Index of the buffer /// True if success, else false. -bool OpenCLWrapper::SetBufferArg(unsigned int kernelIndex, unsigned int argIndex, unsigned int bufferIndex) +bool OpenCLWrapper::SetBufferArg(uint kernelIndex, uint argIndex, uint bufferIndex) { if (m_Init && bufferIndex < m_Buffers.size()) return SetArg(kernelIndex, argIndex, m_Buffers[bufferIndex].m_Buffer); @@ -872,7 +872,7 @@ bool OpenCLWrapper::SetBufferArg(unsigned int kernelIndex, unsigned int argIndex /// True if shared with an OpenGL texture, else false /// The name of the 2D image /// True if success, else false. -bool OpenCLWrapper::SetImageArg(unsigned int kernelIndex, unsigned int argIndex, bool shared, const string& name) +bool OpenCLWrapper::SetImageArg(uint kernelIndex, uint argIndex, bool shared, const string& name) { if (m_Init) { @@ -892,7 +892,7 @@ bool OpenCLWrapper::SetImageArg(unsigned int kernelIndex, unsigned int argIndex, /// True if shared with an OpenGL texture, else false /// Index of the 2D image /// True if success, else false. -bool OpenCLWrapper::SetImageArg(unsigned int kernelIndex, unsigned int argIndex, bool shared, unsigned int imageIndex) +bool OpenCLWrapper::SetImageArg(uint kernelIndex, uint argIndex, bool shared, uint imageIndex) { cl_int err; @@ -920,7 +920,7 @@ bool OpenCLWrapper::SetImageArg(unsigned int kernelIndex, unsigned int argIndex, /// The index if found, else -1. int OpenCLWrapper::FindKernelIndex(const string& name) { - for (unsigned int i = 0; i < m_Programs.size(); i++) + for (uint i = 0; i < m_Programs.size(); i++) if (m_Programs[i].m_Name == name) return (int)i; @@ -938,8 +938,8 @@ int OpenCLWrapper::FindKernelIndex(const string& name) /// Height of each block /// Depth of each block /// True if success, else false. -bool OpenCLWrapper::RunKernel(unsigned int kernelIndex, unsigned int totalGridWidth, unsigned int totalGridHeight, unsigned int totalGridDepth, - unsigned int blockWidth, unsigned int blockHeight, unsigned int blockDepth) +bool OpenCLWrapper::RunKernel(uint kernelIndex, uint totalGridWidth, uint totalGridHeight, uint totalGridDepth, + uint blockWidth, uint blockHeight, uint blockDepth) { if (m_Init && kernelIndex < m_Programs.size()) { @@ -999,7 +999,7 @@ vector OpenCLWrapper::PlatformNames() platforms.reserve(m_Platforms.size()); - for (unsigned int i = 0; i < m_Platforms.size(); i++) + for (uint i = 0; i < m_Platforms.size(); i++) platforms.push_back(PlatformName(i)); return platforms; @@ -1030,7 +1030,7 @@ string OpenCLWrapper::DeviceName(size_t platform, size_t device) /// All available device names on the platform at the specified index as a vector of strings vector OpenCLWrapper::DeviceNames(size_t platform) { - unsigned int i = 0; + uint i = 0; string s; vector devices; @@ -1124,9 +1124,9 @@ string OpenCLWrapper::DumpInfo() bool OpenCLWrapper::Ok() const { return m_Init; } bool OpenCLWrapper::Shared() const { return m_Shared; } cl::Context OpenCLWrapper::Context() const { return m_Context; } -unsigned int OpenCLWrapper::PlatformIndex() const { return m_PlatformIndex; } -unsigned int OpenCLWrapper::DeviceIndex() const { return m_DeviceIndex; } -unsigned int OpenCLWrapper::LocalMemSize() const { return m_LocalMemSize; } +uint OpenCLWrapper::PlatformIndex() const { return m_PlatformIndex; } +uint OpenCLWrapper::DeviceIndex() const { return m_DeviceIndex; } +uint OpenCLWrapper::LocalMemSize() const { return m_LocalMemSize; } /// /// Makes the even grid dims. @@ -1135,7 +1135,7 @@ unsigned int OpenCLWrapper::LocalMemSize() const { return m_LocalMemSize; } /// The block h. /// The grid w. /// The grid h. -void OpenCLWrapper::MakeEvenGridDims(unsigned int blockW, unsigned int blockH, unsigned int& gridW, unsigned int& gridH) +void OpenCLWrapper::MakeEvenGridDims(uint blockW, uint blockH, uint& gridW, uint& gridH) { if (gridW % blockW != 0) gridW += (blockW - (gridW % blockW)); diff --git a/Source/EmberCL/OpenCLWrapper.h b/Source/EmberCL/OpenCLWrapper.h index dfc4616..a58eb12 100644 --- a/Source/EmberCL/OpenCLWrapper.h +++ b/Source/EmberCL/OpenCLWrapper.h @@ -104,7 +104,7 @@ class EMBERCL_API OpenCLWrapper : public EmberReport public: OpenCLWrapper(); bool CheckOpenCL(); - bool Init(unsigned int platform, unsigned int device, bool shared = false); + bool Init(uint platform, uint device, bool shared = false); //Programs. bool AddProgram(const string& name, const string& program, const string& entryPoint, bool doublePrecision); @@ -114,22 +114,22 @@ public: bool AddBuffer(const string& name, size_t size, cl_mem_flags flags = CL_MEM_READ_WRITE); bool AddAndWriteBuffer(const string& name, void* data, size_t size, cl_mem_flags flags = CL_MEM_READ_WRITE); bool WriteBuffer(const string& name, void* data, size_t size); - bool WriteBuffer(unsigned int bufferIndex, void* data, size_t size); + bool WriteBuffer(uint bufferIndex, void* data, size_t size); bool ReadBuffer(const string& name, void* data, size_t size); - bool ReadBuffer(unsigned int bufferIndex, void* data, size_t size); + bool ReadBuffer(uint bufferIndex, void* data, size_t size); int FindBufferIndex(const string& name); - unsigned int GetBufferSize(const string& name); - unsigned int GetBufferSize(unsigned int bufferIndex); + uint GetBufferSize(const string& name); + uint GetBufferSize(uint bufferIndex); void ClearBuffers(); //Images. bool AddAndWriteImage(const string& name, cl_mem_flags flags, const cl::ImageFormat& format, ::size_t width, ::size_t height, ::size_t row_pitch, void* data = NULL, bool shared = false, GLuint texName = 0); - bool WriteImage2D(unsigned int index, bool shared, ::size_t width, ::size_t height, ::size_t row_pitch, void* data); + bool WriteImage2D(uint index, bool shared, ::size_t width, ::size_t height, ::size_t row_pitch, void* data); bool ReadImage(const string& name, ::size_t width, ::size_t height, ::size_t row_pitch, bool shared, void* data); - bool ReadImage(unsigned int imageIndex, ::size_t width, ::size_t height, ::size_t row_pitch, bool shared, void* data); + bool ReadImage(uint imageIndex, ::size_t width, ::size_t height, ::size_t row_pitch, bool shared, void* data); int FindImageIndex(const string& name, bool shared); - unsigned int GetImageSize(const string& name, bool shared); - unsigned int GetImageSize(unsigned int imageIndex, bool shared); + uint GetImageSize(const string& name, bool shared); + uint GetImageSize(uint imageIndex, bool shared); bool CompareImageParams(cl::Image& image, cl_mem_flags flags, const cl::ImageFormat& format, ::size_t width, ::size_t height, ::size_t row_pitch); void ClearImages(bool shared); bool CreateImage2D(cl::Image2D& image2D, cl_mem_flags flags, cl::ImageFormat format, ::size_t width, ::size_t height, ::size_t row_pitch = 0, void* data = NULL); @@ -143,10 +143,10 @@ public: bool CreateSampler(cl::Sampler& sampler, cl_bool normalizedCoords, cl_addressing_mode addressingMode, cl_filter_mode filterMode); //Arguments. - bool SetBufferArg(unsigned int kernelIndex, unsigned int argIndex, const string& name); - bool SetBufferArg(unsigned int kernelIndex, unsigned int argIndex, unsigned int bufferIndex); - bool SetImageArg(unsigned int kernelIndex, unsigned int argIndex, bool shared, const string& name); - bool SetImageArg(unsigned int kernelIndex, unsigned int argIndex, bool shared, unsigned int imageIndex); + bool SetBufferArg(uint kernelIndex, uint argIndex, const string& name); + bool SetBufferArg(uint kernelIndex, uint argIndex, uint bufferIndex); + bool SetImageArg(uint kernelIndex, uint argIndex, bool shared, const string& name); + bool SetImageArg(uint kernelIndex, uint argIndex, bool shared, uint imageIndex); /// /// Set an argument in the specified kernel, at the specified argument index. @@ -157,7 +157,7 @@ public: /// The argument value to set /// True if success, else false template - bool SetArg(unsigned int kernelIndex, unsigned int argIndex, T arg) + bool SetArg(uint kernelIndex, uint argIndex, T arg) { if (m_Init && kernelIndex < m_Programs.size()) { @@ -171,7 +171,7 @@ public: //Kernels. int FindKernelIndex(const string& name); - bool RunKernel(unsigned int kernelIndex, unsigned int totalGridWidth, unsigned int totalGridHeight, unsigned int totalGridDepth, unsigned int blockWidth, unsigned int blockHeight, unsigned int blockDepth); + bool RunKernel(uint kernelIndex, uint totalGridWidth, uint totalGridHeight, uint totalGridDepth, uint blockWidth, uint blockHeight, uint blockDepth); //Info. template @@ -187,11 +187,11 @@ public: bool Ok() const; bool Shared() const; cl::Context Context() const; - unsigned int PlatformIndex() const; - unsigned int DeviceIndex() const; - unsigned int LocalMemSize() const; + uint PlatformIndex() const; + uint DeviceIndex() const; + uint LocalMemSize() const; - static void MakeEvenGridDims(unsigned int blockW, unsigned int blockH, unsigned int& gridW, unsigned int& gridH); + static void MakeEvenGridDims(uint blockW, uint blockH, uint& gridW, uint& gridH); private: bool CreateContext(bool shared); @@ -201,9 +201,9 @@ private: bool m_Init; bool m_Shared; - unsigned int m_PlatformIndex; - unsigned int m_DeviceIndex; - unsigned int m_LocalMemSize; + uint m_PlatformIndex; + uint m_DeviceIndex; + uint m_LocalMemSize; cl::Platform m_Platform; cl::Context m_Context; cl::Device m_Device; diff --git a/Source/EmberCL/RendererCL.cpp b/Source/EmberCL/RendererCL.cpp index 2a20383..291764d 100644 --- a/Source/EmberCL/RendererCL.cpp +++ b/Source/EmberCL/RendererCL.cpp @@ -1,1479 +1,1479 @@ -#include "EmberCLPch.h" -#include "RendererCL.h" - -namespace EmberCLns -{ -/// -/// Constructor that inintializes various buffer names, block dimensions, image formats -/// and finally initializes OpenCL using the passed in parameters. -/// -/// The index platform of the platform to use. Default: 0. -/// The index device of the device to use. Default: 0. -/// True if shared with OpenGL, else false. Default: false. -/// The texture ID of the shared OpenGL texture if shared. Default: 0. -template -RendererCL::RendererCL(unsigned int platform, unsigned int device, bool shared, GLuint outputTexID) -{ - m_Init = false; - m_NVidia = false; - m_DoublePrecision = typeid(T) == typeid(double); - m_NumChannels = 4; - m_Calls = 0; - - //Buffer names. - m_EmberBufferName = "Ember"; - m_XformsBufferName = "Xforms"; - m_ParVarsBufferName = "ParVars"; - m_SeedsBufferName = "Seeds"; - m_DistBufferName = "Dist"; - m_CarToRasBufferName = "CarToRas"; - m_DEFilterParamsBufferName = "DEFilterParams"; - m_SpatialFilterParamsBufferName = "SpatialFilterParams"; - m_DECoefsBufferName = "DECoefs"; - m_DEWidthsBufferName = "DEWidths"; - m_DECoefIndicesBufferName = "DECoefIndices"; - m_SpatialFilterCoefsBufferName = "SpatialFilterCoefs"; - m_HistBufferName = "Hist"; - m_AccumBufferName = "Accum"; - m_FinalImageName = "Final"; - m_PointsBufferName = "Points"; - - //It's critical that these numbers never change. They are - //based on the cuburn model of each kernel launch containing - //256 threads. 32 wide by 8 high. Everything done in the OpenCL - //iteraion kernel depends on these dimensions. - m_IterCountPerKernel = 256; - m_IterBlockWidth = 32; - m_IterBlockHeight = 8; - m_IterBlocksWide = 64; - m_IterBlocksHigh = 2; - - m_PaletteFormat.image_channel_order = CL_RGBA; - m_PaletteFormat.image_channel_data_type = CL_FLOAT; - m_FinalFormat.image_channel_order = CL_RGBA; - m_FinalFormat.image_channel_data_type = CL_UNORM_INT8;//Change if this ever supports 2BPC outputs for PNG. - - FillSeeds(); - Init(platform, device, shared, outputTexID);//Init OpenCL upon construction and create programs that will not change. -} - -/// -/// Virtual destructor. -/// -template -RendererCL::~RendererCL() -{ -} - -/// -/// Non-virtual member functions for OpenCL specific tasks. -/// - -/// -/// Initialize OpenCL. -/// In addition to initializing, this function will create the zeroization program, -/// as well as the basic log scale filtering programs. This is done to ensure basic -/// compilation works. Further compilation will be done later for iteration, density filtering, -/// and final accumulation. -/// -/// The index platform of the platform to use -/// The index device of the device to use -/// True if shared with OpenGL, else false. -/// The texture ID of the shared OpenGL texture if shared -/// True if success, else false. -template -bool RendererCL::Init(unsigned int platform, unsigned int device, bool shared, GLuint outputTexID) -{ - //Timing t; - bool b = true; - m_OutputTexID = outputTexID; - const char* loc = __FUNCTION__; - - if (!m_Wrapper.Ok() || PlatformIndex() != platform || DeviceIndex() != device) - { - m_Init = false; - b = m_Wrapper.Init(platform, device, shared); - } - - if (b && m_Wrapper.Ok() && !m_Init) - { - m_NVidia = ToLower(m_Wrapper.DeviceAndPlatformNames()).find_first_of("nvidia") != string::npos && m_Wrapper.LocalMemSize() > (32 * 1024); - m_WarpSize = m_NVidia ? 32 : 64; - m_IterOpenCLKernelCreator = IterOpenCLKernelCreator(m_NVidia); - m_DEOpenCLKernelCreator = DEOpenCLKernelCreator(m_NVidia); - - string zeroizeProgram = m_IterOpenCLKernelCreator.ZeroizeKernel(); - string logAssignProgram = m_DEOpenCLKernelCreator.LogScaleAssignDEKernel();//Build a couple of simple programs to ensure OpenCL is working right. - - if (b && !(b = m_Wrapper.AddProgram(m_IterOpenCLKernelCreator.ZeroizeEntryPoint(), zeroizeProgram, m_IterOpenCLKernelCreator.ZeroizeEntryPoint(), m_DoublePrecision))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddProgram(m_DEOpenCLKernelCreator.LogScaleAssignDEEntryPoint(), logAssignProgram, m_DEOpenCLKernelCreator.LogScaleAssignDEEntryPoint(), m_DoublePrecision))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddAndWriteImage("Palette", CL_MEM_READ_ONLY, m_PaletteFormat, 256, 1, 0, NULL))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SeedsBufferName, (void*)m_Seeds.data(), SizeOf(m_Seeds)))) { m_ErrorReport.push_back(loc); } - - //This is the maximum box dimension for density filtering which consists of (blockSize * blockSize) + (2 * filterWidth). - //These blocks must be square, and ideally, 32x32. - //Sadly, at the moment, Fermi runs out of resources at that block size because the DE filter function is so complex. - //The next best block size seems to be 24x24. - //AMD is further limited because of less local memory so these have to be 16 on AMD. - m_MaxDEBlockSizeW = m_NVidia ? 32 : 16;//These *must* both be divisible by 16 or else pixels will go missing. - m_MaxDEBlockSizeH = m_NVidia ? 32 : 16; - m_Init = true; - //t.Toc(loc); - } - - return b; -} - -/// -/// Set the shared output texture where final accumulation will be written to. -/// -/// The texture ID of the shared OpenGL texture if shared -/// True if success, else false. -template -bool RendererCL::SetOutputTexture(GLuint outputTexID) -{ - bool success = true; - const char* loc = __FUNCTION__; - - if (!m_Wrapper.Ok()) - return false; - - m_OutputTexID = outputTexID; - EnterResize(); - - if (!m_Wrapper.AddAndWriteImage(m_FinalImageName, CL_MEM_WRITE_ONLY, m_FinalFormat, FinalRasW(), FinalRasH(), 0, NULL, m_Wrapper.Shared(), m_OutputTexID)) - { - m_ErrorReport.push_back(loc); - success = false; - } - - LeaveResize(); - return success; -} - -/// -/// OpenCL property accessors, getters only. -/// - -//Iters per kernel/block/grid. -template unsigned int RendererCL::IterCountPerKernel() const { return m_IterCountPerKernel; } -template unsigned int RendererCL::IterCountPerBlock() const { return IterCountPerKernel() * IterBlockKernelCount(); } -template unsigned int RendererCL::IterCountPerGrid() const { return IterCountPerKernel() * IterGridKernelCount(); } - -//Kernels per block. -template unsigned int RendererCL::IterBlockKernelWidth() const { return m_IterBlockWidth; } -template unsigned int RendererCL::IterBlockKernelHeight() const { return m_IterBlockHeight; } -template unsigned int RendererCL::IterBlockKernelCount() const { return IterBlockKernelWidth() * IterBlockKernelHeight(); } - -//Kernels per grid. -template unsigned int RendererCL::IterGridKernelWidth() const { return IterGridBlockWidth() * IterBlockKernelWidth(); } -template unsigned int RendererCL::IterGridKernelHeight() const { return IterGridBlockHeight() * IterBlockKernelHeight(); } -template unsigned int RendererCL::IterGridKernelCount() const { return IterGridKernelWidth() * IterGridKernelHeight(); } - -//Blocks per grid. -template unsigned int RendererCL::IterGridBlockWidth() const { return m_IterBlocksWide; } -template unsigned int RendererCL::IterGridBlockHeight() const { return m_IterBlocksHigh; } -template unsigned int RendererCL::IterGridBlockCount() const { return IterGridBlockWidth() * IterGridBlockHeight(); } - -template unsigned int RendererCL::PlatformIndex() { return m_Wrapper.PlatformIndex(); } -template unsigned int RendererCL::DeviceIndex() { return m_Wrapper.DeviceIndex(); } - -/// -/// Read the histogram into the host side CPU buffer. -/// Used for debugging. -/// -/// True if success, else false. -template -bool RendererCL::ReadHist() -{ - if (Renderer::Alloc())//Allocate the memory to read into. - return m_Wrapper.ReadBuffer(m_HistBufferName, (void*)HistBuckets(), SuperSize() * sizeof(v4T)); - - return false; -} - -/// -/// Read the density filtering buffer into the host side CPU buffer. -/// Used for debugging. -/// -/// True if success, else false. -template -bool RendererCL::ReadAccum() -{ - if (Renderer::Alloc())//Allocate the memory to read into. - return m_Wrapper.ReadBuffer(m_AccumBufferName, (void*)AccumulatorBuckets(), SuperSize() * sizeof(v4T)); - - return false; -} - -/// -/// Read the temporary points buffer into a host side CPU buffer. -/// Used for debugging. -/// -/// The host side buffer to read into -/// True if success, else false. -template -bool RendererCL::ReadPoints(vector>& vec) -{ - vec.resize(IterGridKernelCount());//Allocate the memory to read into. - - if (vec.size() >= IterGridKernelCount()) - return m_Wrapper.ReadBuffer(m_PointsBufferName, (void*)vec.data(), IterGridKernelCount() * sizeof(PointCL)); - - return false; -} - -/// -/// Clear the histogram buffer with all zeroes. -/// -/// True if success, else false. -template -bool RendererCL::ClearHist() -{ - return ClearBuffer(m_HistBufferName, (unsigned int)SuperRasW(), (unsigned int)SuperRasH(), sizeof(v4T)); -} - -/// -/// Clear the desnity filtering buffer with all zeroes. -/// -/// True if success, else false. -template -bool RendererCL::ClearAccum() -{ - return ClearBuffer(m_AccumBufferName, (unsigned int)SuperRasW(), (unsigned int)SuperRasH(), sizeof(v4T)); -} - -/// -/// Write values from a host side CPU buffer into the temporary points buffer. -/// Used for debugging. -/// -/// The host side buffer whose values to write -/// True if success, else false. -template -bool RendererCL::WritePoints(vector>& vec) -{ - return m_Wrapper.WriteBuffer(m_PointsBufferName, (void*)vec.data(), vec.size() * sizeof(vec[0])); -} - -#ifdef TEST_CL -template -bool RendererCL::WriteRandomPoints() -{ - size_t size = IterGridKernelCount(); - vector> vec(size); - - for (int i = 0; i < size; i++) - { - vec[i].m_X = m_Rand[0].Frand11(); - vec[i].m_Y = m_Rand[0].Frand11(); - vec[i].m_Z = 0; - vec[i].m_ColorX = m_Rand[0].Frand01(); - vec[i].m_LastXfUsed = 0; - } - - return WritePoints(vec); -} -#endif - -/// -/// Get the kernel string for the last built iter program. -/// -/// The string representation of the kernel for the last built iter program. -template -string RendererCL::IterKernel() { return m_IterKernel; } - -/// -/// Virtual functions overridden from RendererCLBase. -/// - -/// -/// Read the final image buffer buffer into the host side CPU buffer. -/// This must be called before saving the final output image to file. -/// -/// The host side buffer to read into -/// True if success, else false. -template -bool RendererCL::ReadFinal(unsigned char* pixels) -{ - if (pixels) - return m_Wrapper.ReadImage(m_FinalImageName, FinalRasW(), FinalRasH(), 0, m_Wrapper.Shared(), pixels); - - return false; -} - -/// -/// Clear the final image output buffer with all zeroes by copying a host side buffer. -/// Slow, but never used because the final output image is always completely overwritten. -/// -/// True if success, else false. -template -bool RendererCL::ClearFinal() -{ - vector v; - unsigned int index = m_Wrapper.FindImageIndex(m_FinalImageName, m_Wrapper.Shared()); - - if (this->PrepFinalAccumVector(v)) - { - bool b = m_Wrapper.WriteImage2D(index, m_Wrapper.Shared(), FinalRasW(), FinalRasH(), 0, v.data()); - - if (!b) - m_ErrorReport.push_back(__FUNCTION__); - - return b; - } - else - return false; -} - -/// -/// Public virtual functions overridden from Renderer or RendererBase. -/// - -/// -/// The amount of video RAM available on the GPU to render with. -/// -/// An unsigned 64-bit integer specifying how much video memory is available -template -size_t RendererCL::MemoryAvailable() -{ - return Ok() ? m_Wrapper.GetInfo(PlatformIndex(), DeviceIndex(), CL_DEVICE_GLOBAL_MEM_SIZE) : 0ULL; -} - -/// -/// Return whether OpenCL has been properly initialized. -/// -/// True if OpenCL has been properly initialized, else false. -template -bool RendererCL::Ok() const -{ - return m_Init; -} - -/// -/// Override to force num channels to be 4 because RGBA is always used for OpenCL -/// since the output is actually an image rather than just a buffer. -/// -/// The number of channels, ignored. -template -void RendererCL::NumChannels(size_t numChannels) -{ - m_NumChannels = 4; -} - -/// -/// Dump the error report for this class as well as the OpenCLWrapper member. -/// -template -void RendererCL::DumpErrorReport() -{ - EmberReport::DumpErrorReport(); - m_Wrapper.DumpErrorReport(); -} - -/// -/// Clear the error report for this class as well as the OpenCLWrapper member. -/// -template -void RendererCL::ClearErrorReport() -{ - EmberReport::ClearErrorReport(); - m_Wrapper.ClearErrorReport(); -} - -/// -/// The sub batch size for OpenCL will always be how many -/// iterations are ran per kernel call. The caller can't -/// change this. -/// -/// The number of iterations ran in a single kernel call -template -size_t RendererCL::SubBatchSize() const -{ - return IterCountPerGrid(); -} - -/// -/// The thread count for OpenCL is always considered to be 1, however -/// the kernel internally runs many threads. -/// -/// 1 -template -size_t RendererCL::ThreadCount() const -{ - return 1; -} - -/// -/// Create the density filter in the base class and copy the filter values -/// to the corresponding OpenCL buffers. -/// -/// True if a new filter instance was created, else false. -/// True if success, else false. -template -bool RendererCL::CreateDEFilter(bool& newAlloc) -{ - bool b = true; - - if (Renderer::CreateDEFilter(newAlloc)) - { - //Copy coefs and widths here. Convert and copy the other filter params right before calling the filtering kernel. - if (newAlloc) - { - const char* loc = __FUNCTION__; - DensityFilter* filter = dynamic_cast*>(GetDensityFilter()); - - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DECoefsBufferName, (void*)filter->Coefs(), filter->CoefsSizeBytes()))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DEWidthsBufferName, (void*)filter->Widths(), filter->WidthsSizeBytes()))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DECoefIndicesBufferName, (void*)filter->CoefIndices(), filter->CoefsIndicesSizeBytes()))) { m_ErrorReport.push_back(loc); } - } - } - else - b = false; - - return b; -} - -/// -/// Create the spatial filter in the base class and copy the filter values -/// to the corresponding OpenCL buffers. -/// -/// True if a new filter instance was created, else false. -/// True if success, else false. -template -bool RendererCL::CreateSpatialFilter(bool& newAlloc) -{ - bool b = true; - - if (Renderer::CreateSpatialFilter(newAlloc)) - { - if (newAlloc) - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SpatialFilterCoefsBufferName, (void*)GetSpatialFilter()->Filter(), GetSpatialFilter()->BufferSizeBytes()))) { m_ErrorReport.push_back(__FUNCTION__); } - - } - else - b = false; - - return b; -} - -/// -/// Get the renderer type enum. -/// -/// OPENCL_RENDERER -template -eRendererType RendererCL::RendererType() const -{ - return OPENCL_RENDERER; -} - -/// -/// Concatenate and return the error report for this class and the -/// OpenCLWrapper member as a single string. -/// -/// The concatenated error report string -template -string RendererCL::ErrorReportString() -{ - return EmberReport::ErrorReportString() + m_Wrapper.ErrorReportString(); -} - -/// -/// Concatenate and return the error report for this class and the -/// OpenCLWrapper member as a vector of strings. -/// -/// The concatenated error report vector of strings -template -vector RendererCL::ErrorReport() -{ - vector ours = EmberReport::ErrorReport(); - vector wrappers = m_Wrapper.ErrorReport(); - - ours.insert(ours.end(), wrappers.begin(), wrappers.end()); - return ours; -} - -/// -/// Set the vector of random contexts. -/// Call the base, and reset the seeds vector. -/// -/// The vector of random contexts to assign -/// True if the size of the vector matched the number of threads used for rendering and writing seeds to OpenCL succeeded, else false. -template -bool RendererCL::RandVec(vector>& randVec) -{ - bool b = Renderer::RandVec(randVec); - const char* loc = __FUNCTION__; - - if (m_Wrapper.Ok()) - { - FillSeeds(); - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SeedsBufferName, (void*)m_Seeds.data(), SizeOf(m_Seeds)))) { m_ErrorReport.push_back(loc); } - } - - return b; -} - -/// -/// Protected virtual functions overridden from Renderer. -/// - -/// -/// Make the final palette used for iteration. -/// This override differs from the base in that it does not use -/// bucketT as the output palette type. This is because OpenCL -/// only supports floats for texture images. -/// -/// The color scalar to multiply the ember's palette by -template -void RendererCL::MakeDmap(T colorScalar) -{ - //m_Ember.m_Palette.MakeDmap(m_DmapCL, colorScalar); - m_Ember.m_Palette.MakeDmap(m_DmapCL, colorScalar); -} - - -/// -/// Allocate all buffers required for running as well as the final -/// 2D image. -/// -/// True if success, else false. -template -bool RendererCL::Alloc() -{ - if (!m_Wrapper.Ok()) - return false; - - EnterResize(); - m_XformsCL.resize(m_Ember.TotalXformCount()); - - bool b = true; - size_t histLength = SuperSize() * sizeof(v4T); - size_t accumLength = SuperSize() * sizeof(v4T); - const char* loc = __FUNCTION__; - - if (b && !(b = m_Wrapper.AddBuffer(m_EmberBufferName, sizeof(m_EmberCL)))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddBuffer(m_XformsBufferName, SizeOf(m_XformsCL)))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddBuffer(m_ParVarsBufferName, 128 * sizeof(T)))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddBuffer(m_DistBufferName, CHOOSE_XFORM_GRAIN))) { m_ErrorReport.push_back(loc); }//Will be resized for xaos. - if (b && !(b = m_Wrapper.AddBuffer(m_CarToRasBufferName, sizeof(m_CarToRasCL)))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddBuffer(m_DEFilterParamsBufferName, sizeof(m_DensityFilterCL)))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddBuffer(m_SpatialFilterParamsBufferName, sizeof(m_SpatialFilterCL)))) { m_ErrorReport.push_back(loc); } - - if (b && !(b = m_Wrapper.AddBuffer(m_HistBufferName, histLength))) { m_ErrorReport.push_back(loc); }//Histogram. Will memset to zero later. - if (b && !(b = m_Wrapper.AddBuffer(m_AccumBufferName, accumLength))) { m_ErrorReport.push_back(loc); }//Accum buffer. - if (b && !(b = m_Wrapper.AddBuffer(m_PointsBufferName, IterGridKernelCount() * sizeof(PointCL)))) { m_ErrorReport.push_back(loc); }//Points between iter calls. - +#include "EmberCLPch.h" +#include "RendererCL.h" + +namespace EmberCLns +{ +/// +/// Constructor that inintializes various buffer names, block dimensions, image formats +/// and finally initializes OpenCL using the passed in parameters. +/// +/// The index platform of the platform to use. Default: 0. +/// The index device of the device to use. Default: 0. +/// True if shared with OpenGL, else false. Default: false. +/// The texture ID of the shared OpenGL texture if shared. Default: 0. +template +RendererCL::RendererCL(uint platform, uint device, bool shared, GLuint outputTexID) +{ + m_Init = false; + m_NVidia = false; + m_DoublePrecision = typeid(T) == typeid(double); + m_NumChannels = 4; + m_Calls = 0; + + //Buffer names. + m_EmberBufferName = "Ember"; + m_XformsBufferName = "Xforms"; + m_ParVarsBufferName = "ParVars"; + m_SeedsBufferName = "Seeds"; + m_DistBufferName = "Dist"; + m_CarToRasBufferName = "CarToRas"; + m_DEFilterParamsBufferName = "DEFilterParams"; + m_SpatialFilterParamsBufferName = "SpatialFilterParams"; + m_DECoefsBufferName = "DECoefs"; + m_DEWidthsBufferName = "DEWidths"; + m_DECoefIndicesBufferName = "DECoefIndices"; + m_SpatialFilterCoefsBufferName = "SpatialFilterCoefs"; + m_HistBufferName = "Hist"; + m_AccumBufferName = "Accum"; + m_FinalImageName = "Final"; + m_PointsBufferName = "Points"; + + //It's critical that these numbers never change. They are + //based on the cuburn model of each kernel launch containing + //256 threads. 32 wide by 8 high. Everything done in the OpenCL + //iteraion kernel depends on these dimensions. + m_IterCountPerKernel = 256; + m_IterBlockWidth = 32; + m_IterBlockHeight = 8; + m_IterBlocksWide = 64; + m_IterBlocksHigh = 2; + + m_PaletteFormat.image_channel_order = CL_RGBA; + m_PaletteFormat.image_channel_data_type = CL_FLOAT; + m_FinalFormat.image_channel_order = CL_RGBA; + m_FinalFormat.image_channel_data_type = CL_UNORM_INT8;//Change if this ever supports 2BPC outputs for PNG. + + FillSeeds(); + Init(platform, device, shared, outputTexID);//Init OpenCL upon construction and create programs that will not change. +} + +/// +/// Virtual destructor. +/// +template +RendererCL::~RendererCL() +{ +} + +/// +/// Non-virtual member functions for OpenCL specific tasks. +/// + +/// +/// Initialize OpenCL. +/// In addition to initializing, this function will create the zeroization program, +/// as well as the basic log scale filtering programs. This is done to ensure basic +/// compilation works. Further compilation will be done later for iteration, density filtering, +/// and final accumulation. +/// +/// The index platform of the platform to use +/// The index device of the device to use +/// True if shared with OpenGL, else false. +/// The texture ID of the shared OpenGL texture if shared +/// True if success, else false. +template +bool RendererCL::Init(uint platform, uint device, bool shared, GLuint outputTexID) +{ + //Timing t; + bool b = true; + m_OutputTexID = outputTexID; + const char* loc = __FUNCTION__; + + if (!m_Wrapper.Ok() || PlatformIndex() != platform || DeviceIndex() != device) + { + m_Init = false; + b = m_Wrapper.Init(platform, device, shared); + } + + if (b && m_Wrapper.Ok() && !m_Init) + { + m_NVidia = ToLower(m_Wrapper.DeviceAndPlatformNames()).find_first_of("nvidia") != string::npos && m_Wrapper.LocalMemSize() > (32 * 1024); + m_WarpSize = m_NVidia ? 32 : 64; + m_IterOpenCLKernelCreator = IterOpenCLKernelCreator(m_NVidia); + m_DEOpenCLKernelCreator = DEOpenCLKernelCreator(m_NVidia); + + string zeroizeProgram = m_IterOpenCLKernelCreator.ZeroizeKernel(); + string logAssignProgram = m_DEOpenCLKernelCreator.LogScaleAssignDEKernel();//Build a couple of simple programs to ensure OpenCL is working right. + + if (b && !(b = m_Wrapper.AddProgram(m_IterOpenCLKernelCreator.ZeroizeEntryPoint(), zeroizeProgram, m_IterOpenCLKernelCreator.ZeroizeEntryPoint(), m_DoublePrecision))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddProgram(m_DEOpenCLKernelCreator.LogScaleAssignDEEntryPoint(), logAssignProgram, m_DEOpenCLKernelCreator.LogScaleAssignDEEntryPoint(), m_DoublePrecision))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddAndWriteImage("Palette", CL_MEM_READ_ONLY, m_PaletteFormat, 256, 1, 0, NULL))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SeedsBufferName, (void*)m_Seeds.data(), SizeOf(m_Seeds)))) { m_ErrorReport.push_back(loc); } + + //This is the maximum box dimension for density filtering which consists of (blockSize * blockSize) + (2 * filterWidth). + //These blocks must be square, and ideally, 32x32. + //Sadly, at the moment, Fermi runs out of resources at that block size because the DE filter function is so complex. + //The next best block size seems to be 24x24. + //AMD is further limited because of less local memory so these have to be 16 on AMD. + m_MaxDEBlockSizeW = m_NVidia ? 32 : 16;//These *must* both be divisible by 16 or else pixels will go missing. + m_MaxDEBlockSizeH = m_NVidia ? 32 : 16; + m_Init = true; + //t.Toc(loc); + } + + return b; +} + +/// +/// Set the shared output texture where final accumulation will be written to. +/// +/// The texture ID of the shared OpenGL texture if shared +/// True if success, else false. +template +bool RendererCL::SetOutputTexture(GLuint outputTexID) +{ + bool success = true; + const char* loc = __FUNCTION__; + + if (!m_Wrapper.Ok()) + return false; + + m_OutputTexID = outputTexID; + EnterResize(); + + if (!m_Wrapper.AddAndWriteImage(m_FinalImageName, CL_MEM_WRITE_ONLY, m_FinalFormat, FinalRasW(), FinalRasH(), 0, NULL, m_Wrapper.Shared(), m_OutputTexID)) + { + m_ErrorReport.push_back(loc); + success = false; + } + LeaveResize(); - - if (b && !(b = SetOutputTexture(m_OutputTexID))) { m_ErrorReport.push_back(loc); } - - return b; -} - -/// -/// Clear OpenCL histogram and/or density filtering buffers to all zeroes. -/// -/// Clear histogram if true, else don't. -/// Clear density filtering buffer if true, else don't. -/// True if success, else false. -template -bool RendererCL::ResetBuckets(bool resetHist, bool resetAccum) -{ - bool b = true; - - if (resetHist) - b &= ClearHist(); - - if (resetAccum) - b &= ClearAccum(); - - return b; -} - -/// -/// Perform log scale density filtering. -/// -/// True if success and not aborted, else false. -template -eRenderStatus RendererCL::LogScaleDensityFilter() -{ - return RunLogScaleFilter(); -} - -/// -/// Run gaussian density estimation filtering. -/// -/// True if success and not aborted, else false. -template -eRenderStatus RendererCL::GaussianDensityFilter() -{ - //This commented section is for debugging density filtering by making it run on the CPU - //then copying the results back to the GPU. - //if (ReadHist()) - //{ - // unsigned int accumLength = SuperSize() * sizeof(glm::detail::tvec4); - // const char* loc = __FUNCTION__; - // - // Renderer::ResetBuckets(false, true); - // Renderer::GaussianDensityFilter(); - // - // if (!m_Wrapper.WriteBuffer(m_AccumBufferName, AccumulatorBuckets(), accumLength)) { m_ErrorReport.push_back(loc); return RENDER_ERROR; } - // return RENDER_OK; - //} - //else - // return RENDER_ERROR; - - //Timing t(4); - - eRenderStatus status = RunDensityFilter(); - //t.Toc(__FUNCTION__ " RunKernel()"); - - return status; -} - -/// -/// Run final accumulation. -/// If pixels is NULL, the output will remain in the OpenCL 2D image. -/// However, if pixels is not NULL, the output will be copied. This is -/// useful when rendering in OpenCL, but saving the output to a file. -/// -/// The pixels to copy the final image to if not NULL -/// Offset in the buffer to store the pixels to -/// True if success and not aborted, else false. -template -eRenderStatus RendererCL::AccumulatorToFinalImage(unsigned char* pixels, size_t finalOffset) -{ - eRenderStatus status = RunFinalAccum(); - - if (status == RENDER_OK && pixels != NULL && !m_Wrapper.Shared()) - { - pixels += finalOffset; - - if (!ReadFinal(pixels)) - status = RENDER_ERROR; - } - - return status; -} - -/// -/// Run the iteration algorithm for the specified number of iterations. -/// This is only called after all other setup has been done. -/// This will recompile the OpenCL program if this ember differs significantly -/// from the previous run. -/// Note that the bad value count is not recorded when running with OpenCL. If it's -/// needed, run on the CPU. -/// -/// The number of iterations to run -/// The temporal sample within the current pass this is running for -/// Rendering statistics -template -EmberStats RendererCL::Iterate(size_t iterCount, size_t temporalSample) -{ - bool b = true; - EmberStats stats;//Do not record bad vals with with GPU. If the user needs to investigate bad vals, use the CPU. - const char* loc = __FUNCTION__; - - IterOpenCLKernelCreator::ParVarIndexDefines(m_Ember, m_Params, true, false);//Always do this to get the values (but no string), regardless of whether a rebuild is necessary. - - //Don't know the size of the parametric varations parameters buffer until the ember is examined. - //So set it up right before the run. - if (!m_Params.second.empty()) - { - if (!m_Wrapper.AddAndWriteBuffer(m_ParVarsBufferName, m_Params.second.data(), m_Params.second.size() * sizeof(m_Params.second[0]))) - { - m_Abort = true; - m_ErrorReport.push_back(loc); - return stats; - } - } - - //Rebuilding is expensive, so only do it if it's required. - if (IterOpenCLKernelCreator::IsBuildRequired(m_Ember, m_LastBuiltEmber)) - b = BuildIterProgramForEmber(true); - - if (b) - { - m_IterTimer.Tic();//Tic() here to avoid including build time in iter time measurement. - - if (m_Stats.m_Iters == 0)//Only reset the call count on the beginning of a new render. Do not reset on KEEP_ITERATING. - m_Calls = 0; - - b = RunIter(iterCount, temporalSample, stats.m_Iters); - - if (!b || stats.m_Iters == 0)//If no iters were executed, something went catastrophically wrong. - m_Abort = true; - - stats.m_IterMs = m_IterTimer.Toc(); - } - else - { - m_Abort = true; - m_ErrorReport.push_back(loc); - } - - return stats; -} - -/// -/// Private functions for making and running OpenCL programs. -/// - -/// -/// Build the iteration program for the current ember. -/// -/// Whether to build in accumulation, only for debugging. Default: true. -/// True if success, else false. -template -bool RendererCL::BuildIterProgramForEmber(bool doAccum) -{ - //Timing t; - const char* loc = __FUNCTION__; - IterOpenCLKernelCreator::ParVarIndexDefines(m_Ember, m_Params, false, true);//Do with string and no vals. - m_IterKernel = m_IterOpenCLKernelCreator.CreateIterKernelString(m_Ember, m_Params.first, m_LockAccum, doAccum); - //cout << "Building: " << endl << iterProgram << endl; - - //A program build is roughly .66s which will detract from the user experience. - //Need to experiment with launching this in a thread/task and returning once it's done.//TODO - if (m_Wrapper.AddProgram(m_IterOpenCLKernelCreator.IterEntryPoint(), m_IterKernel, m_IterOpenCLKernelCreator.IterEntryPoint(), m_DoublePrecision)) - { - //t.Toc(__FUNCTION__ " program build"); - //cout << string(loc) << "():\nBuilding the following program succeeded: \n" << iterProgram << endl; - m_LastBuiltEmber = m_Ember; - } - else - { - m_ErrorReport.push_back(string(loc) + "():\nBuilding the following program failed: \n" + m_IterKernel + "\n"); - return false; - } - - return true; -} - -/// -/// Run the iteration kernel. -/// Fusing on the CPU is done once per sub batch, usually 10,000 iters, however -/// determining when to do it in OpenCL is much more difficult. -/// Currently it's done once every 4 kernel calls which seems to be a good balance -/// between quality of the final image and performance. -/// -/// The number of iterations to run -/// The temporal sample this is running for -/// The storage for the number of iterations ran -/// True if success, else false. -template -bool RendererCL::RunIter(size_t iterCount, size_t temporalSample, size_t& itersRan) -{ - Timing t;//, t2(4); - bool b = true; - unsigned int fuse, argIndex; - unsigned int iterCountPerKernel = IterCountPerKernel(); - unsigned int iterCountPerBlock = IterCountPerBlock(); - unsigned int supersize = (unsigned int)SuperSize(); - int kernelIndex = m_Wrapper.FindKernelIndex(m_IterOpenCLKernelCreator.IterEntryPoint()); - size_t fuseFreq = Renderer::SubBatchSize() / m_IterCountPerKernel;//Use the base sbs to determine when to fuse. - size_t itersRemaining, localIterCount = 0; - double percent, etaMs; - const char* loc = __FUNCTION__; - - itersRan = 0; -#ifdef TEST_CL - m_Abort = false; -#endif - - if (kernelIndex != -1) - { - ConvertEmber(m_Ember, m_EmberCL, m_XformsCL); - m_CarToRasCL = ConvertCarToRas(*CoordMap()); - - if (b && !(b = m_Wrapper.WriteBuffer (m_EmberBufferName, (void*)&m_EmberCL, sizeof(m_EmberCL)))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.WriteBuffer (m_XformsBufferName, (void*)m_XformsCL.data(), sizeof(m_XformsCL[0]) * m_XformsCL.size()))) { m_ErrorReport.push_back(loc); } - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DistBufferName, (void*)XformDistributions(), XformDistributionsSize()))) { m_ErrorReport.push_back(loc); }//Will be resized for xaos. - if (b && !(b = m_Wrapper.WriteBuffer (m_CarToRasBufferName, (void*)&m_CarToRasCL, sizeof(m_CarToRasCL)))) { m_ErrorReport.push_back(loc); } - - if (b && !(b = m_Wrapper.AddAndWriteImage("Palette", CL_MEM_READ_ONLY, m_PaletteFormat, m_DmapCL.m_Entries.size(), 1, 0, m_DmapCL.m_Entries.data()))) { m_ErrorReport.push_back(loc); } - - //If animating, treat each temporal sample as a newly started render for fusing purposes. - if (temporalSample > 0) - m_Calls = 0; - - while (b && itersRan < iterCount && !m_Abort) - { - argIndex = 0; -#ifdef TEST_CL - fuse = 0; -#else - //fuse = 100; - //fuse = ((m_Calls % fuseFreq) == 0 ? (EarlyClip() ? 100u : 15u) : 0u); - fuse = (unsigned int)((m_Calls % fuseFreq) == 0u ? FuseCount() : 0u); - //fuse = ((m_Calls % 4) == 0 ? 100u : 0u); -#endif - itersRemaining = iterCount - itersRan; - unsigned int gridW = (unsigned int)min(ceil((double)itersRemaining / (double)iterCountPerBlock), (double)IterGridBlockWidth()); - unsigned int gridH = (unsigned int)min(ceil((double)itersRemaining / ((double)gridW * iterCountPerBlock)), (double)IterGridBlockHeight()); - unsigned int iterCountThisLaunch = iterCountPerBlock * gridW * gridH; - - //Similar to what's done in the base class. - //The number of iters per thread must be adjusted if they've requested less iters than is normally ran in a block (256 * 256). - if (iterCountThisLaunch > iterCount) - { - iterCountPerKernel = (unsigned int)ceil((double)iterCount / (double)(gridW * gridH * IterBlockKernelCount())); - iterCountThisLaunch = iterCountPerKernel * (gridW * gridH * IterBlockKernelCount()); - } - - if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, iterCountPerKernel))) { m_ErrorReport.push_back(loc); }//Number of iters for each thread to run. - if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, fuse))) { m_ErrorReport.push_back(loc); }//Number of iters to fuse. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_SeedsBufferName))) { m_ErrorReport.push_back(loc); }//Seeds. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_EmberBufferName))) { m_ErrorReport.push_back(loc); }//Ember. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_XformsBufferName))) { m_ErrorReport.push_back(loc); }//Xforms. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_ParVarsBufferName))) { m_ErrorReport.push_back(loc); }//Parametric variation parameters. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_DistBufferName))) { m_ErrorReport.push_back(loc); }//Xform distributions. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_CarToRasBufferName))) { m_ErrorReport.push_back(loc); }//Coordinate converter. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_HistBufferName))) { m_ErrorReport.push_back(loc); }//Histogram. - if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, supersize))) { m_ErrorReport.push_back(loc); }//Histogram size. - if (b && !(b = m_Wrapper.SetImageArg (kernelIndex, argIndex++, false, "Palette"))) { m_ErrorReport.push_back(loc); }//Palette. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_PointsBufferName))) { m_ErrorReport.push_back(loc); }//Random start points. - - if (b && !(b = m_Wrapper.RunKernel(kernelIndex, - gridW * IterBlockKernelWidth(),//Total grid dims. - gridH * IterBlockKernelHeight(), - 1, - IterBlockKernelWidth(),//Individual block dims. - IterBlockKernelHeight(), - 1))) - { - m_Abort = true; - m_ErrorReport.push_back(loc); - break; - } - - itersRan += iterCountThisLaunch; - m_Calls++; - - if (m_Callback) - { - percent = 100.0 * - double - ( - double - ( - double - ( - double(m_LastIter + itersRan) / double(ItersPerTemporalSample()) - ) + temporalSample - ) / (double)TemporalSamples() - ); - - double percentDiff = percent - m_LastIterPercent; - double toc = m_ProgressTimer.Toc(); - - if (percentDiff >= 10 || (toc > 1000 && percentDiff >= 1))//Call callback function if either 10% has passed, or one second (and 1%). - { - etaMs = ((100.0 - percent) / percent) * m_RenderTimer.Toc(); - - if (!m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, percent, 0, etaMs)) - Abort(); - - m_LastIterPercent = percent; - m_ProgressTimer.Tic(); - } - } - } - } - else - { - b = false; - m_ErrorReport.push_back(loc); - } - - //t2.Toc(__FUNCTION__); - return b; -} - -/// -/// Run the log scale filter. -/// -/// True if success, else false. -template -eRenderStatus RendererCL::RunLogScaleFilter() -{ - //Timing t(4); - bool b = true; - int kernelIndex = m_Wrapper.FindKernelIndex(m_DEOpenCLKernelCreator.LogScaleAssignDEEntryPoint()); - const char* loc = __FUNCTION__; - eRenderStatus status = RENDER_OK; - - if (kernelIndex != -1) - { - m_DensityFilterCL = ConvertDensityFilter(); - unsigned int argIndex = 0; - unsigned int blockW = m_WarpSize; - unsigned int blockH = 4;//A height of 4 seems to run the fastest. - unsigned int gridW = m_DensityFilterCL.m_SuperRasW; - unsigned int gridH = m_DensityFilterCL.m_SuperRasH; - - OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); - - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DEFilterParamsBufferName, (void*)&m_DensityFilterCL, sizeof(m_DensityFilterCL)))) { m_ErrorReport.push_back(loc); } - - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_HistBufferName))) { m_ErrorReport.push_back(loc); }//Histogram. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_AccumBufferName))) { m_ErrorReport.push_back(loc); }//Accumulator. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_DEFilterParamsBufferName))) { m_ErrorReport.push_back(loc); }//DensityFilterCL. - - //t.Tic(); - if (b && !(b = m_Wrapper.RunKernel(kernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } - //t.Toc(loc); - } - else - { - b = false; - m_ErrorReport.push_back(loc); - } - - if (b && m_Callback) - m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, 100.0, 1, 0.0); - - return b ? RENDER_OK : RENDER_ERROR; -} - -/// -/// Run the Gaussian density filter. -/// Method 7: Each block processes a 32x32 block and exits. No column or row advancements happen. -/// -/// True if success and not aborted, else false. -template -eRenderStatus RendererCL::RunDensityFilter() -{ - bool b = true; - Timing t(4);// , t2(4); - m_DensityFilterCL = ConvertDensityFilter(); - int kernelIndex = MakeAndGetDensityFilterProgram(Supersample(), m_DensityFilterCL.m_FilterWidth); - const char* loc = __FUNCTION__; - - if (kernelIndex != -1) - { - unsigned int leftBound = m_DensityFilterCL.m_Supersample - 1; - unsigned int rightBound = m_DensityFilterCL.m_SuperRasW - (m_DensityFilterCL.m_Supersample - 1); - unsigned int topBound = leftBound; - unsigned int botBound = m_DensityFilterCL.m_SuperRasH - (m_DensityFilterCL.m_Supersample - 1); - unsigned int gridW = rightBound - leftBound; - unsigned int gridH = botBound - topBound; - unsigned int blockSizeW = m_MaxDEBlockSizeW;//These *must* both be divisible by 16 or else pixels will go missing. - unsigned int blockSizeH = m_MaxDEBlockSizeH; - - //OpenCL runs out of resources when using double or a supersample of 2. - //Remedy this by reducing the height of the block by 2. - if (m_DoublePrecision || m_DensityFilterCL.m_Supersample > 1) - blockSizeH -= 2; - - //Can't just blindly pass in vals. Must adjust them first to evenly divide the block count - //into the total grid dimensions. - OpenCLWrapper::MakeEvenGridDims(blockSizeW, blockSizeH, gridW, gridH); - - //t.Tic(); - //The classic problem with performing DE on adjacent pixels is that the filter will overlap. - //This can be solved in 2 ways. One is to use atomics, which is unacceptably slow. - //The other is to proces the entire image in multiple passes, and each pass processes blocks of pixels - //that are far enough apart such that their filters do not overlap. - //Do the latter. - //Gap is in terms of blocks. How many blocks must separate two blocks running at the same time. - unsigned int gapW = (unsigned int)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)blockSizeW); - unsigned int chunkSizeW = gapW + 1; - unsigned int gapH = (unsigned int)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)blockSizeH); - unsigned int chunkSizeH = gapH + 1; - double totalChunks = chunkSizeW * chunkSizeH; - - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DEFilterParamsBufferName, (void*)&m_DensityFilterCL, sizeof(m_DensityFilterCL)))) { m_ErrorReport.push_back(loc); } - -#ifdef ROW_ONLY_DE - blockSizeW = 64;//These *must* both be divisible by 16 or else pixels will go missing. - blockSizeH = 1; - gapW = (unsigned int)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)blockSizeW); - chunkSizeW = gapW + 1; - gapH = (unsigned int)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)32);//Block height is 1, but iterates over 32 rows. - chunkSizeH = gapH + 1; - totalChunks = chunkSizeW * chunkSizeH; - - OpenCLWrapper::MakeEvenGridDims(blockSizeW, blockSizeH, gridW, gridH); - gridW /= chunkSizeW; - gridH /= chunkSizeH; - - for (unsigned int rowChunk = 0; b && !m_Abort && rowChunk < chunkSizeH; rowChunk++) - { - for (unsigned int colChunk = 0; b && !m_Abort && colChunk < chunkSizeW; colChunk++) - { - //t2.Tic(); - if (b && !(b = RunDensityFilterPrivate(kernelIndex, gridW, gridH, blockSizeW, blockSizeH, chunkSizeW, chunkSizeH, colChunk, rowChunk))) { m_Abort = true; m_ErrorReport.push_back(loc); } - //t2.Toc(loc); - - if (b && m_Callback) - { - double percent = (double((rowChunk * chunkSizeW) + (colChunk + 1)) / totalChunks) * 100.0; - double etaMs = ((100.0 - percent) / percent) * t.Toc(); - - if (!m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, percent, 1, etaMs)) - Abort(); - } - } - } -#else - gridW /= chunkSizeW; - gridH /= chunkSizeH; - OpenCLWrapper::MakeEvenGridDims(blockSizeW, blockSizeH, gridW, gridH); - - for (unsigned int rowChunk = 0; b && !m_Abort && rowChunk < chunkSizeH; rowChunk++) - { - for (unsigned int colChunk = 0; b && !m_Abort && colChunk < chunkSizeW; colChunk++) - { - //t2.Tic(); - if (b && !(b = RunDensityFilterPrivate(kernelIndex, gridW, gridH, blockSizeW, blockSizeH, chunkSizeW, chunkSizeH, colChunk, rowChunk))) { m_Abort = true; m_ErrorReport.push_back(loc); } - //t2.Toc(loc); - - if (b && m_Callback) - { - double percent = (double((rowChunk * chunkSizeW) + (colChunk + 1)) / totalChunks) * 100.0; - double etaMs = ((100.0 - percent) / percent) * t.Toc(); - - if (!m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, percent, 1, etaMs)) - Abort(); - } - } - } -#endif - - if (b && m_Callback) - m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, 100.0, 1, 0.0); - - //t2.Toc(__FUNCTION__ " all passes"); - } - else - { - b = false; - m_ErrorReport.push_back(loc); - } - - return m_Abort ? RENDER_ABORT : (b ? RENDER_OK : RENDER_ERROR); -} - -/// -/// Run final accumulation to the 2D output image. -/// -/// True if success and not aborted, else false. -template -eRenderStatus RendererCL::RunFinalAccum() -{ - //Timing t(4); - bool b = true; - T alphaBase; - T alphaScale; - int accumKernelIndex = MakeAndGetFinalAccumProgram(alphaBase, alphaScale); - unsigned int argIndex; - unsigned int gridW; - unsigned int gridH; - unsigned int blockW; - unsigned int blockH; - const char* loc = __FUNCTION__; - - if (!m_Abort && accumKernelIndex != -1) - { - //This is needed with or without early clip. - m_SpatialFilterCL = ConvertSpatialFilter(); - - if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SpatialFilterParamsBufferName, (void*)&m_SpatialFilterCL, sizeof(m_SpatialFilterCL)))) { m_ErrorReport.push_back(loc); } - - //Since early clip requires gamma correcting the entire accumulator first, - //it can't be done inside of the normal final accumulation kernel, so - //an additional kernel must be launched first. - if (b && EarlyClip()) - { - int gammaCorrectKernelIndex = MakeAndGetGammaCorrectionProgram(); - - if (gammaCorrectKernelIndex != -1) - { - argIndex = 0; - blockW = m_WarpSize; - blockH = 4;//A height of 4 seems to run the fastest. - gridW = m_SpatialFilterCL.m_SuperRasW;//Using super dimensions because this processes the density filtering bufer. - gridH = m_SpatialFilterCL.m_SuperRasH; - OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); - - if (b && !(b = m_Wrapper.SetBufferArg(gammaCorrectKernelIndex, argIndex++, m_AccumBufferName))) { m_ErrorReport.push_back(loc); }//Accumulator. - if (b && !(b = m_Wrapper.SetBufferArg(gammaCorrectKernelIndex, argIndex++, m_SpatialFilterParamsBufferName))) { m_ErrorReport.push_back(loc); }//SpatialFilterCL. - - if (b && !(b = m_Wrapper.RunKernel(gammaCorrectKernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } - } - else - { - b = false; - m_ErrorReport.push_back(loc); - } - } - - argIndex = 0; - blockW = m_WarpSize; - blockH = 4;//A height of 4 seems to run the fastest. - gridW = m_SpatialFilterCL.m_FinalRasW; - gridH = m_SpatialFilterCL.m_FinalRasH; - OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); - - if (b && !(b = m_Wrapper.SetBufferArg(accumKernelIndex, argIndex++, m_AccumBufferName))) { m_ErrorReport.push_back(loc); }//Accumulator. - if (b && !(b = m_Wrapper.SetImageArg (accumKernelIndex, argIndex++, m_Wrapper.Shared(), m_FinalImageName))) { m_ErrorReport.push_back(loc); }//Final image. - if (b && !(b = m_Wrapper.SetBufferArg(accumKernelIndex, argIndex++, m_SpatialFilterParamsBufferName))) { m_ErrorReport.push_back(loc); }//SpatialFilterCL. - if (b && !(b = m_Wrapper.SetBufferArg(accumKernelIndex, argIndex++, m_SpatialFilterCoefsBufferName))) { m_ErrorReport.push_back(loc); }//Filter coefs. - if (b && !(b = m_Wrapper.SetArg (accumKernelIndex, argIndex++, alphaBase))) { m_ErrorReport.push_back(loc); }//Alpha base. - if (b && !(b = m_Wrapper.SetArg (accumKernelIndex, argIndex++, alphaScale))) { m_ErrorReport.push_back(loc); }//Alpha scale. - - if (b && m_Wrapper.Shared()) - if (b && !(b = m_Wrapper.EnqueueAcquireGLObjects(m_FinalImageName))) { m_ErrorReport.push_back(loc); } - - if (b && !(b = m_Wrapper.RunKernel(accumKernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } - - if (b && m_Wrapper.Shared()) - if (b && !(b = m_Wrapper.EnqueueReleaseGLObjects(m_FinalImageName))) { m_ErrorReport.push_back(loc); } - - //t.Toc((char*)loc); - } - else - { - b = false; - m_ErrorReport.push_back(loc); - } - - return b ? RENDER_OK : RENDER_ERROR; -} - -/// -/// Zeroize a buffer of the specified size. -/// -/// Name of the buffer to clear -/// Width in elements -/// Height in elements -/// Size of each element -/// True if success, else false. -template -bool RendererCL::ClearBuffer(const string& bufferName, unsigned int width, unsigned int height, unsigned int elementSize) -{ - bool b = true; - int kernelIndex = m_Wrapper.FindKernelIndex(m_IterOpenCLKernelCreator.ZeroizeEntryPoint()); - unsigned int argIndex = 0; - const char* loc = __FUNCTION__; - - if (kernelIndex != -1) - { - unsigned int blockW = m_NVidia ? 32 : 16;//Max work group size is 256 on AMD, which means 16x16. - unsigned int blockH = m_NVidia ? 32 : 16; - unsigned int gridW = width * elementSize; - unsigned int gridH = height; - - OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); - - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, bufferName))) { m_ErrorReport.push_back(loc); }//Buffer of unsigned char. - if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, width * elementSize))) { m_ErrorReport.push_back(loc); }//Width. - if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, height))) { m_ErrorReport.push_back(loc); }//Height. - if (b && !(b = m_Wrapper.RunKernel(kernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } - } - else - { - b = false; - m_ErrorReport.push_back(loc); - } - - return b; -} - -/// -/// Private wrapper around calling Gaussian density filtering kernel. -/// The parameters are very specific to how the kernel is internally implemented. -/// -/// Index of the kernel to call -/// Grid width -/// Grid height -/// Block width -/// Block height -/// Chunk size width (gapW + 1) -/// Chunk size height (gapH + 1) -/// Row parity -/// Column parity -/// True if success, else false. -template -bool RendererCL::RunDensityFilterPrivate(unsigned int kernelIndex, unsigned int gridW, unsigned int gridH, unsigned int blockW, unsigned int blockH, unsigned int chunkSizeW, unsigned int chunkSizeH, unsigned int chunkW, unsigned int chunkH) -{ - //Timing t(4); - bool b = true; - unsigned int argIndex = 0; - const char* loc = __FUNCTION__; - - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_HistBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Histogram. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_AccumBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Accumulator. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DEFilterParamsBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//FlameDensityFilterCL. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DECoefsBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Coefs. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DEWidthsBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Widths. - if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DECoefIndicesBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Coef indices. - if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkSizeW))) { m_ErrorReport.push_back(loc); } argIndex++;//Chunk size width (gapW + 1). - if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkSizeH))) { m_ErrorReport.push_back(loc); } argIndex++;//Chunk size height (gapH + 1). - if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkW))) { m_ErrorReport.push_back(loc); } argIndex++;//Column chunk. - if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkH))) { m_ErrorReport.push_back(loc); } argIndex++;//Row chunk. - //t.Toc(__FUNCTION__ " set args"); - - //t.Tic(); - if (b && !(b = m_Wrapper.RunKernel(kernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); }//Method 7, accumulating to temp box area. - //t.Toc(__FUNCTION__ " RunKernel()"); - - return b; -} - -/// -/// Make the Gaussian density filter program and return its index. -/// -/// The supersample being used for the current ember -/// Width of the gaussian filter -/// The kernel index if successful, else -1. -template -int RendererCL::MakeAndGetDensityFilterProgram(size_t ss, unsigned int filterWidth) -{ - string deEntryPoint = m_DEOpenCLKernelCreator.GaussianDEEntryPoint(ss, filterWidth); - int kernelIndex = m_Wrapper.FindKernelIndex(deEntryPoint); - const char* loc = __FUNCTION__; - - if (kernelIndex == -1)//Has not been built yet. - { - string kernel = m_DEOpenCLKernelCreator.GaussianDEKernel(ss, filterWidth); - bool b = m_Wrapper.AddProgram(deEntryPoint, kernel, deEntryPoint, m_DoublePrecision); - - if (b) - { - kernelIndex = m_Wrapper.FindKernelIndex(deEntryPoint);//Try to find it again, it will be present if successfully built. - } - else - { - m_ErrorReport.push_back(string(loc) + "():\nBuilding the following program failed: \n" + kernel + "\n"); - //cout << m_ErrorReport.back(); - } - } - - return kernelIndex; -} - -/// -/// Make the final accumulation program and return its index. -/// There are many different kernels for final accum, depending on early clip, alpha channel, and transparency. -/// Loading all of these in the beginning is too much, so only load the one for the current case being worked with. -/// -/// Storage for the alpha base value used in the kernel. 0 if transparency is true, else 255. -/// Storage for the alpha scale value used in the kernel. 255 if transparency is true, else 0. -/// The kernel index if successful, else -1. -template -int RendererCL::MakeAndGetFinalAccumProgram(T& alphaBase, T& alphaScale) -{ - string finalAccumEntryPoint = m_FinalAccumOpenCLKernelCreator.FinalAccumEntryPoint(EarlyClip(), Renderer::NumChannels(), Transparency(), alphaBase, alphaScale); - int kernelIndex = m_Wrapper.FindKernelIndex(finalAccumEntryPoint); - const char* loc = __FUNCTION__; - - if (kernelIndex == -1)//Has not been built yet. - { - string kernel = m_FinalAccumOpenCLKernelCreator.FinalAccumKernel(EarlyClip(), Renderer::NumChannels(), Transparency()); - bool b = m_Wrapper.AddProgram(finalAccumEntryPoint, kernel, finalAccumEntryPoint, m_DoublePrecision); - - if (b) - kernelIndex = m_Wrapper.FindKernelIndex(finalAccumEntryPoint);//Try to find it again, it will be present if successfully built. - else - m_ErrorReport.push_back(loc); - } - - return kernelIndex; -} - -/// -/// Make the gamma correction program for early clipping and return its index. -/// -/// The kernel index if successful, else -1. -template -int RendererCL::MakeAndGetGammaCorrectionProgram() -{ - string gammaEntryPoint = m_FinalAccumOpenCLKernelCreator.GammaCorrectionEntryPoint(Renderer::NumChannels(), Transparency()); - int kernelIndex = m_Wrapper.FindKernelIndex(gammaEntryPoint); - const char* loc = __FUNCTION__; - - if (kernelIndex == -1)//Has not been built yet. - { - string kernel = m_FinalAccumOpenCLKernelCreator.GammaCorrectionKernel(Renderer::NumChannels(), Transparency()); - bool b = m_Wrapper.AddProgram(gammaEntryPoint, kernel, gammaEntryPoint, m_DoublePrecision); - - if (b) - kernelIndex = m_Wrapper.FindKernelIndex(gammaEntryPoint);//Try to find it again, it will be present if successfully built. - else - m_ErrorReport.push_back(loc); - } - - return kernelIndex; -} - -/// -/// Private functions passing data to OpenCL programs. -/// - -/// -/// Convert the currently used host side DensityFilter object into a DensityFilterCL object -/// for passing to OpenCL. -/// -/// The DensityFilterCL object -template -DensityFilterCL RendererCL::ConvertDensityFilter() -{ - DensityFilterCL filterCL; - DensityFilter* densityFilter = dynamic_cast*>(GetDensityFilter()); - - filterCL.m_Supersample = (unsigned int)Supersample(); - filterCL.m_SuperRasW = (unsigned int)SuperRasW(); - filterCL.m_SuperRasH = (unsigned int)SuperRasH(); - filterCL.m_K1 = K1(); - filterCL.m_K2 = K2(); - - if (densityFilter) - { - filterCL.m_Curve = densityFilter->Curve(); - filterCL.m_KernelSize = (unsigned int)densityFilter->KernelSize(); - filterCL.m_MaxFilterIndex = (unsigned int)densityFilter->MaxFilterIndex(); - filterCL.m_MaxFilteredCounts = (unsigned int)densityFilter->MaxFilteredCounts(); - filterCL.m_FilterWidth = (unsigned int)densityFilter->FilterWidth(); - } - - return filterCL; -} - -/// -/// Convert the currently used host side SpatialFilter object into a SpatialFilterCL object -/// for passing to OpenCL. -/// -/// The SpatialFilterCL object -template -SpatialFilterCL RendererCL::ConvertSpatialFilter() -{ - T g, linRange, vibrancy; - Color background; - SpatialFilterCL filterCL; - - this->PrepFinalAccumVals(background, g, linRange, vibrancy); - - filterCL.m_SuperRasW = (unsigned int)SuperRasW(); - filterCL.m_SuperRasH = (unsigned int)SuperRasH(); - filterCL.m_FinalRasW = (unsigned int)FinalRasW(); - filterCL.m_FinalRasH = (unsigned int)FinalRasH(); - filterCL.m_Supersample = (unsigned int)Supersample(); - filterCL.m_FilterWidth = (unsigned int)GetSpatialFilter()->FinalFilterWidth(); - filterCL.m_NumChannels = (unsigned int)Renderer::NumChannels(); - filterCL.m_BytesPerChannel = (unsigned int)BytesPerChannel(); - filterCL.m_DensityFilterOffset = (unsigned int)DensityFilterOffset(); - filterCL.m_Transparency = Transparency(); - filterCL.m_YAxisUp = (unsigned int)m_YAxisUp; - filterCL.m_Vibrancy = vibrancy; - filterCL.m_HighlightPower = HighlightPower(); - filterCL.m_Gamma = g; - filterCL.m_LinRange = linRange; - filterCL.m_Background = background; - - return filterCL; -} - -/// -/// Convert the host side Ember object into an EmberCL object -/// and a vector of XformCL for passing to OpenCL. -/// -/// The Ember object to convert -/// The converted EmberCL -/// The converted vector of XformCL -template -void RendererCL::ConvertEmber(Ember& ember, EmberCL& emberCL, vector>& xformsCL) -{ - memset(&emberCL, 0, sizeof(EmberCL));//Might not really be needed. - - emberCL.m_RotA = m_RotMat.A(); - emberCL.m_RotB = m_RotMat.B(); - emberCL.m_RotD = m_RotMat.D(); - emberCL.m_RotE = m_RotMat.E(); - emberCL.m_CamMat = ember.m_CamMat; - emberCL.m_CenterX = CenterX(); - emberCL.m_CenterY = ember.m_RotCenterY; - emberCL.m_CamZPos = ember.m_CamZPos; - emberCL.m_CamPerspective = ember.m_CamPerspective; - emberCL.m_CamYaw = ember.m_CamYaw; - emberCL.m_CamPitch = ember.m_CamPitch; - emberCL.m_CamDepthBlur = ember.m_CamDepthBlur; - emberCL.m_BlurCoef = ember.BlurCoef(); - - for (unsigned int i = 0; i < ember.TotalXformCount() && i < xformsCL.size(); i++) - { - Xform* xform = ember.GetTotalXform(i); - - xformsCL[i].m_A = xform->m_Affine.A(); - xformsCL[i].m_B = xform->m_Affine.B(); - xformsCL[i].m_C = xform->m_Affine.C(); - xformsCL[i].m_D = xform->m_Affine.D(); - xformsCL[i].m_E = xform->m_Affine.E(); - xformsCL[i].m_F = xform->m_Affine.F(); - - xformsCL[i].m_PostA = xform->m_Post.A(); - xformsCL[i].m_PostB = xform->m_Post.B(); - xformsCL[i].m_PostC = xform->m_Post.C(); - xformsCL[i].m_PostD = xform->m_Post.D(); - xformsCL[i].m_PostE = xform->m_Post.E(); - xformsCL[i].m_PostF = xform->m_Post.F(); - - xformsCL[i].m_DirectColor = xform->m_DirectColor; - xformsCL[i].m_ColorSpeedCache = xform->ColorSpeedCache(); - xformsCL[i].m_OneMinusColorCache = xform->OneMinusColorCache(); - xformsCL[i].m_Opacity = xform->m_Opacity; - xformsCL[i].m_VizAdjusted = xform->VizAdjusted(); - - for (unsigned int varIndex = 0; varIndex < xform->TotalVariationCount() && varIndex < MAX_CL_VARS; varIndex++)//Assign all variation weights for this xform, with a max of MAX_CL_VARS. - xformsCL[i].m_VariationWeights[varIndex] = xform->GetVariation(varIndex)->m_Weight; - } -} - -/// -/// Convert the host side CarToRas object into a CarToRasCL object -/// for passing to OpenCL. -/// -/// The CarToRas object to convert -/// The CarToRasCL object -template -CarToRasCL RendererCL::ConvertCarToRas(const CarToRas& carToRas) -{ - CarToRasCL carToRasCL; - - carToRasCL.m_RasWidth = (unsigned int)carToRas.RasWidth(); - carToRasCL.m_PixPerImageUnitW = carToRas.PixPerImageUnitW(); - carToRasCL.m_RasLlX = carToRas.RasLlX(); - carToRasCL.m_PixPerImageUnitH = carToRas.PixPerImageUnitH(); - carToRasCL.m_RasLlY = carToRas.RasLlY(); - carToRasCL.m_CarLlX = carToRas.CarLlX(); - carToRasCL.m_CarLlY = carToRas.CarLlY(); - carToRasCL.m_CarUrX = carToRas.CarUrX(); - carToRasCL.m_CarUrY = carToRas.CarUrY(); - - return carToRasCL; -} - -/// -/// Fill seeds buffer which gets passed to the iteration kernel. -/// Note, WriteBuffer() must be called after this to actually copy the -/// data from the host to the device. -/// -template -void RendererCL::FillSeeds() -{ - m_Seeds.resize(IterGridKernelCount()); - - for (size_t i = 0; i < m_Seeds.size(); i++) - { - m_Seeds[i].x = m_Rand[0].Rand(); - m_Seeds[i].y = m_Rand[0].Rand(); - } -} - -template EMBERCL_API class RendererCL; - -#ifdef DO_DOUBLE - template EMBERCL_API class RendererCL; -#endif -} + return success; +} + +/// +/// OpenCL property accessors, getters only. +/// + +//Iters per kernel/block/grid. +template uint RendererCL::IterCountPerKernel() const { return m_IterCountPerKernel; } +template uint RendererCL::IterCountPerBlock() const { return IterCountPerKernel() * IterBlockKernelCount(); } +template uint RendererCL::IterCountPerGrid() const { return IterCountPerKernel() * IterGridKernelCount(); } + +//Kernels per block. +template uint RendererCL::IterBlockKernelWidth() const { return m_IterBlockWidth; } +template uint RendererCL::IterBlockKernelHeight() const { return m_IterBlockHeight; } +template uint RendererCL::IterBlockKernelCount() const { return IterBlockKernelWidth() * IterBlockKernelHeight(); } + +//Kernels per grid. +template uint RendererCL::IterGridKernelWidth() const { return IterGridBlockWidth() * IterBlockKernelWidth(); } +template uint RendererCL::IterGridKernelHeight() const { return IterGridBlockHeight() * IterBlockKernelHeight(); } +template uint RendererCL::IterGridKernelCount() const { return IterGridKernelWidth() * IterGridKernelHeight(); } + +//Blocks per grid. +template uint RendererCL::IterGridBlockWidth() const { return m_IterBlocksWide; } +template uint RendererCL::IterGridBlockHeight() const { return m_IterBlocksHigh; } +template uint RendererCL::IterGridBlockCount() const { return IterGridBlockWidth() * IterGridBlockHeight(); } + +template uint RendererCL::PlatformIndex() { return m_Wrapper.PlatformIndex(); } +template uint RendererCL::DeviceIndex() { return m_Wrapper.DeviceIndex(); } + +/// +/// Read the histogram into the host side CPU buffer. +/// Used for debugging. +/// +/// True if success, else false. +template +bool RendererCL::ReadHist() +{ + if (Renderer::Alloc())//Allocate the memory to read into. + return m_Wrapper.ReadBuffer(m_HistBufferName, (void*)HistBuckets(), SuperSize() * sizeof(v4T)); + + return false; +} + +/// +/// Read the density filtering buffer into the host side CPU buffer. +/// Used for debugging. +/// +/// True if success, else false. +template +bool RendererCL::ReadAccum() +{ + if (Renderer::Alloc())//Allocate the memory to read into. + return m_Wrapper.ReadBuffer(m_AccumBufferName, (void*)AccumulatorBuckets(), SuperSize() * sizeof(v4T)); + + return false; +} + +/// +/// Read the temporary points buffer into a host side CPU buffer. +/// Used for debugging. +/// +/// The host side buffer to read into +/// True if success, else false. +template +bool RendererCL::ReadPoints(vector>& vec) +{ + vec.resize(IterGridKernelCount());//Allocate the memory to read into. + + if (vec.size() >= IterGridKernelCount()) + return m_Wrapper.ReadBuffer(m_PointsBufferName, (void*)vec.data(), IterGridKernelCount() * sizeof(PointCL)); + + return false; +} + +/// +/// Clear the histogram buffer with all zeroes. +/// +/// True if success, else false. +template +bool RendererCL::ClearHist() +{ + return ClearBuffer(m_HistBufferName, (uint)SuperRasW(), (uint)SuperRasH(), sizeof(v4T)); +} + +/// +/// Clear the desnity filtering buffer with all zeroes. +/// +/// True if success, else false. +template +bool RendererCL::ClearAccum() +{ + return ClearBuffer(m_AccumBufferName, (uint)SuperRasW(), (uint)SuperRasH(), sizeof(v4T)); +} + +/// +/// Write values from a host side CPU buffer into the temporary points buffer. +/// Used for debugging. +/// +/// The host side buffer whose values to write +/// True if success, else false. +template +bool RendererCL::WritePoints(vector>& vec) +{ + return m_Wrapper.WriteBuffer(m_PointsBufferName, (void*)vec.data(), vec.size() * sizeof(vec[0])); +} + +#ifdef TEST_CL +template +bool RendererCL::WriteRandomPoints() +{ + size_t size = IterGridKernelCount(); + vector> vec(size); + + for (int i = 0; i < size; i++) + { + vec[i].m_X = m_Rand[0].Frand11(); + vec[i].m_Y = m_Rand[0].Frand11(); + vec[i].m_Z = 0; + vec[i].m_ColorX = m_Rand[0].Frand01(); + vec[i].m_LastXfUsed = 0; + } + + return WritePoints(vec); +} +#endif + +/// +/// Get the kernel string for the last built iter program. +/// +/// The string representation of the kernel for the last built iter program. +template +string RendererCL::IterKernel() { return m_IterKernel; } + +/// +/// Virtual functions overridden from RendererCLBase. +/// + +/// +/// Read the final image buffer buffer into the host side CPU buffer. +/// This must be called before saving the final output image to file. +/// +/// The host side buffer to read into +/// True if success, else false. +template +bool RendererCL::ReadFinal(byte* pixels) +{ + if (pixels) + return m_Wrapper.ReadImage(m_FinalImageName, FinalRasW(), FinalRasH(), 0, m_Wrapper.Shared(), pixels); + + return false; +} + +/// +/// Clear the final image output buffer with all zeroes by copying a host side buffer. +/// Slow, but never used because the final output image is always completely overwritten. +/// +/// True if success, else false. +template +bool RendererCL::ClearFinal() +{ + vector v; + uint index = m_Wrapper.FindImageIndex(m_FinalImageName, m_Wrapper.Shared()); + + if (this->PrepFinalAccumVector(v)) + { + bool b = m_Wrapper.WriteImage2D(index, m_Wrapper.Shared(), FinalRasW(), FinalRasH(), 0, v.data()); + + if (!b) + m_ErrorReport.push_back(__FUNCTION__); + + return b; + } + else + return false; +} + +/// +/// Public virtual functions overridden from Renderer or RendererBase. +/// + +/// +/// The amount of video RAM available on the GPU to render with. +/// +/// An unsigned 64-bit integer specifying how much video memory is available +template +size_t RendererCL::MemoryAvailable() +{ + return Ok() ? m_Wrapper.GetInfo(PlatformIndex(), DeviceIndex(), CL_DEVICE_GLOBAL_MEM_SIZE) : 0ULL; +} + +/// +/// Return whether OpenCL has been properly initialized. +/// +/// True if OpenCL has been properly initialized, else false. +template +bool RendererCL::Ok() const +{ + return m_Init; +} + +/// +/// Override to force num channels to be 4 because RGBA is always used for OpenCL +/// since the output is actually an image rather than just a buffer. +/// +/// The number of channels, ignored. +template +void RendererCL::NumChannels(size_t numChannels) +{ + m_NumChannels = 4; +} + +/// +/// Dump the error report for this class as well as the OpenCLWrapper member. +/// +template +void RendererCL::DumpErrorReport() +{ + EmberReport::DumpErrorReport(); + m_Wrapper.DumpErrorReport(); +} + +/// +/// Clear the error report for this class as well as the OpenCLWrapper member. +/// +template +void RendererCL::ClearErrorReport() +{ + EmberReport::ClearErrorReport(); + m_Wrapper.ClearErrorReport(); +} + +/// +/// The sub batch size for OpenCL will always be how many +/// iterations are ran per kernel call. The caller can't +/// change this. +/// +/// The number of iterations ran in a single kernel call +template +size_t RendererCL::SubBatchSize() const +{ + return IterCountPerGrid(); +} + +/// +/// The thread count for OpenCL is always considered to be 1, however +/// the kernel internally runs many threads. +/// +/// 1 +template +size_t RendererCL::ThreadCount() const +{ + return 1; +} + +/// +/// Create the density filter in the base class and copy the filter values +/// to the corresponding OpenCL buffers. +/// +/// True if a new filter instance was created, else false. +/// True if success, else false. +template +bool RendererCL::CreateDEFilter(bool& newAlloc) +{ + bool b = true; + + if (Renderer::CreateDEFilter(newAlloc)) + { + //Copy coefs and widths here. Convert and copy the other filter params right before calling the filtering kernel. + if (newAlloc) + { + const char* loc = __FUNCTION__; + DensityFilter* filter = dynamic_cast*>(GetDensityFilter()); + + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DECoefsBufferName, (void*)filter->Coefs(), filter->CoefsSizeBytes()))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DEWidthsBufferName, (void*)filter->Widths(), filter->WidthsSizeBytes()))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DECoefIndicesBufferName, (void*)filter->CoefIndices(), filter->CoefsIndicesSizeBytes()))) { m_ErrorReport.push_back(loc); } + } + } + else + b = false; + + return b; +} + +/// +/// Create the spatial filter in the base class and copy the filter values +/// to the corresponding OpenCL buffers. +/// +/// True if a new filter instance was created, else false. +/// True if success, else false. +template +bool RendererCL::CreateSpatialFilter(bool& newAlloc) +{ + bool b = true; + + if (Renderer::CreateSpatialFilter(newAlloc)) + { + if (newAlloc) + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SpatialFilterCoefsBufferName, (void*)GetSpatialFilter()->Filter(), GetSpatialFilter()->BufferSizeBytes()))) { m_ErrorReport.push_back(__FUNCTION__); } + + } + else + b = false; + + return b; +} + +/// +/// Get the renderer type enum. +/// +/// OPENCL_RENDERER +template +eRendererType RendererCL::RendererType() const +{ + return OPENCL_RENDERER; +} + +/// +/// Concatenate and return the error report for this class and the +/// OpenCLWrapper member as a single string. +/// +/// The concatenated error report string +template +string RendererCL::ErrorReportString() +{ + return EmberReport::ErrorReportString() + m_Wrapper.ErrorReportString(); +} + +/// +/// Concatenate and return the error report for this class and the +/// OpenCLWrapper member as a vector of strings. +/// +/// The concatenated error report vector of strings +template +vector RendererCL::ErrorReport() +{ + vector ours = EmberReport::ErrorReport(); + vector wrappers = m_Wrapper.ErrorReport(); + + ours.insert(ours.end(), wrappers.begin(), wrappers.end()); + return ours; +} + +/// +/// Set the vector of random contexts. +/// Call the base, and reset the seeds vector. +/// +/// The vector of random contexts to assign +/// True if the size of the vector matched the number of threads used for rendering and writing seeds to OpenCL succeeded, else false. +template +bool RendererCL::RandVec(vector>& randVec) +{ + bool b = Renderer::RandVec(randVec); + const char* loc = __FUNCTION__; + + if (m_Wrapper.Ok()) + { + FillSeeds(); + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SeedsBufferName, (void*)m_Seeds.data(), SizeOf(m_Seeds)))) { m_ErrorReport.push_back(loc); } + } + + return b; +} + +/// +/// Protected virtual functions overridden from Renderer. +/// + +/// +/// Make the final palette used for iteration. +/// This override differs from the base in that it does not use +/// bucketT as the output palette type. This is because OpenCL +/// only supports floats for texture images. +/// +/// The color scalar to multiply the ember's palette by +template +void RendererCL::MakeDmap(T colorScalar) +{ + //m_Ember.m_Palette.MakeDmap(m_DmapCL, colorScalar); + m_Ember.m_Palette.MakeDmap(m_DmapCL, colorScalar); +} + + +/// +/// Allocate all buffers required for running as well as the final +/// 2D image. +/// +/// True if success, else false. +template +bool RendererCL::Alloc() +{ + if (!m_Wrapper.Ok()) + return false; + + EnterResize(); + m_XformsCL.resize(m_Ember.TotalXformCount()); + + bool b = true; + size_t histLength = SuperSize() * sizeof(v4T); + size_t accumLength = SuperSize() * sizeof(v4T); + const char* loc = __FUNCTION__; + + if (b && !(b = m_Wrapper.AddBuffer(m_EmberBufferName, sizeof(m_EmberCL)))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddBuffer(m_XformsBufferName, SizeOf(m_XformsCL)))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddBuffer(m_ParVarsBufferName, 128 * sizeof(T)))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddBuffer(m_DistBufferName, CHOOSE_XFORM_GRAIN))) { m_ErrorReport.push_back(loc); }//Will be resized for xaos. + if (b && !(b = m_Wrapper.AddBuffer(m_CarToRasBufferName, sizeof(m_CarToRasCL)))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddBuffer(m_DEFilterParamsBufferName, sizeof(m_DensityFilterCL)))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddBuffer(m_SpatialFilterParamsBufferName, sizeof(m_SpatialFilterCL)))) { m_ErrorReport.push_back(loc); } + + if (b && !(b = m_Wrapper.AddBuffer(m_HistBufferName, histLength))) { m_ErrorReport.push_back(loc); }//Histogram. Will memset to zero later. + if (b && !(b = m_Wrapper.AddBuffer(m_AccumBufferName, accumLength))) { m_ErrorReport.push_back(loc); }//Accum buffer. + if (b && !(b = m_Wrapper.AddBuffer(m_PointsBufferName, IterGridKernelCount() * sizeof(PointCL)))) { m_ErrorReport.push_back(loc); }//Points between iter calls. + + LeaveResize(); + + if (b && !(b = SetOutputTexture(m_OutputTexID))) { m_ErrorReport.push_back(loc); } + + return b; +} + +/// +/// Clear OpenCL histogram and/or density filtering buffers to all zeroes. +/// +/// Clear histogram if true, else don't. +/// Clear density filtering buffer if true, else don't. +/// True if success, else false. +template +bool RendererCL::ResetBuckets(bool resetHist, bool resetAccum) +{ + bool b = true; + + if (resetHist) + b &= ClearHist(); + + if (resetAccum) + b &= ClearAccum(); + + return b; +} + +/// +/// Perform log scale density filtering. +/// +/// True if success and not aborted, else false. +template +eRenderStatus RendererCL::LogScaleDensityFilter() +{ + return RunLogScaleFilter(); +} + +/// +/// Run gaussian density estimation filtering. +/// +/// True if success and not aborted, else false. +template +eRenderStatus RendererCL::GaussianDensityFilter() +{ + //This commented section is for debugging density filtering by making it run on the CPU + //then copying the results back to the GPU. + //if (ReadHist()) + //{ + // uint accumLength = SuperSize() * sizeof(glm::detail::tvec4); + // const char* loc = __FUNCTION__; + // + // Renderer::ResetBuckets(false, true); + // Renderer::GaussianDensityFilter(); + // + // if (!m_Wrapper.WriteBuffer(m_AccumBufferName, AccumulatorBuckets(), accumLength)) { m_ErrorReport.push_back(loc); return RENDER_ERROR; } + // return RENDER_OK; + //} + //else + // return RENDER_ERROR; + + //Timing t(4); + + eRenderStatus status = RunDensityFilter(); + //t.Toc(__FUNCTION__ " RunKernel()"); + + return status; +} + +/// +/// Run final accumulation. +/// If pixels is NULL, the output will remain in the OpenCL 2D image. +/// However, if pixels is not NULL, the output will be copied. This is +/// useful when rendering in OpenCL, but saving the output to a file. +/// +/// The pixels to copy the final image to if not NULL +/// Offset in the buffer to store the pixels to +/// True if success and not aborted, else false. +template +eRenderStatus RendererCL::AccumulatorToFinalImage(byte* pixels, size_t finalOffset) +{ + eRenderStatus status = RunFinalAccum(); + + if (status == RENDER_OK && pixels != NULL && !m_Wrapper.Shared()) + { + pixels += finalOffset; + + if (!ReadFinal(pixels)) + status = RENDER_ERROR; + } + + return status; +} + +/// +/// Run the iteration algorithm for the specified number of iterations. +/// This is only called after all other setup has been done. +/// This will recompile the OpenCL program if this ember differs significantly +/// from the previous run. +/// Note that the bad value count is not recorded when running with OpenCL. If it's +/// needed, run on the CPU. +/// +/// The number of iterations to run +/// The temporal sample within the current pass this is running for +/// Rendering statistics +template +EmberStats RendererCL::Iterate(size_t iterCount, size_t temporalSample) +{ + bool b = true; + EmberStats stats;//Do not record bad vals with with GPU. If the user needs to investigate bad vals, use the CPU. + const char* loc = __FUNCTION__; + + IterOpenCLKernelCreator::ParVarIndexDefines(m_Ember, m_Params, true, false);//Always do this to get the values (but no string), regardless of whether a rebuild is necessary. + + //Don't know the size of the parametric varations parameters buffer until the ember is examined. + //So set it up right before the run. + if (!m_Params.second.empty()) + { + if (!m_Wrapper.AddAndWriteBuffer(m_ParVarsBufferName, m_Params.second.data(), m_Params.second.size() * sizeof(m_Params.second[0]))) + { + m_Abort = true; + m_ErrorReport.push_back(loc); + return stats; + } + } + + //Rebuilding is expensive, so only do it if it's required. + if (IterOpenCLKernelCreator::IsBuildRequired(m_Ember, m_LastBuiltEmber)) + b = BuildIterProgramForEmber(true); + + if (b) + { + m_IterTimer.Tic();//Tic() here to avoid including build time in iter time measurement. + + if (m_Stats.m_Iters == 0)//Only reset the call count on the beginning of a new render. Do not reset on KEEP_ITERATING. + m_Calls = 0; + + b = RunIter(iterCount, temporalSample, stats.m_Iters); + + if (!b || stats.m_Iters == 0)//If no iters were executed, something went catastrophically wrong. + m_Abort = true; + + stats.m_IterMs = m_IterTimer.Toc(); + } + else + { + m_Abort = true; + m_ErrorReport.push_back(loc); + } + + return stats; +} + +/// +/// Private functions for making and running OpenCL programs. +/// + +/// +/// Build the iteration program for the current ember. +/// +/// Whether to build in accumulation, only for debugging. Default: true. +/// True if success, else false. +template +bool RendererCL::BuildIterProgramForEmber(bool doAccum) +{ + //Timing t; + const char* loc = __FUNCTION__; + IterOpenCLKernelCreator::ParVarIndexDefines(m_Ember, m_Params, false, true);//Do with string and no vals. + m_IterKernel = m_IterOpenCLKernelCreator.CreateIterKernelString(m_Ember, m_Params.first, m_LockAccum, doAccum); + //cout << "Building: " << endl << iterProgram << endl; + + //A program build is roughly .66s which will detract from the user experience. + //Need to experiment with launching this in a thread/task and returning once it's done.//TODO + if (m_Wrapper.AddProgram(m_IterOpenCLKernelCreator.IterEntryPoint(), m_IterKernel, m_IterOpenCLKernelCreator.IterEntryPoint(), m_DoublePrecision)) + { + //t.Toc(__FUNCTION__ " program build"); + //cout << string(loc) << "():\nBuilding the following program succeeded: \n" << iterProgram << endl; + m_LastBuiltEmber = m_Ember; + } + else + { + m_ErrorReport.push_back(string(loc) + "():\nBuilding the following program failed: \n" + m_IterKernel + "\n"); + return false; + } + + return true; +} + +/// +/// Run the iteration kernel. +/// Fusing on the CPU is done once per sub batch, usually 10,000 iters, however +/// determining when to do it in OpenCL is much more difficult. +/// Currently it's done once every 4 kernel calls which seems to be a good balance +/// between quality of the final image and performance. +/// +/// The number of iterations to run +/// The temporal sample this is running for +/// The storage for the number of iterations ran +/// True if success, else false. +template +bool RendererCL::RunIter(size_t iterCount, size_t temporalSample, size_t& itersRan) +{ + Timing t;//, t2(4); + bool b = true; + uint fuse, argIndex; + uint iterCountPerKernel = IterCountPerKernel(); + uint iterCountPerBlock = IterCountPerBlock(); + uint supersize = (uint)SuperSize(); + int kernelIndex = m_Wrapper.FindKernelIndex(m_IterOpenCLKernelCreator.IterEntryPoint()); + size_t fuseFreq = Renderer::SubBatchSize() / m_IterCountPerKernel;//Use the base sbs to determine when to fuse. + size_t itersRemaining, localIterCount = 0; + double percent, etaMs; + const char* loc = __FUNCTION__; + + itersRan = 0; +#ifdef TEST_CL + m_Abort = false; +#endif + + if (kernelIndex != -1) + { + ConvertEmber(m_Ember, m_EmberCL, m_XformsCL); + m_CarToRasCL = ConvertCarToRas(*CoordMap()); + + if (b && !(b = m_Wrapper.WriteBuffer (m_EmberBufferName, (void*)&m_EmberCL, sizeof(m_EmberCL)))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.WriteBuffer (m_XformsBufferName, (void*)m_XformsCL.data(), sizeof(m_XformsCL[0]) * m_XformsCL.size()))) { m_ErrorReport.push_back(loc); } + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DistBufferName, (void*)XformDistributions(), XformDistributionsSize()))) { m_ErrorReport.push_back(loc); }//Will be resized for xaos. + if (b && !(b = m_Wrapper.WriteBuffer (m_CarToRasBufferName, (void*)&m_CarToRasCL, sizeof(m_CarToRasCL)))) { m_ErrorReport.push_back(loc); } + + if (b && !(b = m_Wrapper.AddAndWriteImage("Palette", CL_MEM_READ_ONLY, m_PaletteFormat, m_DmapCL.m_Entries.size(), 1, 0, m_DmapCL.m_Entries.data()))) { m_ErrorReport.push_back(loc); } + + //If animating, treat each temporal sample as a newly started render for fusing purposes. + if (temporalSample > 0) + m_Calls = 0; + + while (b && itersRan < iterCount && !m_Abort) + { + argIndex = 0; +#ifdef TEST_CL + fuse = 0; +#else + //fuse = 100; + //fuse = ((m_Calls % fuseFreq) == 0 ? (EarlyClip() ? 100u : 15u) : 0u); + fuse = (uint)((m_Calls % fuseFreq) == 0u ? FuseCount() : 0u); + //fuse = ((m_Calls % 4) == 0 ? 100u : 0u); +#endif + itersRemaining = iterCount - itersRan; + uint gridW = (uint)min(ceil((double)itersRemaining / (double)iterCountPerBlock), (double)IterGridBlockWidth()); + uint gridH = (uint)min(ceil((double)itersRemaining / ((double)gridW * iterCountPerBlock)), (double)IterGridBlockHeight()); + uint iterCountThisLaunch = iterCountPerBlock * gridW * gridH; + + //Similar to what's done in the base class. + //The number of iters per thread must be adjusted if they've requested less iters than is normally ran in a block (256 * 256). + if (iterCountThisLaunch > iterCount) + { + iterCountPerKernel = (uint)ceil((double)iterCount / (double)(gridW * gridH * IterBlockKernelCount())); + iterCountThisLaunch = iterCountPerKernel * (gridW * gridH * IterBlockKernelCount()); + } + + if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, iterCountPerKernel))) { m_ErrorReport.push_back(loc); }//Number of iters for each thread to run. + if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, fuse))) { m_ErrorReport.push_back(loc); }//Number of iters to fuse. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_SeedsBufferName))) { m_ErrorReport.push_back(loc); }//Seeds. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_EmberBufferName))) { m_ErrorReport.push_back(loc); }//Ember. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_XformsBufferName))) { m_ErrorReport.push_back(loc); }//Xforms. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_ParVarsBufferName))) { m_ErrorReport.push_back(loc); }//Parametric variation parameters. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_DistBufferName))) { m_ErrorReport.push_back(loc); }//Xform distributions. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_CarToRasBufferName))) { m_ErrorReport.push_back(loc); }//Coordinate converter. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_HistBufferName))) { m_ErrorReport.push_back(loc); }//Histogram. + if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, supersize))) { m_ErrorReport.push_back(loc); }//Histogram size. + if (b && !(b = m_Wrapper.SetImageArg (kernelIndex, argIndex++, false, "Palette"))) { m_ErrorReport.push_back(loc); }//Palette. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_PointsBufferName))) { m_ErrorReport.push_back(loc); }//Random start points. + + if (b && !(b = m_Wrapper.RunKernel(kernelIndex, + gridW * IterBlockKernelWidth(),//Total grid dims. + gridH * IterBlockKernelHeight(), + 1, + IterBlockKernelWidth(),//Individual block dims. + IterBlockKernelHeight(), + 1))) + { + m_Abort = true; + m_ErrorReport.push_back(loc); + break; + } + + itersRan += iterCountThisLaunch; + m_Calls++; + + if (m_Callback) + { + percent = 100.0 * + double + ( + double + ( + double + ( + double(m_LastIter + itersRan) / double(ItersPerTemporalSample()) + ) + temporalSample + ) / (double)TemporalSamples() + ); + + double percentDiff = percent - m_LastIterPercent; + double toc = m_ProgressTimer.Toc(); + + if (percentDiff >= 10 || (toc > 1000 && percentDiff >= 1))//Call callback function if either 10% has passed, or one second (and 1%). + { + etaMs = ((100.0 - percent) / percent) * m_RenderTimer.Toc(); + + if (!m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, percent, 0, etaMs)) + Abort(); + + m_LastIterPercent = percent; + m_ProgressTimer.Tic(); + } + } + } + } + else + { + b = false; + m_ErrorReport.push_back(loc); + } + + //t2.Toc(__FUNCTION__); + return b; +} + +/// +/// Run the log scale filter. +/// +/// True if success, else false. +template +eRenderStatus RendererCL::RunLogScaleFilter() +{ + //Timing t(4); + bool b = true; + int kernelIndex = m_Wrapper.FindKernelIndex(m_DEOpenCLKernelCreator.LogScaleAssignDEEntryPoint()); + const char* loc = __FUNCTION__; + eRenderStatus status = RENDER_OK; + + if (kernelIndex != -1) + { + m_DensityFilterCL = ConvertDensityFilter(); + uint argIndex = 0; + uint blockW = m_WarpSize; + uint blockH = 4;//A height of 4 seems to run the fastest. + uint gridW = m_DensityFilterCL.m_SuperRasW; + uint gridH = m_DensityFilterCL.m_SuperRasH; + + OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); + + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DEFilterParamsBufferName, (void*)&m_DensityFilterCL, sizeof(m_DensityFilterCL)))) { m_ErrorReport.push_back(loc); } + + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_HistBufferName))) { m_ErrorReport.push_back(loc); }//Histogram. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_AccumBufferName))) { m_ErrorReport.push_back(loc); }//Accumulator. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, m_DEFilterParamsBufferName))) { m_ErrorReport.push_back(loc); }//DensityFilterCL. + + //t.Tic(); + if (b && !(b = m_Wrapper.RunKernel(kernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } + //t.Toc(loc); + } + else + { + b = false; + m_ErrorReport.push_back(loc); + } + + if (b && m_Callback) + m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, 100.0, 1, 0.0); + + return b ? RENDER_OK : RENDER_ERROR; +} + +/// +/// Run the Gaussian density filter. +/// Method 7: Each block processes a 32x32 block and exits. No column or row advancements happen. +/// +/// True if success and not aborted, else false. +template +eRenderStatus RendererCL::RunDensityFilter() +{ + bool b = true; + Timing t(4);// , t2(4); + m_DensityFilterCL = ConvertDensityFilter(); + int kernelIndex = MakeAndGetDensityFilterProgram(Supersample(), m_DensityFilterCL.m_FilterWidth); + const char* loc = __FUNCTION__; + + if (kernelIndex != -1) + { + uint leftBound = m_DensityFilterCL.m_Supersample - 1; + uint rightBound = m_DensityFilterCL.m_SuperRasW - (m_DensityFilterCL.m_Supersample - 1); + uint topBound = leftBound; + uint botBound = m_DensityFilterCL.m_SuperRasH - (m_DensityFilterCL.m_Supersample - 1); + uint gridW = rightBound - leftBound; + uint gridH = botBound - topBound; + uint blockSizeW = m_MaxDEBlockSizeW;//These *must* both be divisible by 16 or else pixels will go missing. + uint blockSizeH = m_MaxDEBlockSizeH; + + //OpenCL runs out of resources when using double or a supersample of 2. + //Remedy this by reducing the height of the block by 2. + if (m_DoublePrecision || m_DensityFilterCL.m_Supersample > 1) + blockSizeH -= 2; + + //Can't just blindly pass in vals. Must adjust them first to evenly divide the block count + //into the total grid dimensions. + OpenCLWrapper::MakeEvenGridDims(blockSizeW, blockSizeH, gridW, gridH); + + //t.Tic(); + //The classic problem with performing DE on adjacent pixels is that the filter will overlap. + //This can be solved in 2 ways. One is to use atomics, which is unacceptably slow. + //The other is to proces the entire image in multiple passes, and each pass processes blocks of pixels + //that are far enough apart such that their filters do not overlap. + //Do the latter. + //Gap is in terms of blocks. How many blocks must separate two blocks running at the same time. + uint gapW = (uint)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)blockSizeW); + uint chunkSizeW = gapW + 1; + uint gapH = (uint)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)blockSizeH); + uint chunkSizeH = gapH + 1; + double totalChunks = chunkSizeW * chunkSizeH; + + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_DEFilterParamsBufferName, (void*)&m_DensityFilterCL, sizeof(m_DensityFilterCL)))) { m_ErrorReport.push_back(loc); } + +#ifdef ROW_ONLY_DE + blockSizeW = 64;//These *must* both be divisible by 16 or else pixels will go missing. + blockSizeH = 1; + gapW = (uint)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)blockSizeW); + chunkSizeW = gapW + 1; + gapH = (uint)ceil((m_DensityFilterCL.m_FilterWidth * 2.0) / (double)32);//Block height is 1, but iterates over 32 rows. + chunkSizeH = gapH + 1; + totalChunks = chunkSizeW * chunkSizeH; + + OpenCLWrapper::MakeEvenGridDims(blockSizeW, blockSizeH, gridW, gridH); + gridW /= chunkSizeW; + gridH /= chunkSizeH; + + for (uint rowChunk = 0; b && !m_Abort && rowChunk < chunkSizeH; rowChunk++) + { + for (uint colChunk = 0; b && !m_Abort && colChunk < chunkSizeW; colChunk++) + { + //t2.Tic(); + if (b && !(b = RunDensityFilterPrivate(kernelIndex, gridW, gridH, blockSizeW, blockSizeH, chunkSizeW, chunkSizeH, colChunk, rowChunk))) { m_Abort = true; m_ErrorReport.push_back(loc); } + //t2.Toc(loc); + + if (b && m_Callback) + { + double percent = (double((rowChunk * chunkSizeW) + (colChunk + 1)) / totalChunks) * 100.0; + double etaMs = ((100.0 - percent) / percent) * t.Toc(); + + if (!m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, percent, 1, etaMs)) + Abort(); + } + } + } +#else + gridW /= chunkSizeW; + gridH /= chunkSizeH; + OpenCLWrapper::MakeEvenGridDims(blockSizeW, blockSizeH, gridW, gridH); + + for (uint rowChunk = 0; b && !m_Abort && rowChunk < chunkSizeH; rowChunk++) + { + for (uint colChunk = 0; b && !m_Abort && colChunk < chunkSizeW; colChunk++) + { + //t2.Tic(); + if (b && !(b = RunDensityFilterPrivate(kernelIndex, gridW, gridH, blockSizeW, blockSizeH, chunkSizeW, chunkSizeH, colChunk, rowChunk))) { m_Abort = true; m_ErrorReport.push_back(loc); } + //t2.Toc(loc); + + if (b && m_Callback) + { + double percent = (double((rowChunk * chunkSizeW) + (colChunk + 1)) / totalChunks) * 100.0; + double etaMs = ((100.0 - percent) / percent) * t.Toc(); + + if (!m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, percent, 1, etaMs)) + Abort(); + } + } + } +#endif + + if (b && m_Callback) + m_Callback->ProgressFunc(m_Ember, m_ProgressParameter, 100.0, 1, 0.0); + + //t2.Toc(__FUNCTION__ " all passes"); + } + else + { + b = false; + m_ErrorReport.push_back(loc); + } + + return m_Abort ? RENDER_ABORT : (b ? RENDER_OK : RENDER_ERROR); +} + +/// +/// Run final accumulation to the 2D output image. +/// +/// True if success and not aborted, else false. +template +eRenderStatus RendererCL::RunFinalAccum() +{ + //Timing t(4); + bool b = true; + T alphaBase; + T alphaScale; + int accumKernelIndex = MakeAndGetFinalAccumProgram(alphaBase, alphaScale); + uint argIndex; + uint gridW; + uint gridH; + uint blockW; + uint blockH; + const char* loc = __FUNCTION__; + + if (!m_Abort && accumKernelIndex != -1) + { + //This is needed with or without early clip. + m_SpatialFilterCL = ConvertSpatialFilter(); + + if (b && !(b = m_Wrapper.AddAndWriteBuffer(m_SpatialFilterParamsBufferName, (void*)&m_SpatialFilterCL, sizeof(m_SpatialFilterCL)))) { m_ErrorReport.push_back(loc); } + + //Since early clip requires gamma correcting the entire accumulator first, + //it can't be done inside of the normal final accumulation kernel, so + //an additional kernel must be launched first. + if (b && EarlyClip()) + { + int gammaCorrectKernelIndex = MakeAndGetGammaCorrectionProgram(); + + if (gammaCorrectKernelIndex != -1) + { + argIndex = 0; + blockW = m_WarpSize; + blockH = 4;//A height of 4 seems to run the fastest. + gridW = m_SpatialFilterCL.m_SuperRasW;//Using super dimensions because this processes the density filtering bufer. + gridH = m_SpatialFilterCL.m_SuperRasH; + OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); + + if (b && !(b = m_Wrapper.SetBufferArg(gammaCorrectKernelIndex, argIndex++, m_AccumBufferName))) { m_ErrorReport.push_back(loc); }//Accumulator. + if (b && !(b = m_Wrapper.SetBufferArg(gammaCorrectKernelIndex, argIndex++, m_SpatialFilterParamsBufferName))) { m_ErrorReport.push_back(loc); }//SpatialFilterCL. + + if (b && !(b = m_Wrapper.RunKernel(gammaCorrectKernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } + } + else + { + b = false; + m_ErrorReport.push_back(loc); + } + } + + argIndex = 0; + blockW = m_WarpSize; + blockH = 4;//A height of 4 seems to run the fastest. + gridW = m_SpatialFilterCL.m_FinalRasW; + gridH = m_SpatialFilterCL.m_FinalRasH; + OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); + + if (b && !(b = m_Wrapper.SetBufferArg(accumKernelIndex, argIndex++, m_AccumBufferName))) { m_ErrorReport.push_back(loc); }//Accumulator. + if (b && !(b = m_Wrapper.SetImageArg (accumKernelIndex, argIndex++, m_Wrapper.Shared(), m_FinalImageName))) { m_ErrorReport.push_back(loc); }//Final image. + if (b && !(b = m_Wrapper.SetBufferArg(accumKernelIndex, argIndex++, m_SpatialFilterParamsBufferName))) { m_ErrorReport.push_back(loc); }//SpatialFilterCL. + if (b && !(b = m_Wrapper.SetBufferArg(accumKernelIndex, argIndex++, m_SpatialFilterCoefsBufferName))) { m_ErrorReport.push_back(loc); }//Filter coefs. + if (b && !(b = m_Wrapper.SetArg (accumKernelIndex, argIndex++, alphaBase))) { m_ErrorReport.push_back(loc); }//Alpha base. + if (b && !(b = m_Wrapper.SetArg (accumKernelIndex, argIndex++, alphaScale))) { m_ErrorReport.push_back(loc); }//Alpha scale. + + if (b && m_Wrapper.Shared()) + if (b && !(b = m_Wrapper.EnqueueAcquireGLObjects(m_FinalImageName))) { m_ErrorReport.push_back(loc); } + + if (b && !(b = m_Wrapper.RunKernel(accumKernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } + + if (b && m_Wrapper.Shared()) + if (b && !(b = m_Wrapper.EnqueueReleaseGLObjects(m_FinalImageName))) { m_ErrorReport.push_back(loc); } + + //t.Toc((char*)loc); + } + else + { + b = false; + m_ErrorReport.push_back(loc); + } + + return b ? RENDER_OK : RENDER_ERROR; +} + +/// +/// Zeroize a buffer of the specified size. +/// +/// Name of the buffer to clear +/// Width in elements +/// Height in elements +/// Size of each element +/// True if success, else false. +template +bool RendererCL::ClearBuffer(const string& bufferName, uint width, uint height, uint elementSize) +{ + bool b = true; + int kernelIndex = m_Wrapper.FindKernelIndex(m_IterOpenCLKernelCreator.ZeroizeEntryPoint()); + uint argIndex = 0; + const char* loc = __FUNCTION__; + + if (kernelIndex != -1) + { + uint blockW = m_NVidia ? 32 : 16;//Max work group size is 256 on AMD, which means 16x16. + uint blockH = m_NVidia ? 32 : 16; + uint gridW = width * elementSize; + uint gridH = height; + + OpenCLWrapper::MakeEvenGridDims(blockW, blockH, gridW, gridH); + + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex++, bufferName))) { m_ErrorReport.push_back(loc); }//Buffer of byte. + if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, width * elementSize))) { m_ErrorReport.push_back(loc); }//Width. + if (b && !(b = m_Wrapper.SetArg (kernelIndex, argIndex++, height))) { m_ErrorReport.push_back(loc); }//Height. + if (b && !(b = m_Wrapper.RunKernel(kernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); } + } + else + { + b = false; + m_ErrorReport.push_back(loc); + } + + return b; +} + +/// +/// Private wrapper around calling Gaussian density filtering kernel. +/// The parameters are very specific to how the kernel is internally implemented. +/// +/// Index of the kernel to call +/// Grid width +/// Grid height +/// Block width +/// Block height +/// Chunk size width (gapW + 1) +/// Chunk size height (gapH + 1) +/// Row parity +/// Column parity +/// True if success, else false. +template +bool RendererCL::RunDensityFilterPrivate(uint kernelIndex, uint gridW, uint gridH, uint blockW, uint blockH, uint chunkSizeW, uint chunkSizeH, uint chunkW, uint chunkH) +{ + //Timing t(4); + bool b = true; + uint argIndex = 0; + const char* loc = __FUNCTION__; + + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_HistBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Histogram. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_AccumBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Accumulator. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DEFilterParamsBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//FlameDensityFilterCL. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DECoefsBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Coefs. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DEWidthsBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Widths. + if (b && !(b = m_Wrapper.SetBufferArg(kernelIndex, argIndex, m_DECoefIndicesBufferName))) { m_ErrorReport.push_back(loc); } argIndex++;//Coef indices. + if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkSizeW))) { m_ErrorReport.push_back(loc); } argIndex++;//Chunk size width (gapW + 1). + if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkSizeH))) { m_ErrorReport.push_back(loc); } argIndex++;//Chunk size height (gapH + 1). + if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkW))) { m_ErrorReport.push_back(loc); } argIndex++;//Column chunk. + if (b && !(b = m_Wrapper.SetArg( kernelIndex, argIndex, chunkH))) { m_ErrorReport.push_back(loc); } argIndex++;//Row chunk. + //t.Toc(__FUNCTION__ " set args"); + + //t.Tic(); + if (b && !(b = m_Wrapper.RunKernel(kernelIndex, gridW, gridH, 1, blockW, blockH, 1))) { m_ErrorReport.push_back(loc); }//Method 7, accumulating to temp box area. + //t.Toc(__FUNCTION__ " RunKernel()"); + + return b; +} + +/// +/// Make the Gaussian density filter program and return its index. +/// +/// The supersample being used for the current ember +/// Width of the gaussian filter +/// The kernel index if successful, else -1. +template +int RendererCL::MakeAndGetDensityFilterProgram(size_t ss, uint filterWidth) +{ + string deEntryPoint = m_DEOpenCLKernelCreator.GaussianDEEntryPoint(ss, filterWidth); + int kernelIndex = m_Wrapper.FindKernelIndex(deEntryPoint); + const char* loc = __FUNCTION__; + + if (kernelIndex == -1)//Has not been built yet. + { + string kernel = m_DEOpenCLKernelCreator.GaussianDEKernel(ss, filterWidth); + bool b = m_Wrapper.AddProgram(deEntryPoint, kernel, deEntryPoint, m_DoublePrecision); + + if (b) + { + kernelIndex = m_Wrapper.FindKernelIndex(deEntryPoint);//Try to find it again, it will be present if successfully built. + } + else + { + m_ErrorReport.push_back(string(loc) + "():\nBuilding the following program failed: \n" + kernel + "\n"); + //cout << m_ErrorReport.back(); + } + } + + return kernelIndex; +} + +/// +/// Make the final accumulation program and return its index. +/// There are many different kernels for final accum, depending on early clip, alpha channel, and transparency. +/// Loading all of these in the beginning is too much, so only load the one for the current case being worked with. +/// +/// Storage for the alpha base value used in the kernel. 0 if transparency is true, else 255. +/// Storage for the alpha scale value used in the kernel. 255 if transparency is true, else 0. +/// The kernel index if successful, else -1. +template +int RendererCL::MakeAndGetFinalAccumProgram(T& alphaBase, T& alphaScale) +{ + string finalAccumEntryPoint = m_FinalAccumOpenCLKernelCreator.FinalAccumEntryPoint(EarlyClip(), Renderer::NumChannels(), Transparency(), alphaBase, alphaScale); + int kernelIndex = m_Wrapper.FindKernelIndex(finalAccumEntryPoint); + const char* loc = __FUNCTION__; + + if (kernelIndex == -1)//Has not been built yet. + { + string kernel = m_FinalAccumOpenCLKernelCreator.FinalAccumKernel(EarlyClip(), Renderer::NumChannels(), Transparency()); + bool b = m_Wrapper.AddProgram(finalAccumEntryPoint, kernel, finalAccumEntryPoint, m_DoublePrecision); + + if (b) + kernelIndex = m_Wrapper.FindKernelIndex(finalAccumEntryPoint);//Try to find it again, it will be present if successfully built. + else + m_ErrorReport.push_back(loc); + } + + return kernelIndex; +} + +/// +/// Make the gamma correction program for early clipping and return its index. +/// +/// The kernel index if successful, else -1. +template +int RendererCL::MakeAndGetGammaCorrectionProgram() +{ + string gammaEntryPoint = m_FinalAccumOpenCLKernelCreator.GammaCorrectionEntryPoint(Renderer::NumChannels(), Transparency()); + int kernelIndex = m_Wrapper.FindKernelIndex(gammaEntryPoint); + const char* loc = __FUNCTION__; + + if (kernelIndex == -1)//Has not been built yet. + { + string kernel = m_FinalAccumOpenCLKernelCreator.GammaCorrectionKernel(Renderer::NumChannels(), Transparency()); + bool b = m_Wrapper.AddProgram(gammaEntryPoint, kernel, gammaEntryPoint, m_DoublePrecision); + + if (b) + kernelIndex = m_Wrapper.FindKernelIndex(gammaEntryPoint);//Try to find it again, it will be present if successfully built. + else + m_ErrorReport.push_back(loc); + } + + return kernelIndex; +} + +/// +/// Private functions passing data to OpenCL programs. +/// + +/// +/// Convert the currently used host side DensityFilter object into a DensityFilterCL object +/// for passing to OpenCL. +/// +/// The DensityFilterCL object +template +DensityFilterCL RendererCL::ConvertDensityFilter() +{ + DensityFilterCL filterCL; + DensityFilter* densityFilter = dynamic_cast*>(GetDensityFilter()); + + filterCL.m_Supersample = (uint)Supersample(); + filterCL.m_SuperRasW = (uint)SuperRasW(); + filterCL.m_SuperRasH = (uint)SuperRasH(); + filterCL.m_K1 = K1(); + filterCL.m_K2 = K2(); + + if (densityFilter) + { + filterCL.m_Curve = densityFilter->Curve(); + filterCL.m_KernelSize = (uint)densityFilter->KernelSize(); + filterCL.m_MaxFilterIndex = (uint)densityFilter->MaxFilterIndex(); + filterCL.m_MaxFilteredCounts = (uint)densityFilter->MaxFilteredCounts(); + filterCL.m_FilterWidth = (uint)densityFilter->FilterWidth(); + } + + return filterCL; +} + +/// +/// Convert the currently used host side SpatialFilter object into a SpatialFilterCL object +/// for passing to OpenCL. +/// +/// The SpatialFilterCL object +template +SpatialFilterCL RendererCL::ConvertSpatialFilter() +{ + T g, linRange, vibrancy; + Color background; + SpatialFilterCL filterCL; + + this->PrepFinalAccumVals(background, g, linRange, vibrancy); + + filterCL.m_SuperRasW = (uint)SuperRasW(); + filterCL.m_SuperRasH = (uint)SuperRasH(); + filterCL.m_FinalRasW = (uint)FinalRasW(); + filterCL.m_FinalRasH = (uint)FinalRasH(); + filterCL.m_Supersample = (uint)Supersample(); + filterCL.m_FilterWidth = (uint)GetSpatialFilter()->FinalFilterWidth(); + filterCL.m_NumChannels = (uint)Renderer::NumChannels(); + filterCL.m_BytesPerChannel = (uint)BytesPerChannel(); + filterCL.m_DensityFilterOffset = (uint)DensityFilterOffset(); + filterCL.m_Transparency = Transparency(); + filterCL.m_YAxisUp = (uint)m_YAxisUp; + filterCL.m_Vibrancy = vibrancy; + filterCL.m_HighlightPower = HighlightPower(); + filterCL.m_Gamma = g; + filterCL.m_LinRange = linRange; + filterCL.m_Background = background; + + return filterCL; +} + +/// +/// Convert the host side Ember object into an EmberCL object +/// and a vector of XformCL for passing to OpenCL. +/// +/// The Ember object to convert +/// The converted EmberCL +/// The converted vector of XformCL +template +void RendererCL::ConvertEmber(Ember& ember, EmberCL& emberCL, vector>& xformsCL) +{ + memset(&emberCL, 0, sizeof(EmberCL));//Might not really be needed. + + emberCL.m_RotA = m_RotMat.A(); + emberCL.m_RotB = m_RotMat.B(); + emberCL.m_RotD = m_RotMat.D(); + emberCL.m_RotE = m_RotMat.E(); + emberCL.m_CamMat = ember.m_CamMat; + emberCL.m_CenterX = CenterX(); + emberCL.m_CenterY = ember.m_RotCenterY; + emberCL.m_CamZPos = ember.m_CamZPos; + emberCL.m_CamPerspective = ember.m_CamPerspective; + emberCL.m_CamYaw = ember.m_CamYaw; + emberCL.m_CamPitch = ember.m_CamPitch; + emberCL.m_CamDepthBlur = ember.m_CamDepthBlur; + emberCL.m_BlurCoef = ember.BlurCoef(); + + for (uint i = 0; i < ember.TotalXformCount() && i < xformsCL.size(); i++) + { + Xform* xform = ember.GetTotalXform(i); + + xformsCL[i].m_A = xform->m_Affine.A(); + xformsCL[i].m_B = xform->m_Affine.B(); + xformsCL[i].m_C = xform->m_Affine.C(); + xformsCL[i].m_D = xform->m_Affine.D(); + xformsCL[i].m_E = xform->m_Affine.E(); + xformsCL[i].m_F = xform->m_Affine.F(); + + xformsCL[i].m_PostA = xform->m_Post.A(); + xformsCL[i].m_PostB = xform->m_Post.B(); + xformsCL[i].m_PostC = xform->m_Post.C(); + xformsCL[i].m_PostD = xform->m_Post.D(); + xformsCL[i].m_PostE = xform->m_Post.E(); + xformsCL[i].m_PostF = xform->m_Post.F(); + + xformsCL[i].m_DirectColor = xform->m_DirectColor; + xformsCL[i].m_ColorSpeedCache = xform->ColorSpeedCache(); + xformsCL[i].m_OneMinusColorCache = xform->OneMinusColorCache(); + xformsCL[i].m_Opacity = xform->m_Opacity; + xformsCL[i].m_VizAdjusted = xform->VizAdjusted(); + + for (uint varIndex = 0; varIndex < xform->TotalVariationCount() && varIndex < MAX_CL_VARS; varIndex++)//Assign all variation weights for this xform, with a max of MAX_CL_VARS. + xformsCL[i].m_VariationWeights[varIndex] = xform->GetVariation(varIndex)->m_Weight; + } +} + +/// +/// Convert the host side CarToRas object into a CarToRasCL object +/// for passing to OpenCL. +/// +/// The CarToRas object to convert +/// The CarToRasCL object +template +CarToRasCL RendererCL::ConvertCarToRas(const CarToRas& carToRas) +{ + CarToRasCL carToRasCL; + + carToRasCL.m_RasWidth = (uint)carToRas.RasWidth(); + carToRasCL.m_PixPerImageUnitW = carToRas.PixPerImageUnitW(); + carToRasCL.m_RasLlX = carToRas.RasLlX(); + carToRasCL.m_PixPerImageUnitH = carToRas.PixPerImageUnitH(); + carToRasCL.m_RasLlY = carToRas.RasLlY(); + carToRasCL.m_CarLlX = carToRas.CarLlX(); + carToRasCL.m_CarLlY = carToRas.CarLlY(); + carToRasCL.m_CarUrX = carToRas.CarUrX(); + carToRasCL.m_CarUrY = carToRas.CarUrY(); + + return carToRasCL; +} + +/// +/// Fill seeds buffer which gets passed to the iteration kernel. +/// Note, WriteBuffer() must be called after this to actually copy the +/// data from the host to the device. +/// +template +void RendererCL::FillSeeds() +{ + m_Seeds.resize(IterGridKernelCount()); + + for (size_t i = 0; i < m_Seeds.size(); i++) + { + m_Seeds[i].x = m_Rand[0].Rand(); + m_Seeds[i].y = m_Rand[0].Rand(); + } +} + +template EMBERCL_API class RendererCL; + +#ifdef DO_DOUBLE + template EMBERCL_API class RendererCL; +#endif +} diff --git a/Source/EmberCL/RendererCL.h b/Source/EmberCL/RendererCL.h index f168c89..5c072da 100644 --- a/Source/EmberCL/RendererCL.h +++ b/Source/EmberCL/RendererCL.h @@ -19,7 +19,7 @@ class EMBERCL_API RendererCLBase { public: virtual ~RendererCLBase() { } - virtual bool ReadFinal(unsigned char* pixels) = 0; + virtual bool ReadFinal(byte* pixels) = 0; virtual bool ClearFinal() = 0; }; @@ -54,35 +54,35 @@ using EmberNs::Renderer::m_RotMat; using EmberNs::Renderer::m_Ember; public: - RendererCL(unsigned int platform = 0, unsigned int device = 0, bool shared = false, GLuint outputTexID = 0); + RendererCL(uint platform = 0, uint device = 0, bool shared = false, GLuint outputTexID = 0); ~RendererCL(); //Non-virtual member functions for OpenCL specific tasks. - bool Init(unsigned int platform, unsigned int device, bool shared, GLuint outputTexID); + bool Init(uint platform, uint device, bool shared, GLuint outputTexID); bool SetOutputTexture(GLuint outputTexID); //Iters per kernel/block/grid. - inline unsigned int IterCountPerKernel() const; - inline unsigned int IterCountPerBlock() const; - inline unsigned int IterCountPerGrid() const; + inline uint IterCountPerKernel() const; + inline uint IterCountPerBlock() const; + inline uint IterCountPerGrid() const; //Kernels per block. - inline unsigned int IterBlockKernelWidth() const; - inline unsigned int IterBlockKernelHeight() const; - inline unsigned int IterBlockKernelCount() const; + inline uint IterBlockKernelWidth() const; + inline uint IterBlockKernelHeight() const; + inline uint IterBlockKernelCount() const; //Kernels per grid. - inline unsigned int IterGridKernelWidth() const; - inline unsigned int IterGridKernelHeight() const; - inline unsigned int IterGridKernelCount() const; + inline uint IterGridKernelWidth() const; + inline uint IterGridKernelHeight() const; + inline uint IterGridKernelCount() const; //Blocks per grid. - inline unsigned int IterGridBlockWidth() const; - inline unsigned int IterGridBlockHeight() const; - inline unsigned int IterGridBlockCount() const; + inline uint IterGridBlockWidth() const; + inline uint IterGridBlockHeight() const; + inline uint IterGridBlockCount() const; - unsigned int PlatformIndex(); - unsigned int DeviceIndex(); + uint PlatformIndex(); + uint DeviceIndex(); bool ReadHist(); bool ReadAccum(); bool ReadPoints(vector>& vec); @@ -95,7 +95,7 @@ public: string IterKernel(); //Virtual functions overridden from RendererCLBase. - virtual bool ReadFinal(unsigned char* pixels); + virtual bool ReadFinal(byte* pixels); virtual bool ClearFinal(); //Public virtual functions overridden from Renderer or RendererBase. @@ -122,7 +122,7 @@ protected: 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 eRenderStatus AccumulatorToFinalImage(byte* pixels, size_t finalOffset) override; virtual EmberStats Iterate(size_t iterCount, size_t temporalSample) override; private: @@ -132,9 +132,9 @@ private: eRenderStatus RunLogScaleFilter(); eRenderStatus RunDensityFilter(); eRenderStatus RunFinalAccum(); - bool ClearBuffer(const string& bufferName, unsigned int width, unsigned int height, unsigned int elementSize); - 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 chunkW, unsigned int chunkH); - int MakeAndGetDensityFilterProgram(size_t ss, unsigned int filterWidth); + bool ClearBuffer(const string& bufferName, uint width, uint height, uint elementSize); + bool RunDensityFilterPrivate(uint kernelIndex, uint gridW, uint gridH, uint blockW, uint blockH, uint chunkSizeW, uint chunkSizeH, uint chunkW, uint chunkH); + int MakeAndGetDensityFilterProgram(size_t ss, uint filterWidth); int MakeAndGetFinalAccumProgram(T& alphaBase, T& alphaScale); int MakeAndGetGammaCorrectionProgram(); void FillSeeds(); @@ -148,12 +148,12 @@ private: bool m_Init; bool m_NVidia; bool m_DoublePrecision; - unsigned int m_IterCountPerKernel; - unsigned int m_IterBlocksWide, m_IterBlockWidth; - unsigned int m_IterBlocksHigh, m_IterBlockHeight; - unsigned int m_MaxDEBlockSizeW; - unsigned int m_MaxDEBlockSizeH; - unsigned int m_WarpSize; + uint m_IterCountPerKernel; + uint m_IterBlocksWide, m_IterBlockWidth; + uint m_IterBlocksHigh, m_IterBlockHeight; + uint m_MaxDEBlockSizeW; + uint m_MaxDEBlockSizeH; + uint m_WarpSize; size_t m_Calls; //Buffer names. diff --git a/Source/EmberCommon/EmberCommon.h b/Source/EmberCommon/EmberCommon.h index b6788ab..0eea695 100644 --- a/Source/EmberCommon/EmberCommon.h +++ b/Source/EmberCommon/EmberCommon.h @@ -129,11 +129,11 @@ static bool InitPaletteList(const string& filename) /// The RGB buffer /// The width of the image in pixels /// The height of the image in pixels -static void RgbaToRgb(vector& rgba, vector& rgb, size_t width, size_t height) +static void RgbaToRgb(vector& rgba, vector& rgb, size_t width, size_t height) { rgb.resize(width * height * 3); - for (unsigned int i = 0, j = 0; i < (width * height * 4); i += 4, j += 3) + for (uint i = 0, j = 0; i < (width * height * 4); i += 4, j += 3) { rgb[j] = rgba[i]; rgb[j + 1] = rgba[i + 1]; @@ -149,9 +149,9 @@ static void RgbaToRgb(vector& rgba, vector& rgb, s /// Amount of memory available on the system /// The maximum amount of memory to use. Use max if 0. /// The number of strips to use -static unsigned int CalcStrips(double memRequired, double memAvailable, double useMem) +static uint CalcStrips(double memRequired, double memAvailable, double useMem) { - unsigned int strips; + uint strips; if (useMem > 0) memAvailable = useMem; @@ -161,7 +161,7 @@ static unsigned int CalcStrips(double memRequired, double memAvailable, double u if (memAvailable >= memRequired) return 1; - strips = (unsigned int)ceil(memRequired / memAvailable); + strips = (uint)ceil(memRequired / memAvailable); return strips; } @@ -239,7 +239,7 @@ static T NextLowestEvenDiv(T numerator, T denominator) /// The error report for holding errors if anything goes wrong /// A pointer to the created renderer if successful, else false. template -static Renderer* CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared, GLuint texId, EmberReport& errorReport) +static Renderer* CreateRenderer(eRendererType renderType, uint platform, uint device, bool shared, GLuint texId, EmberReport& errorReport) { string s; unique_ptr> renderer; @@ -275,7 +275,7 @@ static Renderer* CreateRenderer(eRendererType renderType, unsigned i } template -static bool StripsRender(RendererBase* renderer, Ember& ember, vector& finalImage, double time, size_t strips, bool yAxisUp, +static bool StripsRender(RendererBase* renderer, Ember& ember, vector& finalImage, double time, size_t strips, bool yAxisUp, std::function perStripStart, std::function perStripFinish, std::function perStripError, diff --git a/Source/EmberCommon/EmberOptions.h b/Source/EmberCommon/EmberOptions.h index b76b1f7..b72e493 100644 --- a/Source/EmberCommon/EmberOptions.h +++ b/Source/EmberCommon/EmberOptions.h @@ -126,7 +126,7 @@ class EmberOptions; /// /// A single option. -/// Template argument expected to be bool, int, unsigned int, double or string. +/// Template argument expected to be bool, int, uint, double or string. /// template class EmberOptionEntry @@ -217,7 +217,7 @@ private: break //Uint. -#define Eou EmberOptionEntry +#define Eou EmberOptionEntry #define INITUINTOPTION(member, option) \ member = option; \ m_UintArgs.push_back(&member) @@ -431,7 +431,7 @@ public: PARSEINTOPTION(OPT_SYMMETRY, Symmetry);//Int args PARSEINTOPTION(OPT_SHEEP_GEN, SheepGen); PARSEINTOPTION(OPT_SHEEP_ID, SheepId); - PARSEUINTOPTION(OPT_OPENCL_PLATFORM, Platform);//Unsigned int args. + PARSEUINTOPTION(OPT_OPENCL_PLATFORM, Platform);//uint args. PARSEUINTOPTION(OPT_OPENCL_DEVICE, Device); PARSEUINTOPTION(OPT_SEED, Seed); PARSEUINTOPTION(OPT_NTHREADS, ThreadCount); @@ -645,27 +645,27 @@ public: EmberOptionEntry Symmetry;//Value int. EmberOptionEntry SheepGen; EmberOptionEntry SheepId; - EmberOptionEntry Platform;//Value unsigned int. - EmberOptionEntry Device; - EmberOptionEntry Seed; - EmberOptionEntry ThreadCount; - EmberOptionEntry Strips; - EmberOptionEntry Supersample; - EmberOptionEntry BitsPerChannel; - EmberOptionEntry SubBatchSize; - EmberOptionEntry Bits; - EmberOptionEntry PrintEditDepth; - EmberOptionEntry JpegQuality; - EmberOptionEntry FirstFrame; - EmberOptionEntry LastFrame; - EmberOptionEntry Frame; - EmberOptionEntry Time; - EmberOptionEntry Dtime; - EmberOptionEntry Frames; - EmberOptionEntry Loops; - EmberOptionEntry Repeat; - EmberOptionEntry Tries; - EmberOptionEntry MaxXforms; + EmberOptionEntry Platform;//Value uint. + EmberOptionEntry Device; + EmberOptionEntry Seed; + EmberOptionEntry ThreadCount; + EmberOptionEntry Strips; + EmberOptionEntry Supersample; + EmberOptionEntry BitsPerChannel; + EmberOptionEntry SubBatchSize; + EmberOptionEntry Bits; + EmberOptionEntry PrintEditDepth; + EmberOptionEntry JpegQuality; + EmberOptionEntry FirstFrame; + EmberOptionEntry LastFrame; + EmberOptionEntry Frame; + EmberOptionEntry Time; + EmberOptionEntry Dtime; + EmberOptionEntry Frames; + EmberOptionEntry Loops; + EmberOptionEntry Repeat; + EmberOptionEntry Tries; + EmberOptionEntry MaxXforms; EmberOptionEntry SizeScale;//Value double. EmberOptionEntry QualityScale; @@ -711,7 +711,7 @@ public: private: vector*> m_BoolArgs; vector*> m_IntArgs; - vector*> m_UintArgs; + vector*> m_UintArgs; vector*> m_DoubleArgs; vector*> m_StringArgs; }; diff --git a/Source/EmberCommon/JpegUtils.h b/Source/EmberCommon/JpegUtils.h index e3d1b46..1539ed4 100644 --- a/Source/EmberCommon/JpegUtils.h +++ b/Source/EmberCommon/JpegUtils.h @@ -12,7 +12,7 @@ /// Width of the image in pixels /// Height of the image in pixels /// True if success, else false -static bool WritePpm(const char* filename, unsigned char* image, size_t width, size_t height) +static bool WritePpm(const char* filename, byte* image, size_t width, size_t height) { bool b = false; size_t size = width * height * 3; @@ -44,7 +44,7 @@ static bool WritePpm(const char* filename, unsigned char* image, size_t width, s /// Url of the author /// Nickname of the author /// True if success, else false -static bool WriteJpeg(const char* filename, unsigned char* image, size_t width, size_t height, int quality, bool enableComments, EmberImageComments& comments, string id, string url, string nick) +static bool WriteJpeg(const char* filename, byte* image, size_t width, size_t height, int quality, bool enableComments, EmberImageComments& comments, string id, string url, string nick) { bool b = false; FILE* file; @@ -79,36 +79,36 @@ static bool WriteJpeg(const char* filename, unsigned char* image, size_t width, //Write comments to jpeg. if (enableComments) { - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)verString, (int)strlen(verString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)verString, (int)strlen(verString)); if (nick != "") { snprintf_s(nickString, 64, "flam3_nickname: %s", nick.c_str()); - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)nickString, (int)strlen(nickString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)nickString, (int)strlen(nickString)); } if (url != "") { snprintf_s(urlString, 128, "flam3_url: %s", url.c_str()); - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)urlString, (int)strlen(urlString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)urlString, (int)strlen(urlString)); } if (id != "") { snprintf_s(idString, 128, "flam3_id: %s", id.c_str()); - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)idString, (int)strlen(idString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)idString, (int)strlen(idString)); } - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)bvString, (int)strlen(bvString)); - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)niString, (int)strlen(niString)); - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)rtString, (int)strlen(rtString)); - jpeg_write_marker(&info, JPEG_COM, (unsigned char*)genomeString, (int)strlen(genomeString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)bvString, (int)strlen(bvString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)niString, (int)strlen(niString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)rtString, (int)strlen(rtString)); + jpeg_write_marker(&info, JPEG_COM, (byte*)genomeString, (int)strlen(genomeString)); } for (i = 0; i < height; i++) { JSAMPROW row_pointer[1]; - row_pointer[0] = (unsigned char*)image + (3 * width * i); + row_pointer[0] = (byte*)image + (3 * width * i); jpeg_write_scanlines(&info, row_pointer, 1); } @@ -135,7 +135,7 @@ static bool WriteJpeg(const char* filename, unsigned char* image, size_t width, /// Url of the author /// Nickname of the author /// True if success, else false -static bool WritePng(const char* filename, unsigned char* image, size_t width, size_t height, size_t bytesPerChannel, bool enableComments, EmberImageComments& comments, string id, string url, string nick) +static bool WritePng(const char* filename, byte* image, size_t width, size_t height, size_t bytesPerChannel, bool enableComments, EmberImageComments& comments, string id, string url, string nick) { bool b = false; FILE* file; @@ -146,8 +146,8 @@ static bool WritePng(const char* filename, unsigned char* image, size_t width, s png_infop info_ptr; png_text text[PNG_COMMENT_MAX]; size_t i; - unsigned short testbe = 1; - vector rows(height); + uint16 testbe = 1; + vector rows(height); text[0].compression = PNG_TEXT_COMPRESSION_NONE; text[0].key = (png_charp)"flam3_version"; @@ -182,7 +182,7 @@ static bool WritePng(const char* filename, unsigned char* image, size_t width, s text[7].text = (png_charp)comments.m_Genome.c_str(); for (i = 0; i < height; i++) - rows[i] = (unsigned char*)image + i * width * 4 * bytesPerChannel; + rows[i] = (byte*)image + i * width * 4 * bytesPerChannel; png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); info_ptr = png_create_info_struct(png_ptr); @@ -232,7 +232,7 @@ static bool WritePng(const char* filename, unsigned char* image, size_t width, s /// The height. /// The size of the new buffer created /// The converted buffer if successful, else NULL. -static unsigned char* ConvertRGBToBMPBuffer(unsigned char* buffer, size_t width, size_t height, size_t& newSize) +static byte* ConvertRGBToBMPBuffer(byte* buffer, size_t width, size_t height, size_t& newSize) { if (buffer == nullptr || width == 0 || height == 0) return nullptr; @@ -245,7 +245,7 @@ static unsigned char* ConvertRGBToBMPBuffer(unsigned char* buffer, size_t width, size_t psw = scanlinebytes + padding; newSize = height * psw; - unsigned char* newBuf = new unsigned char[newSize]; + byte* newBuf = new byte[newSize]; if (newBuf) { @@ -286,7 +286,7 @@ static unsigned char* ConvertRGBToBMPBuffer(unsigned char* buffer, size_t width, /// Height of the image in pixels /// Padded size, greater than or equal to total image size. /// True if success, else false -static bool SaveBmp(const char* filename, unsigned char* image, size_t width, size_t height, size_t paddedSize) +static bool SaveBmp(const char* filename, byte* image, size_t width, size_t height, size_t paddedSize) { #ifdef WIN32 BITMAPFILEHEADER bmfh; @@ -351,11 +351,11 @@ static bool SaveBmp(const char* filename, unsigned char* image, size_t width, si /// Width of the image in pixels /// Height of the image in pixels /// True if success, else false -static bool WriteBmp(const char* filename, unsigned char* image, size_t width, size_t height) +static bool WriteBmp(const char* filename, byte* image, size_t width, size_t height) { bool b = false; size_t newSize; - unique_ptr bgrBuf(ConvertRGBToBMPBuffer(image, width, height, newSize)); + unique_ptr bgrBuf(ConvertRGBToBMPBuffer(image, width, height, newSize)); if (bgrBuf.get()) b = SaveBmp(filename, bgrBuf.get(), width, height, newSize); diff --git a/Source/EmberCommon/SimpleGlob.h b/Source/EmberCommon/SimpleGlob.h index a9e46bf..dbdc494 100644 --- a/Source/EmberCommon/SimpleGlob.h +++ b/Source/EmberCommon/SimpleGlob.h @@ -176,7 +176,7 @@ enum SG_Error { # endif # define sg_strcmp ::_mbscmp # define sg_strcasecmp ::_mbsicmp -# define SOCHAR_T unsigned char +# define SOCHAR_T byte #else # include # include @@ -309,7 +309,7 @@ struct SimpleGlobBase { SimpleGlobBase() : m_hFind(INVALID_HANDLE_VALUE) { } - int FindFirstFileS(const char * a_pszFileSpec, unsigned int) { + int FindFirstFileS(const char * a_pszFileSpec, uint) { m_hFind = FindFirstFileA(a_pszFileSpec, &m_oFindDataA); if (m_hFind != INVALID_HANDLE_VALUE) { return SG_SUCCESS; @@ -320,7 +320,7 @@ struct SimpleGlobBase } return SG_ERR_FAILURE; } - int FindFirstFileS(const wchar_t * a_pszFileSpec, unsigned int) { + int FindFirstFileS(const wchar_t * a_pszFileSpec, uint) { m_hFind = FindFirstFileW(a_pszFileSpec, &m_oFindDataW); if (m_hFind != INVALID_HANDLE_VALUE) { return SG_SUCCESS; @@ -405,7 +405,7 @@ struct SimpleGlobBase } } - int FindFirstFileS(const char * a_pszFileSpec, unsigned int a_uiFlags) { + int FindFirstFileS(const char * a_pszFileSpec, uint a_uiFlags) { int nFlags = GLOB_MARK | GLOB_NOSORT; if (a_uiFlags & SG_GLOB_ERR) nFlags |= GLOB_ERR; if (a_uiFlags & SG_GLOB_TILDE) nFlags |= GLOB_TILDE; @@ -419,7 +419,7 @@ struct SimpleGlobBase } #if SG_HAVE_ICU - int FindFirstFileS(const UChar * a_pszFileSpec, unsigned int a_uiFlags) { + int FindFirstFileS(const UChar * a_pszFileSpec, uint a_uiFlags) { char buf[PATH_MAX] = { 0 }; UErrorCode status = U_ZERO_ERROR; u_strToUTF8(buf, sizeof(buf), nullptr, a_pszFileSpec, -1, &status); @@ -531,7 +531,7 @@ public: argv[0] ... argv[a_nReservedSlots-1] will be left empty for the caller to fill in. */ - CSimpleGlobTempl(unsigned int a_uiFlags = 0, int a_nReservedSlots = 0); + CSimpleGlobTempl(uint a_uiFlags = 0, int a_nReservedSlots = 0); /*! @brief Deallocate all memory buffers. */ ~CSimpleGlobTempl(); @@ -548,7 +548,7 @@ public: argv[0] ... argv[a_nReservedSlots-1] will be left empty for the caller to fill in. */ - int Init(unsigned int a_uiFlags = 0, int a_nReservedSlots = 0); + int Init(uint a_uiFlags = 0, int a_nReservedSlots = 0); /*! @brief Add a new filespec to the glob. @@ -624,7 +624,7 @@ private: static int fileSortCompare(const void *a1, const void *a2); private: - unsigned int m_uiFlags; + uint m_uiFlags; ARG_ARRAY_TYPE m_nArgArrayType; //!< argv is indexes or pointers SOCHAR ** m_rgpArgs; //!< argv int m_nReservedSlots; //!< # client slots in argv array @@ -642,7 +642,7 @@ private: template CSimpleGlobTempl::CSimpleGlobTempl( - unsigned int a_uiFlags, + uint a_uiFlags, int a_nReservedSlots ) { @@ -664,7 +664,7 @@ CSimpleGlobTempl::~CSimpleGlobTempl() template int CSimpleGlobTempl::Init( - unsigned int a_uiFlags, + uint a_uiFlags, int a_nReservedSlots ) { diff --git a/Source/EmberGenome/EmberGenome.cpp b/Source/EmberGenome/EmberGenome.cpp index ae3c6ad..926c537 100644 --- a/Source/EmberGenome/EmberGenome.cpp +++ b/Source/EmberGenome/EmberGenome.cpp @@ -58,15 +58,15 @@ bool EmberGenome(EmberOptions& opt) //Regular variables. Timing t; bool exactTimeMatch, randomMode, didColor, seqFlag; - unsigned int i, j, i0, i1, rep, val, frame, frameCount, count = 0; - unsigned int ftime, firstFrame, lastFrame; + uint i, j, i0, i1, rep, val, frame, frameCount, count = 0; + uint ftime, firstFrame, lastFrame; size_t n, tot, totb, totw; T avgPix, fractionBlack, fractionWhite, blend, spread, mix0, mix1; string token, filename; ostringstream os, os2; vector> embers, embers2, templateEmbers; vector vars, noVars; - vector finalImage; + vector finalImage; eCrossMode crossMeth; eMutateMode mutMeth; Ember orig, save, selp0, selp1, parent0, parent1; @@ -312,8 +312,8 @@ bool EmberGenome(EmberOptions& opt) embers[i].DeleteMotionElements(); } - firstFrame = (unsigned int)(opt.FirstFrame() == UINT_MAX ? embers[0].m_Time : opt.FirstFrame()); - lastFrame = (unsigned int)(opt.LastFrame() == UINT_MAX ? embers.back().m_Time : opt.LastFrame()); + firstFrame = (uint)(opt.FirstFrame() == UINT_MAX ? embers[0].m_Time : opt.FirstFrame()); + lastFrame = (uint)(opt.LastFrame() == UINT_MAX ? embers.back().m_Time : opt.LastFrame()); if (lastFrame < firstFrame) lastFrame = firstFrame; @@ -326,7 +326,7 @@ bool EmberGenome(EmberOptions& opt) for (i = 0; i < embers.size(); i++) { - if (ftime == (unsigned int)embers[i].m_Time) + if (ftime == (uint)embers[i].m_Time) { interpolated = embers[i]; exactTimeMatch = true; @@ -340,7 +340,7 @@ bool EmberGenome(EmberOptions& opt) for (i = 0; i < embers.size(); i++) { - if (ftime == (unsigned int)(embers[i].m_Time - 1)) + if (ftime == (uint)(embers[i].m_Time - 1)) { exactTimeMatch = true; break; @@ -480,7 +480,7 @@ bool EmberGenome(EmberOptions& opt) oldX = embers[i].m_CenterX; oldY = embers[i].m_CenterY; - embers[i].m_FinalRasH = (unsigned int)((T)embers[i].m_FinalRasH / (T)opt.Frames()); + embers[i].m_FinalRasH = (uint)((T)embers[i].m_FinalRasH / (T)opt.Frames()); embers[i].m_CenterY = embers[i].m_CenterY - ((opt.Frames() - 1) * embers[i].m_FinalRasH) / (2 * embers[i].m_PixelsPerUnit * pow(T(2.0), embers[i].m_Zoom)); diff --git a/Source/EmberRender/EmberRender.cpp b/Source/EmberRender/EmberRender.cpp index 766c17c..192bb6d 100644 --- a/Source/EmberRender/EmberRender.cpp +++ b/Source/EmberRender/EmberRender.cpp @@ -27,7 +27,7 @@ bool EmberRender(EmberOptions& opt) Timing t; bool writeSuccess = false; - unsigned char* finalImagep; + byte* finalImagep; size_t i, channels; size_t strips; size_t iterCount; @@ -35,7 +35,7 @@ bool EmberRender(EmberOptions& opt) string inputPath = GetPath(opt.Input()); ostringstream os; vector> embers; - vector finalImage, vecRgb; + vector finalImage, vecRgb; EmberStats stats; EmberReport emberReport; EmberImageComments comments; @@ -168,8 +168,8 @@ bool EmberRender(EmberOptions& opt) embers[i].m_TemporalSamples = 1;//Force temporal samples to 1 for render. embers[i].m_Quality *= T(opt.QualityScale()); - embers[i].m_FinalRasW = (unsigned int)((T)embers[i].m_FinalRasW * opt.SizeScale()); - embers[i].m_FinalRasH = (unsigned int)((T)embers[i].m_FinalRasH * opt.SizeScale()); + embers[i].m_FinalRasW = (uint)((T)embers[i].m_FinalRasW * opt.SizeScale()); + embers[i].m_FinalRasH = (uint)((T)embers[i].m_FinalRasH * opt.SizeScale()); embers[i].m_PixelsPerUnit *= T(opt.SizeScale()); if (embers[i].m_FinalRasW == 0 || embers[i].m_FinalRasH == 0) diff --git a/Source/EmberTester/EmberTester.cpp b/Source/EmberTester/EmberTester.cpp index 1780ce7..91c90ac 100644 --- a/Source/EmberTester/EmberTester.cpp +++ b/Source/EmberTester/EmberTester.cpp @@ -16,7 +16,7 @@ using namespace EmberNs; //#define TEST_CL 1 template -void SaveFinalImage(Renderer& renderer, vector& pixels, char* suffix) +void SaveFinalImage(Renderer& renderer, vector& pixels, char* suffix) { Timing t; //renderer.AccumulatorToFinalImage(pixels); @@ -31,7 +31,7 @@ void SaveFinalImage(Renderer& renderer, vector& pixels, cha } template -Ember CreateBasicEmber(unsigned int width, unsigned int height, unsigned int ss, T quality, T centerX, T centerY, T rotate) +Ember CreateBasicEmber(uint width, uint height, uint ss, T quality, T centerX, T centerY, T rotate) { Timing t; QTIsaac rand; @@ -69,7 +69,7 @@ Ember CreateBasicEmber(unsigned int width, unsigned int height, unsigned int return ember1; } -string GetEmberCLKernelString(Ember& ember, bool iter, bool log, bool de, unsigned int ss, bool accum) +string GetEmberCLKernelString(Ember& ember, bool iter, bool log, bool de, uint ss, bool accum) { ostringstream os; IterOpenCLKernelCreator iterCreator; @@ -99,7 +99,7 @@ void MakeTestAllVarsRegPrePostComboFile(const string& filename) EmberToXml writer; vector> embers; VariationList varList; - unsigned int index = 0; + uint index = 0; PaletteList paletteList; ostringstream ss; QTIsaac rand; @@ -221,13 +221,13 @@ void TestAtomicAdd() "{\n" " union\n" " {\n" - " unsigned int intVal;\n" + " uint intVal;\n" " float floatVal;\n" " } newVal;\n" "\n" " union\n" " {\n" - " unsigned int intVal;\n" + " uint intVal;\n" " float floatVal;\n" " } prevVal;\n" "\n" @@ -235,15 +235,15 @@ void TestAtomicAdd() " {\n" " prevVal.floatVal = *source;\n" " newVal.floatVal = prevVal.floatVal + operand;\n" - " } while (atomic_cmpxchg((volatile __global unsigned int*)source, prevVal.intVal, newVal.intVal) != prevVal.intVal);\n" + " } while (atomic_cmpxchg((volatile __global uint*)source, prevVal.intVal, newVal.intVal) != prevVal.intVal);\n" "}\n" "\n" "__kernel void MyKernel(\n" " __global float* buff,\n" - " unsigned int lockit\n" + " uint lockit\n" "\t)\n" "{\n" - " unsigned int index = THREAD_ID_X;\n" + " uint index = THREAD_ID_X;\n" "\n" " if (lockit)\n" " {\n" @@ -263,12 +263,12 @@ void TestAtomicAdd() for (i = 0; i < vec.size(); i++) vec[i] = (i * 10.2234f); - if (wrapper.AddAndWriteBuffer("buff", (void*)vec.data(), (unsigned int)vec.size() * sizeof(vec[0]))) + if (wrapper.AddAndWriteBuffer("buff", (void*)vec.data(), (uint)vec.size() * sizeof(vec[0]))) { if (wrapper.AddProgram(entry, program, entry, false)) { wrapper.SetBufferArg(0, 0, 0); - wrapper.SetArg(0, 1, 0); + wrapper.SetArg(0, 1, 0); if (wrapper.RunKernel(0, 32,//Total grid dims. @@ -278,7 +278,7 @@ void TestAtomicAdd() 1, 1)) { - wrapper.ReadBuffer(0, vec.data(), (unsigned int)vec.size() * sizeof(vec[0])); + wrapper.ReadBuffer(0, vec.data(), (uint)vec.size() * sizeof(vec[0])); cout << "Vector after unlocked add: " << endl; for (i = 0; i < vec.size(); i++) @@ -289,9 +289,9 @@ void TestAtomicAdd() for (i = 0; i < vec.size(); i++) vec[i] = (i * 10.2234f); - wrapper.AddAndWriteBuffer("buff", (void*)vec.data(), (unsigned int)vec.size() * sizeof(vec[0])); + wrapper.AddAndWriteBuffer("buff", (void*)vec.data(), (uint)vec.size() * sizeof(vec[0])); wrapper.SetBufferArg(0, 0, 0); - wrapper.SetArg(0, 1, 1); + wrapper.SetArg(0, 1, 1); if (wrapper.RunKernel(0, 32,//Total grid dims. @@ -301,7 +301,7 @@ void TestAtomicAdd() 1, 1)) { - wrapper.ReadBuffer(0, vec.data(), (unsigned int)vec.size() * sizeof(vec[0])); + wrapper.ReadBuffer(0, vec.data(), (uint)vec.size() * sizeof(vec[0])); cout << "\n\nVector after locked add: " << endl; for (i = 0; i < vec.size(); i++) @@ -383,14 +383,14 @@ bool TestVarCounts() #else bool success = true; #endif - unsigned int start = (unsigned int)VAR_ARCH; + uint start = (uint)VAR_ARCH; if (!success) { - cout << "Variation list size " << vlf.Size() << " does not equal the max var ID enum " << (unsigned int)LAST_VAR << "." << endl; + cout << "Variation list size " << vlf.Size() << " does not equal the max var ID enum " << (uint)LAST_VAR << "." << endl; } - for (; start < (unsigned int)LAST_VAR; start++) + for (; start < (uint)LAST_VAR; start++) { Variation* var = vlf.GetVariation((eVariationId)start); @@ -709,7 +709,7 @@ bool TestParVars() names.reserve(parVar->ParamCount()); addresses.reserve(parVar->ParamCount()); - for (unsigned int j = 0; j < parVar->ParamCount(); j++) + for (uint j = 0; j < parVar->ParamCount(); j++) { if (std::find(names.begin(), names.end(), params[j].Name()) != names.end()) { @@ -1123,7 +1123,7 @@ bool TestConstants() void PrintAllVars() { - unsigned int i = 0; + uint i = 0; VariationList vlf; while(Variation* var = vlf.GetVariation(i++)) @@ -1132,7 +1132,7 @@ void PrintAllVars() void TestXformsInOutPoints() { - unsigned int index = 0; + uint index = 0; VariationList varList; PaletteList paletteList; QTIsaac rand; @@ -1417,13 +1417,13 @@ void TestVarsSimilar() if (parVar) { - for (unsigned int v = 0; v < parVar->ParamCount(); v++) + for (uint v = 0; v < parVar->ParamCount(); v++) parVar->SetParamVal(v, (T)iter); } if (parVarComp) { - for (unsigned int v = 0; v < parVarComp->ParamCount(); v++) + for (uint v = 0; v < parVarComp->ParamCount(); v++) parVarComp->SetParamVal(v, (T)iter); } @@ -1620,7 +1620,7 @@ void TestGpuVectorRead() if (!renderer.Alloc()) return; - unsigned int i, iters = renderer.IterCountPerKernel() * renderer.TotalIterKernelCount();//Make each thread in each block run at least once. + uint i, iters = renderer.IterCountPerKernel() * renderer.TotalIterKernelCount();//Make each thread in each block run at least once. renderer.Iterate(iters, 0, 1); renderer.ReadPoints(points); diff --git a/Source/Fractorium/EmberFile.h b/Source/Fractorium/EmberFile.h index caa17ce..cabbc55 100644 --- a/Source/Fractorium/EmberFile.h +++ b/Source/Fractorium/EmberFile.h @@ -144,7 +144,7 @@ public: /// /// The index in the file of the ember /// The default ember name - static QString DefaultEmberName(unsigned int i) + static QString DefaultEmberName(uint i) { return DefaultFilename() + "-" + ToString(i); } diff --git a/Source/Fractorium/EmberTreeWidgetItem.h b/Source/Fractorium/EmberTreeWidgetItem.h index 6a289ce..e68aace 100644 --- a/Source/Fractorium/EmberTreeWidgetItem.h +++ b/Source/Fractorium/EmberTreeWidgetItem.h @@ -40,7 +40,7 @@ public: /// The vector containing the RGB pixels [0..255] which will make up the preview image /// The width of the image in pixels /// The height of the image in pixels - void SetImage(vector& v, unsigned int width, unsigned int height) + void SetImage(vector& v, uint width, uint height) { int size = 64; diff --git a/Source/Fractorium/FinalRenderDialog.cpp b/Source/Fractorium/FinalRenderDialog.cpp index 5e27222..959731d 100644 --- a/Source/Fractorium/FinalRenderDialog.cpp +++ b/Source/Fractorium/FinalRenderDialog.cpp @@ -16,7 +16,7 @@ FractoriumFinalRenderDialog::FractoriumFinalRenderDialog(FractoriumSettings* set ui.setupUi(this); int row = 0, spinHeight = 20; - unsigned int i; + uint i; double dmax = numeric_limits::max(); QTableWidget* table = ui.FinalRenderParamsTable; QTableWidgetItem* item = NULL; @@ -197,16 +197,16 @@ QString FractoriumFinalRenderDialog::Path() { return ui.FinalRenderParamsTable-> void FractoriumFinalRenderDialog::Path(const QString& s) { ui.FinalRenderParamsTable->item(m_PathCellIndex, 1)->setText(s); } QString FractoriumFinalRenderDialog::Prefix() { return m_PrefixEdit->text(); } QString FractoriumFinalRenderDialog::Suffix() { return m_SuffixEdit->text(); } -unsigned int FractoriumFinalRenderDialog::Current() { return ui.FinalRenderCurrentSpin->value(); } -unsigned int FractoriumFinalRenderDialog::PlatformIndex() { return ui.FinalRenderPlatformCombo->currentIndex(); } -unsigned int FractoriumFinalRenderDialog::DeviceIndex() { return ui.FinalRenderDeviceCombo->currentIndex(); } -unsigned int FractoriumFinalRenderDialog::ThreadCount() { return ui.FinalRenderThreadCountSpin->value(); } +uint FractoriumFinalRenderDialog::Current() { return ui.FinalRenderCurrentSpin->value(); } +uint FractoriumFinalRenderDialog::PlatformIndex() { return ui.FinalRenderPlatformCombo->currentIndex(); } +uint FractoriumFinalRenderDialog::DeviceIndex() { return ui.FinalRenderDeviceCombo->currentIndex(); } +uint FractoriumFinalRenderDialog::ThreadCount() { return ui.FinalRenderThreadCountSpin->value(); } double FractoriumFinalRenderDialog::WidthScale() { return m_WidthScaleSpin->value(); } double FractoriumFinalRenderDialog::HeightScale() { return m_HeightScaleSpin->value(); } double FractoriumFinalRenderDialog::Quality() { return m_QualitySpin->value(); } -unsigned int FractoriumFinalRenderDialog::TemporalSamples() { return m_TemporalSamplesSpin->value(); } -unsigned int FractoriumFinalRenderDialog::Supersample() { return m_SupersampleSpin->value(); } -unsigned int FractoriumFinalRenderDialog::Strips() { return m_StripsSpin->value(); } +uint FractoriumFinalRenderDialog::TemporalSamples() { return m_TemporalSamplesSpin->value(); } +uint FractoriumFinalRenderDialog::Supersample() { return m_SupersampleSpin->value(); } +uint FractoriumFinalRenderDialog::Strips() { return m_StripsSpin->value(); } /// /// Capture the current state of the Gui. diff --git a/Source/Fractorium/FinalRenderDialog.h b/Source/Fractorium/FinalRenderDialog.h index 8e473cc..1d9d4fe 100644 --- a/Source/Fractorium/FinalRenderDialog.h +++ b/Source/Fractorium/FinalRenderDialog.h @@ -61,16 +61,16 @@ public: void Path(const QString& s); QString Prefix(); QString Suffix(); - unsigned int Current(); - unsigned int PlatformIndex(); - unsigned int DeviceIndex(); - unsigned int ThreadCount(); + uint Current(); + uint PlatformIndex(); + uint DeviceIndex(); + uint ThreadCount(); double WidthScale(); double HeightScale(); double Quality(); - unsigned int TemporalSamples(); - unsigned int Supersample(); - unsigned int Strips(); + uint TemporalSamples(); + uint Supersample(); + uint Strips(); FinalRenderGuiState State(); public Q_SLOTS: diff --git a/Source/Fractorium/FinalRenderEmberController.cpp b/Source/Fractorium/FinalRenderEmberController.cpp index 680ba4d..54aea94 100644 --- a/Source/Fractorium/FinalRenderEmberController.cpp +++ b/Source/Fractorium/FinalRenderEmberController.cpp @@ -125,7 +125,7 @@ FinalRenderEmberController::FinalRenderEmberController(FractoriumFinalRenderD m_FinalPreviewRenderer->SetEmber(m_PreviewEmber); m_FinalPreviewRenderer->PrepFinalAccumVector(m_PreviewFinalImage);//Must manually call this first because it could be erroneously made smaller due to strips if called inside Renderer::Run(). - unsigned int strips = VerifyStrips(m_PreviewEmber.m_FinalRasH, m_FinalRenderDialog->Strips(), + uint strips = VerifyStrips(m_PreviewEmber.m_FinalRasH, m_FinalRenderDialog->Strips(), [&](const string& s) { }, [&](const string& s) { }, [&](const string& s) { }); StripsRender(m_FinalPreviewRenderer.get(), m_PreviewEmber, m_PreviewFinalImage, 0, strips, m_FinalRenderDialog->YAxisUp(), @@ -154,7 +154,7 @@ FinalRenderEmberController::FinalRenderEmberController(FractoriumFinalRenderD size_t i; m_GuiState = m_FinalRenderDialog->State();//Cache render settings from the GUI before running. bool doAll = m_GuiState.m_DoAll && m_EmberFile.Size() > 1; - unsigned int currentStripForProgress = 0;//Sort of a hack to get the strip value to the progress function. + uint currentStripForProgress = 0;//Sort of a hack to get the strip value to the progress function. QString path = doAll ? ComposePath(QString::fromStdString(m_EmberFile.m_Embers[0].m_Name)) : ComposePath(Name()); QString backup = path + "_backup.flame"; @@ -395,11 +395,11 @@ bool FinalRenderEmberController::Render() /// True if shared with OpenGL, else false. Default: true. /// True if nothing went wrong, else false. template -bool FinalRenderEmberController::CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared) +bool FinalRenderEmberController::CreateRenderer(eRendererType renderType, uint platform, uint device, bool shared) { bool ok = true; vector errorReport; - unsigned int channels = m_FinalRenderDialog->Ext() == "png" ? 4 : 3; + uint channels = m_FinalRenderDialog->Ext() == "png" ? 4 : 3; CancelRender(); @@ -464,7 +464,7 @@ template int FinalRenderEmberController::ProgressFunc(Ember& ember, void* foo, double fraction, int stage, double etaMs) { static int count = 0; - unsigned int strip = *((unsigned int*)m_Renderer->m_ProgressParameter); + uint strip = *((uint*)m_Renderer->m_ProgressParameter); double fracPerStrip = ceil(100.0 / m_GuiState.m_Strips); double stripsfrac = ceil(fracPerStrip * strip) + ceil(fraction / m_GuiState.m_Strips); int intFract = (int)stripsfrac; @@ -573,7 +573,7 @@ pair FinalRenderEmberController::SyncAndComputeMemory() if (m_Renderer.get()) { bool b = false; - unsigned int channels = m_FinalRenderDialog->Ext() == "png" ? 4 : 3;//4 channels for Png, else 3. + uint channels = m_FinalRenderDialog->Ext() == "png" ? 4 : 3;//4 channels for Png, else 3. size_t strips = VerifyStrips(m_Ember->m_FinalRasH, m_FinalRenderDialog->Strips(), [&](const string& s) { }, [&](const string& s) { }, [&](const string& s) { }); diff --git a/Source/Fractorium/FinalRenderEmberController.h b/Source/Fractorium/FinalRenderEmberController.h index 06dfec2..35efdd0 100644 --- a/Source/Fractorium/FinalRenderEmberController.h +++ b/Source/Fractorium/FinalRenderEmberController.h @@ -34,15 +34,15 @@ struct FinalRenderGuiState QString m_Ext; QString m_Prefix; QString m_Suffix; - unsigned int m_PlatformIndex; - unsigned int m_DeviceIndex; - unsigned int m_ThreadCount; + uint m_PlatformIndex; + uint m_DeviceIndex; + uint m_ThreadCount; double m_WidthScale; double m_HeightScale; double m_Quality; - unsigned int m_TemporalSamples; - unsigned int m_Supersample; - unsigned int m_Strips; + uint m_TemporalSamples; + uint m_Supersample; + uint m_Strips; }; /// @@ -74,8 +74,8 @@ public: protected: bool m_Run; bool m_PreviewRun; - unsigned int m_ImageCount; - unsigned int m_FinishedImageCount; + uint m_ImageCount; + uint m_FinishedImageCount; QFuture m_Result; QFuture m_FinalPreviewResult; @@ -111,10 +111,10 @@ public: #endif virtual void SetEmber(size_t index) override; virtual bool Render() override; - virtual bool CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared = true) override; + virtual bool CreateRenderer(eRendererType renderType, uint platform, uint device, bool shared = true) override; virtual int ProgressFunc(Ember& ember, void* foo, double fraction, int stage, double etaMs) override; virtual size_t Index() const override { return m_Ember->m_Index; } - virtual unsigned int SizeOfT() const override { return sizeof(T); } + virtual uint SizeOfT() const override { return sizeof(T); } //Virtual functions overridden from FinalRenderEmberControllerBase. virtual void SyncCurrentToGui() override; diff --git a/Source/Fractorium/Fractorium.cpp b/Source/Fractorium/Fractorium.cpp index dc6c307..b42a61a 100644 --- a/Source/Fractorium/Fractorium.cpp +++ b/Source/Fractorium/Fractorium.cpp @@ -15,7 +15,7 @@ Fractorium::Fractorium(QWidget* parent) Timing t; ui.setupUi(this); qRegisterMetaType>("QVector");//For previews. - qRegisterMetaType>("vector"); + qRegisterMetaType>("vector"); qRegisterMetaType("EmberTreeWidgetItemBase*"); m_FontSize = 9; diff --git a/Source/Fractorium/Fractorium.h b/Source/Fractorium/Fractorium.h index bbdfe18..d99ab44 100644 --- a/Source/Fractorium/Fractorium.h +++ b/Source/Fractorium/Fractorium.h @@ -74,7 +74,7 @@ public: void SetCoordinateStatus(int x, int y, float worldX, float worldY); //Xforms. - void CurrentXform(unsigned int i); + void CurrentXform(uint i); //Xforms Affine. bool DrawAllPre(); @@ -236,7 +236,7 @@ public slots: void ShowCritical(const QString& title, const QString& text, bool invokeRequired = false); //Can't have a template function be a slot. - void SetLibraryTreeItemData(EmberTreeWidgetItemBase* item, vector& v, unsigned int width, unsigned int height); + void SetLibraryTreeItemData(EmberTreeWidgetItemBase* item, vector& v, uint width, uint height); public: //template//See below. diff --git a/Source/Fractorium/FractoriumEmberController.cpp b/Source/Fractorium/FractoriumEmberController.cpp index 1be19dc..76b807a 100644 --- a/Source/Fractorium/FractoriumEmberController.cpp +++ b/Source/Fractorium/FractoriumEmberController.cpp @@ -84,7 +84,7 @@ FractoriumEmberController::FractoriumEmberController(Fractorium* fractorium) m_PreviewRenderer->SetEmber(m_Ember);//Give it an initial ember, will be updated many times later. //m_PreviewRenderer->ThreadCount(1);//For debugging. - m_PreviewRenderFunc = [&](unsigned int start, unsigned int end) + m_PreviewRenderFunc = [&](uint start, uint end) { while(m_PreviewRun || m_PreviewRunning) { @@ -117,9 +117,9 @@ FractoriumEmberController::FractoriumEmberController(Fractorium* fractorium) //until the update is complete. QMetaObject::invokeMethod(m_Fractorium, "SetLibraryTreeItemData", Qt::BlockingQueuedConnection, Q_ARG(EmberTreeWidgetItemBase*, (EmberTreeWidgetItemBase*)treeItem), - Q_ARG(vector&, m_PreviewFinalImage), - Q_ARG(unsigned int, PREVIEW_SIZE), - Q_ARG(unsigned int, PREVIEW_SIZE)); + Q_ARG(vector&, m_PreviewFinalImage), + Q_ARG(uint, PREVIEW_SIZE), + Q_ARG(uint, PREVIEW_SIZE)); //treeItem->SetImage(m_PreviewFinalImage, PREVIEW_SIZE, PREVIEW_SIZE); } @@ -189,7 +189,7 @@ void FractoriumEmberController::SetEmber(size_t index) { if (QTreeWidgetItem* top = m_Fractorium->ui.LibraryTree->topLevelItem(0)) { - for (unsigned int i = 0; i < top->childCount(); i++) + for (uint i = 0; i < top->childCount(); i++) { if (EmberTreeWidgetItem* emberItem = dynamic_cast*>(top->child(i))) emberItem->setSelected(i == index); diff --git a/Source/Fractorium/FractoriumEmberController.h b/Source/Fractorium/FractoriumEmberController.h index 3614769..9bfd3df 100644 --- a/Source/Fractorium/FractoriumEmberController.h +++ b/Source/Fractorium/FractoriumEmberController.h @@ -11,7 +11,7 @@ /// /// An enum representing the type of edit being done. /// -enum eEditUndoState : unsigned int { REGULAR_EDIT = 0, UNDO_REDO = 1, EDIT_UNDO = 2 }; +enum eEditUndoState : uint { REGULAR_EDIT = 0, UNDO_REDO = 1, EDIT_UNDO = 2 }; /// /// FractoriumEmberController and Fractorium need each other, but each can't include the other. @@ -66,16 +66,16 @@ public: virtual size_t TotalXformCount() const { return 0; } virtual QString Name() const { return ""; } virtual void Name(const string& s) { } - virtual unsigned int FinalRasW() const { return 0; } - virtual void FinalRasW(unsigned int w) { } - virtual unsigned int FinalRasH() const { return 0; } - virtual void FinalRasH(unsigned int h) { } + virtual uint FinalRasW() const { return 0; } + virtual void FinalRasW(uint w) { } + virtual uint FinalRasH() const { return 0; } + virtual void FinalRasH(uint h) { } virtual size_t Index() const { return 0; } virtual void AddSymmetry(int sym, QTIsaac& rand) { } virtual void CalcNormalizedWeights() { } //Menu. - virtual void NewFlock(unsigned int count) { }//File. + virtual void NewFlock(uint count) { }//File. virtual void NewEmptyFlameInCurrentFile() { } virtual void NewRandomFlameInCurrentFile() { } virtual void CopyFlameInCurrentFile() { } @@ -106,9 +106,9 @@ public: virtual void GammaThresholdChanged(double d) { } virtual void VibrancyChanged(double d) { } virtual void HighlightPowerChanged(double d) { } - virtual void PaletteModeChanged(unsigned int i) { } - virtual void WidthChanged(unsigned int i) { } - virtual void HeightChanged(unsigned int i) { } + virtual void PaletteModeChanged(uint i) { } + virtual void WidthChanged(uint i) { } + virtual void HeightChanged(uint i) { } virtual void CenterXChanged(double d) { } virtual void CenterYChanged(double d) { } virtual void ScaleChanged(double d) { } @@ -164,7 +164,7 @@ public: //Xforms Xaos. virtual void FillXaosWithCurrentXform() { } - virtual QString MakeXaosNameString(unsigned int i) { return ""; } + virtual QString MakeXaosNameString(uint i) { return ""; } virtual void XaosChanged(DoubleSpinBox* sender) { } virtual void ClearXaos() { } virtual void RandomXaos() { } @@ -173,7 +173,7 @@ public: virtual bool InitPaletteTable(const string& s) { return false; } virtual void ApplyPaletteToEmber() { } virtual void PaletteAdjust() { } - virtual QRgb GetQRgbFromPaletteIndex(unsigned int i) { return QRgb(); } + virtual QRgb GetQRgbFromPaletteIndex(uint i) { return QRgb(); } virtual void PaletteCellClicked(int row, int col) { } //Library. @@ -182,15 +182,15 @@ public: virtual void UpdateLibraryTree() { } virtual void EmberTreeItemChanged(QTreeWidgetItem* item, int col) { } virtual void EmberTreeItemDoubleClicked(QTreeWidgetItem* item, int col) { } - virtual void RenderPreviews(unsigned int start = UINT_MAX, unsigned int end = UINT_MAX) { } + virtual void RenderPreviews(uint start = UINT_MAX, uint end = UINT_MAX) { } virtual void StopPreviewRender() { } //Info. //Rendering/progress. virtual bool Render() { return false; } - virtual bool CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared = true) { return false; } - virtual unsigned int SizeOfT() const { return 0; } + virtual bool CreateRenderer(eRendererType renderType, uint platform, uint device, bool shared = true) { return false; } + virtual uint SizeOfT() const { return 0; } virtual void ClearUndo() { } virtual GLEmberControllerBase* GLController() { return NULL; } bool RenderTimerRunning(); @@ -202,8 +202,8 @@ public: void DeleteRenderer(); void SaveCurrentRender(const QString& filename, bool forcePull); RendererBase* Renderer() { return m_Renderer.get(); } - vector* FinalImage() { return &m_FinalImage; } - vector* PreviewFinalImage() { return &m_PreviewFinalImage; } + vector* FinalImage() { return &m_FinalImage; } + vector* PreviewFinalImage() { return &m_PreviewFinalImage; } protected: //Rendering/progress. @@ -215,11 +215,11 @@ protected: bool m_Rendering; bool m_Shared; bool m_LastEditWasUndoRedo; - unsigned int m_Platform; - unsigned int m_Device; - unsigned int m_SubBatchCount; - unsigned int m_FailedRenders; - unsigned int m_UndoIndex; + uint m_Platform; + uint m_Device; + uint m_SubBatchCount; + uint m_FailedRenders; + uint m_UndoIndex; eRendererType m_RenderType; eEditUndoState m_EditState; GLuint m_OutputTexID; @@ -229,8 +229,8 @@ protected: QString m_LastSaveAll; QString m_LastSaveCurrent; CriticalSection m_Cs; - vector m_FinalImage; - vector m_PreviewFinalImage; + vector m_FinalImage; + vector m_PreviewFinalImage; vector m_ProcessActions; unique_ptr m_Renderer; QTIsaac m_Rand; @@ -275,15 +275,15 @@ public: virtual void DeleteCurrentXform() override; virtual void AddFinalXform() override; virtual bool UseFinalXform() override { return m_Ember.UseFinalXform(); } - //virtual bool IsFinal(unsigned int i) { return false; } + //virtual bool IsFinal(uint i) { return false; } virtual size_t XformCount() const override { return m_Ember.XformCount(); } virtual size_t TotalXformCount() const override { return m_Ember.TotalXformCount(); } virtual QString Name() const override { return QString::fromStdString(m_Ember.m_Name); } virtual void Name(const string& s) override { m_Ember.m_Name = s; } - virtual unsigned int FinalRasW() const override { return m_Ember.m_FinalRasW; } - virtual void FinalRasW(unsigned int w) override { m_Ember.m_FinalRasW = w; } - virtual unsigned int FinalRasH() const override { return m_Ember.m_FinalRasH; } - virtual void FinalRasH(unsigned int h) override { m_Ember.m_FinalRasH = h; } + virtual uint FinalRasW() const override { return m_Ember.m_FinalRasW; } + virtual void FinalRasW(uint w) override { m_Ember.m_FinalRasW = w; } + virtual uint FinalRasH() const override { return m_Ember.m_FinalRasH; } + virtual void FinalRasH(uint h) override { m_Ember.m_FinalRasH = h; } virtual size_t Index() const override { return m_Ember.m_Index; } virtual void AddSymmetry(int sym, QTIsaac& rand) override { m_Ember.AddSymmetry(sym, rand); } virtual void CalcNormalizedWeights() override { m_Ember.CalcNormalizedWeights(m_NormalizedWeights); } @@ -291,7 +291,7 @@ public: Ember* CurrentEmber(); //Menu. - virtual void NewFlock(unsigned int count) override; + virtual void NewFlock(uint count) override; virtual void NewEmptyFlameInCurrentFile() override; virtual void NewRandomFlameInCurrentFile() override; virtual void CopyFlameInCurrentFile() override; @@ -322,9 +322,9 @@ public: virtual void GammaThresholdChanged(double d) override; virtual void VibrancyChanged(double d) override; virtual void HighlightPowerChanged(double d) override; - virtual void PaletteModeChanged(unsigned int i) override; - virtual void WidthChanged(unsigned int i) override; - virtual void HeightChanged(unsigned int i) override; + virtual void PaletteModeChanged(uint i) override; + virtual void WidthChanged(uint i) override; + virtual void HeightChanged(uint i) override; virtual void CenterXChanged(double d) override; virtual void CenterYChanged(double d) override; virtual void ScaleChanged(double d) override; @@ -384,7 +384,7 @@ public: //Xforms Xaos. virtual void FillXaosWithCurrentXform() override; - virtual QString MakeXaosNameString(unsigned int i) override; + virtual QString MakeXaosNameString(uint i) override; virtual void XaosChanged(DoubleSpinBox* sender) override; virtual void ClearXaos() override; virtual void RandomXaos() override; @@ -393,7 +393,7 @@ public: virtual bool InitPaletteTable(const string& s) override; virtual void ApplyPaletteToEmber() override; virtual void PaletteAdjust() override; - virtual QRgb GetQRgbFromPaletteIndex(unsigned int i) override { return QRgb(); } + virtual QRgb GetQRgbFromPaletteIndex(uint i) override { return QRgb(); } virtual void PaletteCellClicked(int row, int col) override; //Library. @@ -402,15 +402,15 @@ public: virtual void UpdateLibraryTree() override; virtual void EmberTreeItemChanged(QTreeWidgetItem* item, int col) override; virtual void EmberTreeItemDoubleClicked(QTreeWidgetItem* item, int col) override; - virtual void RenderPreviews(unsigned int start = UINT_MAX, unsigned int end = UINT_MAX) override; + virtual void RenderPreviews(uint start = UINT_MAX, uint end = UINT_MAX) override; virtual void StopPreviewRender() override; //Info. //Rendering/progress. virtual bool Render() override; - virtual bool CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared = true) override; - virtual unsigned int SizeOfT() const override { return sizeof(T); } + virtual bool CreateRenderer(eRendererType renderType, uint platform, uint device, bool shared = true) override; + virtual uint SizeOfT() const override { return sizeof(T); } virtual int ProgressFunc(Ember& ember, void* foo, double fraction, int stage, double etaMs) override; virtual void ClearUndo() override; virtual GLEmberControllerBase* GLController() override { return m_GLController.get(); } @@ -453,7 +453,7 @@ private: unique_ptr> m_GLController; unique_ptr> m_PreviewRenderer; QFuture m_PreviewResult; - std::function m_PreviewRenderFunc; + std::function m_PreviewRenderFunc; }; template class FractoriumEmberController; diff --git a/Source/Fractorium/FractoriumInfo.cpp b/Source/Fractorium/FractoriumInfo.cpp index 1d49cb2..9bea892 100644 --- a/Source/Fractorium/FractoriumInfo.cpp +++ b/Source/Fractorium/FractoriumInfo.cpp @@ -28,7 +28,7 @@ void Fractorium::UpdateHistogramBounds() if (r->GetDensityFilter()) { - unsigned int deWidth = (r->GetDensityFilter()->FilterWidth() * 2) + 1; + uint deWidth = (r->GetDensityFilter()->FilterWidth() * 2) + 1; sprintf_s(m_DEString, 16, "%d x %d", deWidth, deWidth); ui.InfoBoundsTable->item(1, 1)->setText(QString(m_DEString)); diff --git a/Source/Fractorium/FractoriumLibrary.cpp b/Source/Fractorium/FractoriumLibrary.cpp index 0c95a8c..0f31a7d 100644 --- a/Source/Fractorium/FractoriumLibrary.cpp +++ b/Source/Fractorium/FractoriumLibrary.cpp @@ -17,7 +17,7 @@ void Fractorium::InitLibraryUI() /// The vector holding the RGBA bitmap /// The width of the bitmap /// The height of the bitmap -void Fractorium::SetLibraryTreeItemData(EmberTreeWidgetItemBase* item, vector& v, unsigned int width, unsigned int height) +void Fractorium::SetLibraryTreeItemData(EmberTreeWidgetItemBase* item, vector& v, uint width, uint height) { item->SetImage(v, width, height); } @@ -55,9 +55,9 @@ void FractoriumEmberController::SyncNames() template void FractoriumEmberController::FillLibraryTree(int selectIndex) { - unsigned int i, j, size = 64; + uint i, j, size = 64; QTreeWidget* tree = m_Fractorium->ui.LibraryTree; - vector v(size * size * 4); + vector v(size * size * 4); StopPreviewRender(); tree->clear(); @@ -107,9 +107,9 @@ void FractoriumEmberController::FillLibraryTree(int selectIndex) template void FractoriumEmberController::UpdateLibraryTree() { - unsigned int i, size = 64; + uint i, size = 64; QTreeWidget* tree = m_Fractorium->ui.LibraryTree; - vector v(size * size * 4); + vector v(size * size * 4); if (QTreeWidgetItem* top = tree->topLevelItem(0)) { @@ -229,7 +229,7 @@ void Fractorium::OnEmberTreeItemDoubleClicked(QTreeWidgetItem* item, int col) { /// The 0-based index to start rendering previews for /// The 0-based index which is one beyond the last ember to render a preview for template -void FractoriumEmberController::RenderPreviews(unsigned int start, unsigned int end) +void FractoriumEmberController::RenderPreviews(uint start, uint end) { StopPreviewRender(); @@ -242,7 +242,7 @@ void FractoriumEmberController::RenderPreviews(unsigned int start, unsigned i if (QTreeWidgetItem* top = tree->topLevelItem(0)) { int childCount = top->childCount(); - vector emptyPreview(PREVIEW_SIZE * PREVIEW_SIZE * 3); + vector emptyPreview(PREVIEW_SIZE * PREVIEW_SIZE * 3); for (int i = 0; i < childCount; i++) if (EmberTreeWidgetItem* treeItem = dynamic_cast*>(top->child(i))) diff --git a/Source/Fractorium/FractoriumMenus.cpp b/Source/Fractorium/FractoriumMenus.cpp index 92a12d0..73b989e 100644 --- a/Source/Fractorium/FractoriumMenus.cpp +++ b/Source/Fractorium/FractoriumMenus.cpp @@ -48,7 +48,7 @@ void Fractorium::InitMenusUI() /// /// The number of embers to include in the flock template -void FractoriumEmberController::NewFlock(unsigned int count) +void FractoriumEmberController::NewFlock(uint count) { Ember ember; @@ -57,7 +57,7 @@ void FractoriumEmberController::NewFlock(unsigned int count) m_EmberFile.m_Embers.reserve(count); m_EmberFile.m_Filename = EmberFile::DefaultFilename(); - for (unsigned int i = 0; i < count; i++) + for (uint i = 0; i < count; i++) { m_SheepTools->Random(ember); ParamsToEmber(ember); @@ -174,7 +174,7 @@ void FractoriumEmberController::OpenAndPrepFiles(const QStringList& filenames EmberFile emberFile; XmlToEmber parser; vector> embers; - unsigned int previousSize = append ? m_EmberFile.Size() : 0; + uint previousSize = append ? m_EmberFile.Size() : 0; StopPreviewRender(); emberFile.m_Filename = filenames[0]; @@ -423,7 +423,7 @@ void FractoriumEmberController::Redo() int index = m_Ember.GetTotalXformIndex(CurrentXform()); m_LastEditWasUndoRedo = true; - m_UndoIndex = min(m_UndoIndex + 1, m_UndoList.size() - 1); + m_UndoIndex = min(m_UndoIndex + 1, m_UndoList.size() - 1); SetEmber(m_UndoList[m_UndoIndex], true); m_EditState = UNDO_REDO; @@ -493,7 +493,7 @@ void Fractorium::OnActionCopyAllXml(bool checked) { m_Controller->CopyAllXml(); template void FractoriumEmberController::PasteXmlAppend() { - unsigned int i, previousSize = m_EmberFile.Size(); + uint i, previousSize = m_EmberFile.Size(); string s, errors; XmlToEmber parser; vector> embers; @@ -504,13 +504,13 @@ void FractoriumEmberController::PasteXmlAppend() for (i = 0; i < b.size(); i++) { - if ((unsigned int)b[i] < 128u) + if ((uint)b[i] < 128u) s.push_back(b[i]); } b.clear(); StopPreviewRender(); - parser.Parse((unsigned char*)s.c_str(), "", embers); + parser.Parse((byte*)s.c_str(), "", embers); errors = parser.ErrorReportString(); if (errors != "") @@ -548,7 +548,7 @@ void Fractorium::OnActionPasteXmlAppend(bool checked) { m_Controller->PasteXmlAp template void FractoriumEmberController::PasteXmlOver() { - unsigned int i; + uint i; string s, errors; XmlToEmber parser; Ember backupEmber = m_EmberFile.m_Embers[0]; @@ -559,14 +559,14 @@ void FractoriumEmberController::PasteXmlOver() for (i = 0; i < b.size(); i++) { - if ((unsigned int)b[i] < 128u) + if ((uint)b[i] < 128u) s.push_back(b[i]); } b.clear(); StopPreviewRender(); m_EmberFile.m_Embers.clear();//Will invalidate the pointers contained in the EmberTreeWidgetItems, UpdateLibraryTree() will resync. - parser.Parse((unsigned char*)s.c_str(), "", m_EmberFile.m_Embers); + parser.Parse((byte*)s.c_str(), "", m_EmberFile.m_Embers); errors = parser.ErrorReportString(); if (errors != "") diff --git a/Source/Fractorium/FractoriumPalette.cpp b/Source/Fractorium/FractoriumPalette.cpp index 7965a07..f9f5cac 100644 --- a/Source/Fractorium/FractoriumPalette.cpp +++ b/Source/Fractorium/FractoriumPalette.cpp @@ -76,7 +76,7 @@ bool FractoriumEmberController::InitPaletteTable(const string& s) for (size_t i = 0; i < m_PaletteList.Size(); i++) { Palette* p = m_PaletteList.GetPalette(i); - vector v = p->MakeRgbPaletteBlock(PALETTE_CELL_HEIGHT); + vector v = p->MakeRgbPaletteBlock(PALETTE_CELL_HEIGHT); QTableWidgetItem* nameCol = new QTableWidgetItem(p->m_Name.c_str()); nameCol->setToolTip(p->m_Name.c_str()); @@ -109,8 +109,8 @@ template void FractoriumEmberController::ApplyPaletteToEmber() { int i, rot = 0; - unsigned int blur = m_Fractorium->m_PaletteBlurSpin->value(); - unsigned int freq = m_Fractorium->m_PaletteFrequencySpin->value(); + uint blur = m_Fractorium->m_PaletteBlurSpin->value(); + uint freq = m_Fractorium->m_PaletteFrequencySpin->value(); double sat = (double)m_Fractorium->m_PaletteSaturationSpin->value() / 100.0; double brightness = (double)m_Fractorium->m_PaletteBrightnessSpin->value() / 255.0; double contrast = (double)(m_Fractorium->m_PaletteContrastSpin->value() > 0 ? (m_Fractorium->m_PaletteContrastSpin->value() * 2) : m_Fractorium->m_PaletteContrastSpin->value()) / 100.0; @@ -138,7 +138,7 @@ void FractoriumEmberController::UpdateAdjustedPaletteGUI(Palette& palette) if (previewPaletteItem)//This can be null if the palette file was moved or corrupted. { //Use the adjusted palette to fill the preview palette control so the user can see the effects of applying the adjustements. - vector v = palette.MakeRgbPaletteBlock(PALETTE_CELL_HEIGHT);//Make the palette repeat for PALETTE_CELL_HEIGHT rows. + vector v = palette.MakeRgbPaletteBlock(PALETTE_CELL_HEIGHT);//Make the palette repeat for PALETTE_CELL_HEIGHT rows. m_FinalPaletteImage = QImage(palette.Size(), PALETTE_CELL_HEIGHT, QImage::Format_RGB888);//Create a QImage out of it. memcpy(m_FinalPaletteImage.scanLine(0), v.data(), v.size() * sizeof(v[0]));//Memcpy the data in. @@ -232,7 +232,7 @@ void Fractorium::OnPaletteCellDoubleClicked(int row, int col) /// The current row selected void Fractorium::OnPaletteRandomSelectButtonClicked(bool checked) { - unsigned int i = 0; + uint i = 0; int rowCount = ui.PaletteListTable->rowCount() - 1; while ((i = QTIsaac::GlobalRand->Rand(rowCount)) == m_PreviousPaletteRow); diff --git a/Source/Fractorium/FractoriumParams.cpp b/Source/Fractorium/FractoriumParams.cpp index 68ba34b..aaf0c65 100644 --- a/Source/Fractorium/FractoriumParams.cpp +++ b/Source/Fractorium/FractoriumParams.cpp @@ -207,7 +207,7 @@ void Fractorium::OnColorSelected(const QColor& color) { m_Controller->Background /// Resets the rendering process. /// /// The index of the palette mode combo box -template void FractoriumEmberController::PaletteModeChanged(unsigned int i) { Update([&] { m_Ember.m_PaletteMode = i == 0 ? PALETTE_STEP : PALETTE_LINEAR; }); } +template void FractoriumEmberController::PaletteModeChanged(uint i) { Update([&] { m_Ember.m_PaletteMode = i == 0 ? PALETTE_STEP : PALETTE_LINEAR; }); } void Fractorium::OnPaletteModeComboCurrentIndexChanged(int index) { m_Controller->PaletteModeChanged(index); } /// @@ -219,7 +219,7 @@ void Fractorium::OnPaletteModeComboCurrentIndexChanged(int index) { m_Controller /// Dimensions are set automatically to match the dimensions of GLWidget. /// /// Ignored -template void FractoriumEmberController::WidthChanged(unsigned int i) { Update([&] { m_Ember.m_FinalRasW = i; }); } +template void FractoriumEmberController::WidthChanged(uint i) { Update([&] { m_Ember.m_FinalRasW = i; }); } void Fractorium::OnWidthChanged(int i) { m_Controller->WidthChanged(i); } /// @@ -227,7 +227,7 @@ void Fractorium::OnWidthChanged(int i) { m_Controller->WidthChanged(i); } /// Dimensions are set automatically to match the dimensions of GLWidget. /// /// Ignored -template void FractoriumEmberController::HeightChanged(unsigned int i) { Update([&] { m_Ember.m_FinalRasH = i; }); } +template void FractoriumEmberController::HeightChanged(uint i) { Update([&] { m_Ember.m_FinalRasH = i; }); } void Fractorium::OnHeightChanged(int i) { m_Controller->HeightChanged(i); } /// diff --git a/Source/Fractorium/FractoriumRender.cpp b/Source/Fractorium/FractoriumRender.cpp index 2bc0cb5..f4c3e74 100644 --- a/Source/Fractorium/FractoriumRender.cpp +++ b/Source/Fractorium/FractoriumRender.cpp @@ -114,11 +114,11 @@ void FractoriumEmberControllerBase::SaveCurrentRender(const QString& filename, b if (filename != "") { bool b = false; - unsigned int i, j; - unsigned int width = m_Renderer->FinalRasW(); - unsigned int height = m_Renderer->FinalRasH(); - unsigned char* data = NULL; - vector vecRgb; + uint i, j; + uint width = m_Renderer->FinalRasW(); + uint height = m_Renderer->FinalRasH(); + byte* data = NULL; + vector vecRgb; QFileInfo fileInfo(filename); QString suffix = fileInfo.suffix(); FractoriumSettings* settings = m_Fractorium->m_Settings; @@ -379,7 +379,7 @@ bool FractoriumEmberController::Render() { EmberStats stats = m_Renderer->Stats(); QString iters = ToString(stats.m_Iters); - QString scaledQuality = ToString((unsigned int)m_Renderer->ScaledQuality()); + QString scaledQuality = ToString((uint)m_Renderer->ScaledQuality()); string renderTime = m_RenderElapsedTimer.Format(m_RenderElapsedTimer.Toc()); m_Fractorium->m_ProgressBar->setValue(100); @@ -485,7 +485,7 @@ bool FractoriumEmberController::Render() /// True if shared with OpenGL, else false. Default: true. /// True if nothing went wrong, else false. template -bool FractoriumEmberController::CreateRenderer(eRendererType renderType, unsigned int platform, unsigned int device, bool shared) +bool FractoriumEmberController::CreateRenderer(eRendererType renderType, uint platform, uint device, bool shared) { bool ok = true; FractoriumSettings* s = m_Fractorium->m_Settings; diff --git a/Source/Fractorium/FractoriumSettings.cpp b/Source/Fractorium/FractoriumSettings.cpp index 672ff5b..28bcd15 100644 --- a/Source/Fractorium/FractoriumSettings.cpp +++ b/Source/Fractorium/FractoriumSettings.cpp @@ -117,14 +117,14 @@ void FractoriumSettings::Double(bool b) { setValue(DOUBLEPRECISION, b); bool FractoriumSettings::ShowAllXforms() { return value(SHOWALLXFORMS).toBool(); } void FractoriumSettings::ShowAllXforms(bool b) { setValue(SHOWALLXFORMS, b); } -unsigned int FractoriumSettings::PlatformIndex() { return value(PLATFORMINDEX).toUInt(); } -void FractoriumSettings::PlatformIndex(unsigned int i) { setValue(PLATFORMINDEX, i); } +uint FractoriumSettings::PlatformIndex() { return value(PLATFORMINDEX).toUInt(); } +void FractoriumSettings::PlatformIndex(uint i) { setValue(PLATFORMINDEX, i); } -unsigned int FractoriumSettings::DeviceIndex() { return value(DEVICEINDEX).toUInt(); } -void FractoriumSettings::DeviceIndex(unsigned int i) { setValue(DEVICEINDEX, i); } +uint FractoriumSettings::DeviceIndex() { return value(DEVICEINDEX).toUInt(); } +void FractoriumSettings::DeviceIndex(uint i) { setValue(DEVICEINDEX, i); } -unsigned int FractoriumSettings::ThreadCount() { return value(THREADCOUNT).toUInt(); } -void FractoriumSettings::ThreadCount(unsigned int i) { setValue(THREADCOUNT, i); } +uint FractoriumSettings::ThreadCount() { return value(THREADCOUNT).toUInt(); } +void FractoriumSettings::ThreadCount(uint i) { setValue(THREADCOUNT, i); } bool FractoriumSettings::CpuDEFilter() { return value(CPUDEFILTER).toBool(); } void FractoriumSettings::CpuDEFilter(bool b) { setValue(CPUDEFILTER, b); } @@ -132,11 +132,11 @@ void FractoriumSettings::CpuDEFilter(bool b) { setValue(CPUDEFI bool FractoriumSettings::OpenCLDEFilter() { return value(OPENCLDEFILTER).toBool(); } void FractoriumSettings::OpenCLDEFilter(bool b) { setValue(OPENCLDEFILTER, b); } -unsigned int FractoriumSettings::CpuSubBatch() { return value(CPUSUBBATCH).toUInt(); } -void FractoriumSettings::CpuSubBatch(unsigned int b) { setValue(CPUSUBBATCH, b); } +uint FractoriumSettings::CpuSubBatch() { return value(CPUSUBBATCH).toUInt(); } +void FractoriumSettings::CpuSubBatch(uint b) { setValue(CPUSUBBATCH, b); } -unsigned int FractoriumSettings::OpenCLSubBatch() { return value(OPENCLSUBBATCH).toUInt(); } -void FractoriumSettings::OpenCLSubBatch(unsigned int b) { setValue(OPENCLSUBBATCH, b); } +uint FractoriumSettings::OpenCLSubBatch() { return value(OPENCLSUBBATCH).toUInt(); } +void FractoriumSettings::OpenCLSubBatch(uint b) { setValue(OPENCLSUBBATCH, b); } /// /// Final render settings. @@ -169,45 +169,45 @@ void FractoriumSettings::FinalDoSequence(bool b) { setValue(FINALDOSEQUENCE, bool FractoriumSettings::FinalKeepAspect() { return value(FINALKEEPASPECT).toBool(); } void FractoriumSettings::FinalKeepAspect(bool b) { setValue(FINALKEEPASPECT, b); } -unsigned int FractoriumSettings::FinalScale() { return value(FINALSCALE).toUInt(); } -void FractoriumSettings::FinalScale(unsigned int i) { setValue(FINALSCALE, i); } +uint FractoriumSettings::FinalScale() { return value(FINALSCALE).toUInt(); } +void FractoriumSettings::FinalScale(uint i) { setValue(FINALSCALE, i); } QString FractoriumSettings::FinalExt() { return value(FINALEXT).toString(); } void FractoriumSettings::FinalExt(const QString& s) { setValue(FINALEXT, s); } -unsigned int FractoriumSettings::FinalPlatformIndex() { return value(FINALPLATFORMINDEX).toUInt(); } -void FractoriumSettings::FinalPlatformIndex(unsigned int i) { setValue(FINALPLATFORMINDEX, i); } +uint FractoriumSettings::FinalPlatformIndex() { return value(FINALPLATFORMINDEX).toUInt(); } +void FractoriumSettings::FinalPlatformIndex(uint i) { setValue(FINALPLATFORMINDEX, i); } -unsigned int FractoriumSettings::FinalDeviceIndex() { return value(FINALDEVICEINDEX).toUInt(); } -void FractoriumSettings::FinalDeviceIndex(unsigned int i) { setValue(FINALDEVICEINDEX, i); } +uint FractoriumSettings::FinalDeviceIndex() { return value(FINALDEVICEINDEX).toUInt(); } +void FractoriumSettings::FinalDeviceIndex(uint i) { setValue(FINALDEVICEINDEX, i); } -unsigned int FractoriumSettings::FinalThreadCount() { return value(FINALTHREADCOUNT).toUInt(); } -void FractoriumSettings::FinalThreadCount(unsigned int i) { setValue(FINALTHREADCOUNT, i); } +uint FractoriumSettings::FinalThreadCount() { return value(FINALTHREADCOUNT).toUInt(); } +void FractoriumSettings::FinalThreadCount(uint i) { setValue(FINALTHREADCOUNT, i); } -unsigned int FractoriumSettings::FinalQuality() { return value(FINALQUALITY).toUInt(); } -void FractoriumSettings::FinalQuality(unsigned int i) { setValue(FINALQUALITY, i); } +uint FractoriumSettings::FinalQuality() { return value(FINALQUALITY).toUInt(); } +void FractoriumSettings::FinalQuality(uint i) { setValue(FINALQUALITY, i); } -unsigned int FractoriumSettings::FinalTemporalSamples() { return value(FINALTEMPORALSAMPLES).toUInt(); } -void FractoriumSettings::FinalTemporalSamples(unsigned int i) { setValue(FINALTEMPORALSAMPLES, i); } +uint FractoriumSettings::FinalTemporalSamples() { return value(FINALTEMPORALSAMPLES).toUInt(); } +void FractoriumSettings::FinalTemporalSamples(uint i) { setValue(FINALTEMPORALSAMPLES, i); } -unsigned int FractoriumSettings::FinalSupersample() { return value(FINALSUPERSAMPLE).toUInt(); } -void FractoriumSettings::FinalSupersample(unsigned int i) { setValue(FINALSUPERSAMPLE, i); } +uint FractoriumSettings::FinalSupersample() { return value(FINALSUPERSAMPLE).toUInt(); } +void FractoriumSettings::FinalSupersample(uint i) { setValue(FINALSUPERSAMPLE, i); } -unsigned int FractoriumSettings::FinalStrips() { return value(FINALSTRIPS).toUInt(); } -void FractoriumSettings::FinalStrips(unsigned int i) { setValue(FINALSTRIPS, i); } +uint FractoriumSettings::FinalStrips() { return value(FINALSTRIPS).toUInt(); } +void FractoriumSettings::FinalStrips(uint i) { setValue(FINALSTRIPS, i); } /// /// Xml file saving settings. /// -unsigned int FractoriumSettings::XmlTemporalSamples() { return value(XMLTEMPORALSAMPLES).toUInt(); } -void FractoriumSettings::XmlTemporalSamples(unsigned int i) { setValue(XMLTEMPORALSAMPLES, i); } +uint FractoriumSettings::XmlTemporalSamples() { return value(XMLTEMPORALSAMPLES).toUInt(); } +void FractoriumSettings::XmlTemporalSamples(uint i) { setValue(XMLTEMPORALSAMPLES, i); } -unsigned int FractoriumSettings::XmlQuality() { return value(XMLQUALITY).toUInt(); } -void FractoriumSettings::XmlQuality(unsigned int i) { setValue(XMLQUALITY, i); } +uint FractoriumSettings::XmlQuality() { return value(XMLQUALITY).toUInt(); } +void FractoriumSettings::XmlQuality(uint i) { setValue(XMLQUALITY, i); } -unsigned int FractoriumSettings::XmlSupersample() { return value(XMLSUPERSAMPLE).toUInt(); } -void FractoriumSettings::XmlSupersample(unsigned int i) { setValue(XMLSUPERSAMPLE, i); } +uint FractoriumSettings::XmlSupersample() { return value(XMLSUPERSAMPLE).toUInt(); } +void FractoriumSettings::XmlSupersample(uint i) { setValue(XMLSUPERSAMPLE, i); } QString FractoriumSettings::Id() { return value(IDENTITYID).toString(); } void FractoriumSettings::Id(const QString& s) { setValue(IDENTITYID, s); } diff --git a/Source/Fractorium/FractoriumSettings.h b/Source/Fractorium/FractoriumSettings.h index 2564fef..07b08d2 100644 --- a/Source/Fractorium/FractoriumSettings.h +++ b/Source/Fractorium/FractoriumSettings.h @@ -87,14 +87,14 @@ public: bool ShowAllXforms(); void ShowAllXforms(bool b); - unsigned int PlatformIndex(); - void PlatformIndex(unsigned int b); + uint PlatformIndex(); + void PlatformIndex(uint b); - unsigned int DeviceIndex(); - void DeviceIndex(unsigned int b); + uint DeviceIndex(); + void DeviceIndex(uint b); - unsigned int ThreadCount(); - void ThreadCount(unsigned int b); + uint ThreadCount(); + void ThreadCount(uint b); bool CpuDEFilter(); void CpuDEFilter(bool b); @@ -102,11 +102,11 @@ public: bool OpenCLDEFilter(); void OpenCLDEFilter(bool b); - unsigned int CpuSubBatch(); - void CpuSubBatch(unsigned int b); + uint CpuSubBatch(); + void CpuSubBatch(uint b); - unsigned int OpenCLSubBatch(); - void OpenCLSubBatch(unsigned int b); + uint OpenCLSubBatch(); + void OpenCLSubBatch(uint b); bool FinalEarlyClip(); void FinalEarlyClip(bool b); @@ -135,41 +135,41 @@ public: bool FinalKeepAspect(); void FinalKeepAspect(bool b); - unsigned int FinalScale(); - void FinalScale(unsigned int i); + uint FinalScale(); + void FinalScale(uint i); QString FinalExt(); void FinalExt(const QString& s); - unsigned int FinalPlatformIndex(); - void FinalPlatformIndex(unsigned int b); + uint FinalPlatformIndex(); + void FinalPlatformIndex(uint b); - unsigned int FinalDeviceIndex(); - void FinalDeviceIndex(unsigned int b); + uint FinalDeviceIndex(); + void FinalDeviceIndex(uint b); - unsigned int FinalThreadCount(); - void FinalThreadCount(unsigned int b); + uint FinalThreadCount(); + void FinalThreadCount(uint b); - unsigned int FinalQuality(); - void FinalQuality(unsigned int i); + uint FinalQuality(); + void FinalQuality(uint i); - unsigned int FinalTemporalSamples(); - void FinalTemporalSamples(unsigned int i); + uint FinalTemporalSamples(); + void FinalTemporalSamples(uint i); - unsigned int FinalSupersample(); - void FinalSupersample(unsigned int i); + uint FinalSupersample(); + void FinalSupersample(uint i); - unsigned int FinalStrips(); - void FinalStrips(unsigned int i); + uint FinalStrips(); + void FinalStrips(uint i); - unsigned int XmlTemporalSamples(); - void XmlTemporalSamples(unsigned int i); + uint XmlTemporalSamples(); + void XmlTemporalSamples(uint i); - unsigned int XmlQuality(); - void XmlQuality(unsigned int i); + uint XmlQuality(); + void XmlQuality(uint i); - unsigned int XmlSupersample(); - void XmlSupersample(unsigned int i); + uint XmlSupersample(); + void XmlSupersample(uint i); QString OpenFolder(); void OpenFolder(const QString& s); diff --git a/Source/Fractorium/FractoriumXforms.cpp b/Source/Fractorium/FractoriumXforms.cpp index cef5f08..535b604 100644 --- a/Source/Fractorium/FractoriumXforms.cpp +++ b/Source/Fractorium/FractoriumXforms.cpp @@ -46,7 +46,7 @@ Xform* FractoriumEmberController::CurrentXform() /// Set the current xform to the index passed in. /// /// The index to set the current xform to -void Fractorium::CurrentXform(unsigned int i) +void Fractorium::CurrentXform(uint i) { if (i < ui.CurrentXformCombo->count()) ui.CurrentXformCombo->setCurrentIndex(i); diff --git a/Source/Fractorium/FractoriumXformsColor.cpp b/Source/Fractorium/FractoriumXformsColor.cpp index a7bcee4..915af6f 100644 --- a/Source/Fractorium/FractoriumXformsColor.cpp +++ b/Source/Fractorium/FractoriumXformsColor.cpp @@ -163,7 +163,7 @@ void FractoriumEmberController::SetCurrentXformColorIndex(double d) entry.g *= 255; entry.b *= 255; - QRgb rgb = (unsigned int)entry.r << 16 | (unsigned int)entry.g << 8 | (unsigned int)entry.b; + QRgb rgb = (uint)entry.r << 16 | (uint)entry.g << 8 | (uint)entry.b; m_Fractorium->ui.XformColorIndexTable->item(0, 0)->setBackgroundColor(QColor::fromRgb(rgb)); }, false); } diff --git a/Source/Fractorium/FractoriumXformsVariations.cpp b/Source/Fractorium/FractoriumXformsVariations.cpp index c36c10d..a1824c3 100644 --- a/Source/Fractorium/FractoriumXformsVariations.cpp +++ b/Source/Fractorium/FractoriumXformsVariations.cpp @@ -106,14 +106,14 @@ void FractoriumEmberController::ClearVariationsTree() { QTreeWidget* tree = m_Fractorium->ui.VariationsTree; - for (unsigned int i = 0; i < tree->topLevelItemCount(); i++) + for (uint i = 0; i < tree->topLevelItemCount(); i++) { QTreeWidgetItem* item = tree->topLevelItem(i); VariationTreeDoubleSpinBox* spinBox = dynamic_cast*>(tree->itemWidget(item, 1)); spinBox->SetValueStealth(0); - for (unsigned int j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params. + for (uint j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params. { if (spinBox = dynamic_cast*>(tree->itemWidget(item->child(j), 1)))//Cast the child widget to the VariationTreeDoubleSpinBox type. spinBox->SetValueStealth(0); @@ -223,7 +223,7 @@ void FractoriumEmberController::FillVariationTreeWithXform(Xform* xform) tree->blockSignals(true); - for (unsigned int i = 0; i < tree->topLevelItemCount(); i++) + for (uint i = 0; i < tree->topLevelItemCount(); i++) { VariationTreeWidgetItem* item = dynamic_cast*>(tree->topLevelItem(i)); Variation* var = xform->GetVariationById(item->Id());//See if this variation in the tree was contained in the xform. @@ -235,7 +235,7 @@ void FractoriumEmberController::FillVariationTreeWithXform(Xform* xform) spinBox->SetValueStealth(var ? var->m_Weight : 0);//If the variation was present, set the spin box to its weight, else zero. item->setBackgroundColor(0, var ? QColor(200, 200, 200) : QColor(255, 255, 255));//Ensure background is always white if the value goes to zero, else gray if var present. - for (unsigned int j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params if it was a parametric variation. + for (uint j = 0; j < item->childCount(); j++)//Iterate through all of the children, which will be the params if it was a parametric variation. { T* param = NULL; QTreeWidgetItem* childItem = item->child(j);//Get the child. @@ -293,7 +293,7 @@ void Fractorium::OnVariationsFilterLineEditTextChanged(const QString& text) tree->setUpdatesEnabled(false); - for (unsigned int i = 0; i < tree->topLevelItemCount(); i++) + for (uint i = 0; i < tree->topLevelItemCount(); i++) { QTreeWidgetItem* item = tree->topLevelItem(i); QString varName = item->text(0); diff --git a/Source/Fractorium/FractoriumXformsXaos.cpp b/Source/Fractorium/FractoriumXformsXaos.cpp index 325a141..e530b20 100644 --- a/Source/Fractorium/FractoriumXformsXaos.cpp +++ b/Source/Fractorium/FractoriumXformsXaos.cpp @@ -50,7 +50,7 @@ void FractoriumEmberController::FillXaosWithCurrentXform() /// The index of the xform whose xaos will be used /// The xaos name string template -QString FractoriumEmberController::MakeXaosNameString(unsigned int i) +QString FractoriumEmberController::MakeXaosNameString(uint i) { Xform* xform = m_Ember.GetXform(i); QString name; diff --git a/Source/Fractorium/GLEmberController.cpp b/Source/Fractorium/GLEmberController.cpp index b771f01..90d8f75 100644 --- a/Source/Fractorium/GLEmberController.cpp +++ b/Source/Fractorium/GLEmberController.cpp @@ -119,7 +119,7 @@ typename v3T GLEmberController::SnapToGrid(v3T& vec) /// The divisions of a circle to use for snapping /// The snapped world cartesian coordinate template -typename v3T GLEmberController::SnapToNormalizedAngle(v3T& vec, unsigned int divisions) +typename v3T GLEmberController::SnapToNormalizedAngle(v3T& vec, uint divisions) { T rsq, theta; T bestRsq = numeric_limits::max(); @@ -128,7 +128,7 @@ typename v3T GLEmberController::SnapToNormalizedAngle(v3T& vec, unsigned int best.x = 1; best.y = 0; - for (unsigned int i = 0; i < divisions; i++) + for (uint i = 0; i < divisions; i++) { theta = 2.0 * M_PI * (T)i / (T)divisions; c.x = cos(theta); diff --git a/Source/Fractorium/GLEmberController.h b/Source/Fractorium/GLEmberController.h index 4e18c61..6f8f7b5 100644 --- a/Source/Fractorium/GLEmberController.h +++ b/Source/Fractorium/GLEmberController.h @@ -65,7 +65,7 @@ public: virtual void QueryMatrices(bool print) { } protected: - unsigned int m_DragModifier; + uint m_DragModifier; glm::ivec2 m_MousePos; glm::ivec2 m_MouseDownPos; glm::ivec4 m_Viewport; @@ -111,7 +111,7 @@ public: private: v3T SnapToGrid(v3T& vec); - v3T SnapToNormalizedAngle(v3T& vec, unsigned int divisions); + v3T SnapToNormalizedAngle(v3T& vec, uint divisions); v3T WindowToWorld(v3T& v, bool flip); void QueryVMP(); void MultMatrix(m4T& mat); diff --git a/Source/Fractorium/GLWidget.cpp b/Source/Fractorium/GLWidget.cpp index 79a08fb..8b6bbd5 100644 --- a/Source/Fractorium/GLWidget.cpp +++ b/Source/Fractorium/GLWidget.cpp @@ -51,7 +51,7 @@ void GLWidget::DrawQuad() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); RendererBase* renderer = m_Fractorium->m_Controller->Renderer(); - vector* finalImage = m_Fractorium->m_Controller->FinalImage(); + vector* finalImage = m_Fractorium->m_Controller->FinalImage(); //Ensure all allocation has taken place first. if (m_OutputTexID != 0 && finalImage && !finalImage->empty()) @@ -270,7 +270,7 @@ void GLEmberController::DrawImage() if (SizesMatch())//Ensure all sizes are correct. If not, do nothing. { - vector* finalImage = m_FractoriumEmberController->FinalImage(); + vector* finalImage = m_FractoriumEmberController->FinalImage(); if (renderer->RendererType() == OPENCL_RENDERER || finalImage)//Final image only matters for CPU renderer. if (renderer->RendererType() == OPENCL_RENDERER || finalImage->size() == renderer->FinalBufferSize()) @@ -310,7 +310,7 @@ void GLEmberController::DrawAffines(bool pre, bool post) { if (pre && m_Fractorium->DrawAllPre())//Draw all pre affine if specified. { - for (unsigned int i = 0; i < ember->TotalXformCount(); i++) + for (uint i = 0; i < ember->TotalXformCount(); i++) { Xform* xform = ember->GetTotalXform(i); bool selected = dragging ? (m_SelectedXform == xform) : (m_HoverXform == xform); @@ -325,7 +325,7 @@ void GLEmberController::DrawAffines(bool pre, bool post) if (post && m_Fractorium->DrawAllPost())//Draw all post affine if specified. { - for (unsigned int i = 0; i < ember->TotalXformCount(); i++) + for (uint i = 0; i < ember->TotalXformCount(); i++) { Xform* xform = ember->GetTotalXform(i); bool selected = dragging ? (m_SelectedXform == xform) : (m_HoverXform == xform); @@ -1073,7 +1073,7 @@ int GLEmberController::UpdateHover(v3T& glCoords) bool post = m_Fractorium->ui.PostAffineGroupBox->isChecked(); bool preAll = pre && m_Fractorium->DrawAllPre(); bool postAll = post && m_Fractorium->DrawAllPost(); - unsigned int bestIndex = -1; + uint bestIndex = -1; T bestDist = 10; Ember* ember = m_FractoriumEmberController->CurrentEmber(); @@ -1096,7 +1096,7 @@ int GLEmberController::UpdateHover(v3T& glCoords) } //Check all xforms. - for (unsigned int i = 0; i < ember->TotalXformCount(); i++) + for (uint i = 0; i < ember->TotalXformCount(); i++) { Xform* xform = ember->GetTotalXform(i); diff --git a/Source/Fractorium/OptionsDialog.cpp b/Source/Fractorium/OptionsDialog.cpp index 31b9f70..f46b027 100644 --- a/Source/Fractorium/OptionsDialog.cpp +++ b/Source/Fractorium/OptionsDialog.cpp @@ -12,7 +12,7 @@ FractoriumOptionsDialog::FractoriumOptionsDialog(FractoriumSettings* settings, Q : QDialog(parent, f) { int row = 0, spinHeight = 20; - unsigned int i; + uint i; ui.setupUi(this); m_Settings = settings; @@ -102,9 +102,9 @@ bool FractoriumOptionsDialog::Transparency() { return ui.TransparencyCheckBox->i bool FractoriumOptionsDialog::OpenCL() { return ui.OpenCLCheckBox->isChecked(); } bool FractoriumOptionsDialog::Double() { return ui.DoublePrecisionCheckBox->isChecked(); } bool FractoriumOptionsDialog::ShowAllXforms() { return ui.ShowAllXformsCheckBox->isChecked(); } -unsigned int FractoriumOptionsDialog::PlatformIndex() { return ui.PlatformCombo->currentIndex(); } -unsigned int FractoriumOptionsDialog::DeviceIndex() { return ui.DeviceCombo->currentIndex(); } -unsigned int FractoriumOptionsDialog::ThreadCount() { return ui.ThreadCountSpin->value(); } +uint FractoriumOptionsDialog::PlatformIndex() { return ui.PlatformCombo->currentIndex(); } +uint FractoriumOptionsDialog::DeviceIndex() { return ui.DeviceCombo->currentIndex(); } +uint FractoriumOptionsDialog::ThreadCount() { return ui.ThreadCountSpin->value(); } /// /// Disable or enable the OpenCL related controls based on the state passed in. diff --git a/Source/Fractorium/OptionsDialog.h b/Source/Fractorium/OptionsDialog.h index c0bf4d0..ceea506 100644 --- a/Source/Fractorium/OptionsDialog.h +++ b/Source/Fractorium/OptionsDialog.h @@ -40,9 +40,9 @@ private: bool OpenCL(); bool Double(); bool ShowAllXforms(); - unsigned int PlatformIndex(); - unsigned int DeviceIndex(); - unsigned int ThreadCount(); + uint PlatformIndex(); + uint DeviceIndex(); + uint ThreadCount(); Ui::OptionsDialog ui; OpenCLWrapper m_Wrapper;