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