Path: blob/master/thirdparty/cvtt/ConvectionKernels_AggregatedError.h
9913 views
#pragma once1#ifndef __CVTT_AGGREGATEDERROR_H__2#define __CVTT_AGGREGATEDERROR_H__34#include "ConvectionKernels_ParallelMath.h"56namespace cvtt7{8namespace Internal9{10template<int TVectorSize>11class AggregatedError12{13public:14typedef ParallelMath::UInt16 MUInt16;15typedef ParallelMath::UInt31 MUInt31;16typedef ParallelMath::Float MFloat;1718AggregatedError()19{20for (int ch = 0; ch < TVectorSize; ch++)21m_errorUnweighted[ch] = ParallelMath::MakeUInt31(0);22}2324void Add(const MUInt16 &channelErrorUnweighted, int ch)25{26m_errorUnweighted[ch] = m_errorUnweighted[ch] + ParallelMath::ToUInt31(channelErrorUnweighted);27}2829MFloat Finalize(uint32_t flags, const float channelWeightsSq[TVectorSize]) const30{31if (flags & cvtt::Flags::Uniform)32{33MUInt31 total = m_errorUnweighted[0];34for (int ch = 1; ch < TVectorSize; ch++)35total = total + m_errorUnweighted[ch];36return ParallelMath::ToFloat(total);37}38else39{40MFloat total = ParallelMath::ToFloat(m_errorUnweighted[0]) * channelWeightsSq[0];41for (int ch = 1; ch < TVectorSize; ch++)42total = total + ParallelMath::ToFloat(m_errorUnweighted[ch]) * channelWeightsSq[ch];43return total;44}45}4647private:48MUInt31 m_errorUnweighted[TVectorSize];49};50}51}5253#endif54555657