MCPcopy Create free account
hub / github.com/GPUOpen-Tools/compressonator / FindBestPattern

Method FindBestPattern

cmp_compressonatorlib/bc6h/bc6h_encode.cpp:886–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

884}
885
886float BC6HBlockEncoder::FindBestPattern(AMD_BC6H_Format& BC6H_data, bool TwoRegionShapes, int shape_pattern)
887{
888 // Index bit size for the patterns been used.
889 // All two zone shapes have 3 bits per color, max index value < 8
890 // All one zone shapes gave 4 bits per color, max index value < 16
891 int Index_BitSize = TwoRegionShapes ? 8 : 16;
892 int max_subsets = TwoRegionShapes ? 2 : 1;
893 float direction[NCHANNELS];
894 float step;
895
896 BC6H_data.region = (unsigned short)max_subsets;
897 BC6H_data.index = 0;
898 BC6H_data.d_shape_index = (unsigned short)shape_pattern;
899 memset(BC6H_data.partition, 0, sizeof(BC6H_data.partition));
900 memset(BC6H_data.shape_indices, 0, sizeof(BC6H_data.shape_indices));
901
902 // Get the pattern to encode with
903 Partition(shape_pattern, // Shape pattern we want to get
904 BC6H_data.din, // Input data
905 BC6H_data.partition, // Returns the patterned shape data
906 BC6H_data.entryCount, // counts the number of pixel used in each subset region num of 0's amd 1's
907 max_subsets, // Table Shapes to use eithe one regions 1 or two regions 2
908 3); // rgb no alpha always = 3
909
910 float error[MAX_SUBSETS] = {0.0, FLT_MAX, FLT_MAX};
911 int BestOutB = 0;
912 float BestError; //the lowest error from vector direction quantization
913 float BestError_endpts; //the lowest error from endpoints extracted from the vector direction quantization
914
915 float outB[2][2][MAX_SUBSET_SIZE][MAX_DIMENSION_BIG];
916 int shape_indicesB[2][MAX_SUBSETS][MAX_SUBSET_SIZE];
917
918 for (int subset = 0; subset < max_subsets; subset++)
919 {
920 error[0] += optQuantAnD_d(BC6H_data.partition[subset], // input data
921 BC6H_data.entryCount[subset], // number of input points above (not clear about 1, better to avoid)
922 Index_BitSize, // number of clusters on the ramp, 8 or 16
923 shape_indicesB[0][subset], // output index, if not all points of the ramp used, 0 may not be assigned
924 outB[0][subset], // resulting quantization
925 direction, // direction vector of the ramp (check normalization)
926 &step, // step size (check normalization)
927 3, // number of channels (always 3 = RGB for BC6H)
928 m_quality // Quality set number of retry to get good end points
929 // Max retries = MAX_TRY = 4000 when Quality is 1.0
930 // Min = 0 and default with quality 0.05 is 200 times
931 );
932 }
933
934 BestError = error[0];
935 BestOutB = 0;
936
937 // The following code is almost complete - runs very slow and not sure if % of improvement is justified..
938#ifdef USE_SHAKERHD
939 // Valid only for 2 region shapes
940 if ((max_subsets > 1) && (m_quality > 0.80))
941 {
942 int tempIndices[MAX_SUBSET_SIZE];
943 // int temp_epo_code[2][2][MAX_DIMENSION_BIG];

Callers

nothing calls this directly

Calls 8

memsetFunction · 0.85
memcpyFunction · 0.85
clampF16MaxFunction · 0.85
CalcShapeErrorFunction · 0.70
PartitionFunction · 0.50
optQuantAnD_dFunction · 0.50
ep_shaker_HDFunction · 0.50
GetEndPointsFunction · 0.50

Tested by

no test coverage detected