ConvectionKernels_BC67.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #include "ConvectionKernels_ParallelMath.h"
  3. namespace cvtt
  4. {
  5. namespace Tables
  6. {
  7. namespace BC7SC
  8. {
  9. struct Table;
  10. }
  11. }
  12. namespace Internal
  13. {
  14. namespace BC67
  15. {
  16. struct WorkInfo;
  17. }
  18. template<int TVectorSize>
  19. class IndexSelectorHDR;
  20. }
  21. struct PixelBlockU8;
  22. }
  23. namespace cvtt
  24. {
  25. namespace Internal
  26. {
  27. class BC7Computer
  28. {
  29. public:
  30. static void Pack(uint32_t flags, const PixelBlockU8* inputs, uint8_t* packedBlocks, const float channelWeights[4], const BC7EncodingPlan &encodingPlan, int numRefineRounds);
  31. static void UnpackOne(PixelBlockU8 &output, const uint8_t* packedBlock);
  32. private:
  33. static const int MaxTweakRounds = 4;
  34. typedef ParallelMath::SInt16 MSInt16;
  35. typedef ParallelMath::UInt15 MUInt15;
  36. typedef ParallelMath::UInt16 MUInt16;
  37. typedef ParallelMath::SInt32 MSInt32;
  38. typedef ParallelMath::Float MFloat;
  39. static void TweakAlpha(const MUInt15 original[2], int tweak, int range, MUInt15 result[2]);
  40. static void Quantize(MUInt15* color, int bits, int channels);
  41. static void QuantizeP(MUInt15* color, int bits, uint16_t p, int channels);
  42. static void Unquantize(MUInt15* color, int bits, int channels);
  43. static void CompressEndpoints0(MUInt15 ep[2][4], uint16_t p[2]);
  44. static void CompressEndpoints1(MUInt15 ep[2][4], uint16_t p);
  45. static void CompressEndpoints2(MUInt15 ep[2][4]);
  46. static void CompressEndpoints3(MUInt15 ep[2][4], uint16_t p[2]);
  47. static void CompressEndpoints4(MUInt15 epRGB[2][3], MUInt15 epA[2]);
  48. static void CompressEndpoints5(MUInt15 epRGB[2][3], MUInt15 epA[2]);
  49. static void CompressEndpoints6(MUInt15 ep[2][4], uint16_t p[2]);
  50. static void CompressEndpoints7(MUInt15 ep[2][4], uint16_t p[2]);
  51. static 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);
  52. static 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);
  53. static 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);
  54. template<class T>
  55. static void Swap(T& a, T& b);
  56. };
  57. class BC6HComputer
  58. {
  59. public:
  60. static void Pack(uint32_t flags, const PixelBlockF16* inputs, uint8_t* packedBlocks, const float channelWeights[4], bool isSigned, int numTweakRounds, int numRefineRounds);
  61. static void UnpackOne(PixelBlockF16 &output, const uint8_t *pBC, bool isSigned);
  62. private:
  63. typedef ParallelMath::Float MFloat;
  64. typedef ParallelMath::SInt16 MSInt16;
  65. typedef ParallelMath::UInt16 MUInt16;
  66. typedef ParallelMath::UInt15 MUInt15;
  67. typedef ParallelMath::AInt16 MAInt16;
  68. typedef ParallelMath::SInt32 MSInt32;
  69. typedef ParallelMath::UInt31 MUInt31;
  70. static const int MaxTweakRounds = 4;
  71. static const int MaxRefineRounds = 3;
  72. static MSInt16 QuantizeSingleEndpointElementSigned(const MSInt16 &elem2CL, int precision, const ParallelMath::RoundUpForScope* ru);
  73. static MUInt15 QuantizeSingleEndpointElementUnsigned(const MUInt15 &elem, int precision, const ParallelMath::RoundUpForScope* ru);
  74. static void UnquantizeSingleEndpointElementSigned(const MSInt16 &comp, int precision, MSInt16 &outUnquantized, MSInt16 &outUnquantizedFinished2CL);
  75. static void UnquantizeSingleEndpointElementUnsigned(const MUInt15 &comp, int precision, MUInt16 &outUnquantized, MUInt16 &outUnquantizedFinished);
  76. static 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);
  77. static 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);
  78. static 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);
  79. static void EvaluateSingleLegality(const MAInt16 ep[2][3], int aPrec, const int bPrec[3], bool isTransformed, MAInt16 outEncodedEPs[2][3], ParallelMath::Int16CompFlag& outIsLegal);
  80. static void SignExtendSingle(int &v, int bits);
  81. };
  82. }
  83. }