Path: blob/master/thirdparty/cvtt/ConvectionKernels_BC67.h
9903 views
#pragma once12#include "ConvectionKernels_ParallelMath.h"345namespace cvtt6{7namespace Tables8{9namespace BC7SC10{11struct Table;12}13}1415namespace Internal16{17namespace BC6718{19struct WorkInfo;20}2122template<int TVectorSize>23class IndexSelectorHDR;24}2526struct PixelBlockU8;27}2829namespace cvtt30{31namespace Internal32{33class BC7Computer34{35public:36static void Pack(uint32_t flags, const PixelBlockU8* inputs, uint8_t* packedBlocks, const float channelWeights[4], const BC7EncodingPlan &encodingPlan, int numRefineRounds);37static void UnpackOne(PixelBlockU8 &output, const uint8_t* packedBlock);3839private:40static const int MaxTweakRounds = 4;4142typedef ParallelMath::SInt16 MSInt16;43typedef ParallelMath::UInt15 MUInt15;44typedef ParallelMath::UInt16 MUInt16;45typedef ParallelMath::SInt32 MSInt32;46typedef ParallelMath::Float MFloat;4748static void TweakAlpha(const MUInt15 original[2], int tweak, int range, MUInt15 result[2]);49static void Quantize(MUInt15* color, int bits, int channels);50static void QuantizeP(MUInt15* color, int bits, uint16_t p, int channels);51static void Unquantize(MUInt15* color, int bits, int channels);52static void CompressEndpoints0(MUInt15 ep[2][4], uint16_t p[2]);53static void CompressEndpoints1(MUInt15 ep[2][4], uint16_t p);54static void CompressEndpoints2(MUInt15 ep[2][4]);55static void CompressEndpoints3(MUInt15 ep[2][4], uint16_t p[2]);56static void CompressEndpoints4(MUInt15 epRGB[2][3], MUInt15 epA[2]);57static void CompressEndpoints5(MUInt15 epRGB[2][3], MUInt15 epA[2]);58static void CompressEndpoints6(MUInt15 ep[2][4], uint16_t p[2]);59static void CompressEndpoints7(MUInt15 ep[2][4], uint16_t p[2]);60static void TrySingleColorRGBAMultiTable(uint32_t flags, const MUInt15 pixels[16][4], const MFloat average[4], int numRealChannels, const uint8_t *fragmentStart, int shapeLength, const MFloat &staticAlphaError, const ParallelMath::Int16CompFlag punchThroughInvalid[4], MFloat& shapeBestError, MUInt15 shapeBestEP[2][4], MUInt15 *fragmentBestIndexes, const float *channelWeightsSq, const cvtt::Tables::BC7SC::Table*const* tables, int numTables, const ParallelMath::RoundTowardNearestForScope *rtn);61static void TrySinglePlane(uint32_t flags, const MUInt15 pixels[16][4], const MFloat floatPixels[16][4], const float channelWeights[4], const BC7EncodingPlan &encodingPlan, int numRefineRounds, BC67::WorkInfo& work, const ParallelMath::RoundTowardNearestForScope *rtn);62static void TryDualPlane(uint32_t flags, const MUInt15 pixels[16][4], const MFloat floatPixels[16][4], const float channelWeights[4], const BC7EncodingPlan &encodingPlan, int numRefineRounds, BC67::WorkInfo& work, const ParallelMath::RoundTowardNearestForScope *rtn);6364template<class T>65static void Swap(T& a, T& b);66};676869class BC6HComputer70{71public:72static void Pack(uint32_t flags, const PixelBlockF16* inputs, uint8_t* packedBlocks, const float channelWeights[4], bool isSigned, int numTweakRounds, int numRefineRounds);73static void UnpackOne(PixelBlockF16 &output, const uint8_t *pBC, bool isSigned);7475private:76typedef ParallelMath::Float MFloat;77typedef ParallelMath::SInt16 MSInt16;78typedef ParallelMath::UInt16 MUInt16;79typedef ParallelMath::UInt15 MUInt15;80typedef ParallelMath::AInt16 MAInt16;81typedef ParallelMath::SInt32 MSInt32;82typedef ParallelMath::UInt31 MUInt31;8384static const int MaxTweakRounds = 4;85static const int MaxRefineRounds = 3;8687static MSInt16 QuantizeSingleEndpointElementSigned(const MSInt16 &elem2CL, int precision, const ParallelMath::RoundUpForScope* ru);88static MUInt15 QuantizeSingleEndpointElementUnsigned(const MUInt15 &elem, int precision, const ParallelMath::RoundUpForScope* ru);89static void UnquantizeSingleEndpointElementSigned(const MSInt16 &comp, int precision, MSInt16 &outUnquantized, MSInt16 &outUnquantizedFinished2CL);90static void UnquantizeSingleEndpointElementUnsigned(const MUInt15 &comp, int precision, MUInt16 &outUnquantized, MUInt16 &outUnquantizedFinished);91static void QuantizeEndpointsSigned(const MSInt16 endPoints[2][3], const MFloat floatPixelsColorSpace[16][3], const MFloat floatPixelsLinearWeighted[16][3], MAInt16 quantizedEndPoints[2][3], MUInt15 indexes[16], IndexSelectorHDR<3> &indexSelector, int fixupIndex, int precision, int indexRange, const float *channelWeights, bool fastIndexing, const ParallelMath::RoundTowardNearestForScope *rtn);92static void QuantizeEndpointsUnsigned(const MSInt16 endPoints[2][3], const MFloat floatPixelsColorSpace[16][3], const MFloat floatPixelsLinearWeighted[16][3], MAInt16 quantizedEndPoints[2][3], MUInt15 indexes[16], IndexSelectorHDR<3> &indexSelector, int fixupIndex, int precision, int indexRange, const float *channelWeights, bool fastIndexing, const ParallelMath::RoundTowardNearestForScope *rtn);93static void EvaluatePartitionedLegality(const MAInt16 ep0[2][3], const MAInt16 ep1[2][3], int aPrec, const int bPrec[3], bool isTransformed, MAInt16 outEncodedEPs[2][2][3], ParallelMath::Int16CompFlag& outIsLegal);94static void EvaluateSingleLegality(const MAInt16 ep[2][3], int aPrec, const int bPrec[3], bool isTransformed, MAInt16 outEncodedEPs[2][3], ParallelMath::Int16CompFlag& outIsLegal);95static void SignExtendSingle(int &v, int bits);96};97}98}99100101