| 1 |
|
| 2 |
#pragma once |
| 3 |
#include "basisu_astc_helpers.h" |
| 4 |
|
| 5 |
namespace basist |
| 6 |
{ |
| 7 |
struct astc_blk |
| 8 |
{ |
| 9 |
uint8_t m_vals[16]; |
| 10 |
}; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
const float ASTC_HDR_MAX_VAL = 65216.0f; |
| 15 |
|
| 16 |
|
| 17 |
const uint32_t MAX_QLOG7 = 123; |
| 18 |
|
| 19 |
|
| 20 |
const uint32_t MAX_QLOG8 = 247; |
| 21 |
|
| 22 |
|
| 23 |
const uint32_t MAX_QLOG9 = 495; |
| 24 |
|
| 25 |
|
| 26 |
const uint32_t MAX_QLOG10 = 991; |
| 27 |
|
| 28 |
|
| 29 |
const uint32_t MAX_QLOG11 = 1983; |
| 30 |
|
| 31 |
|
| 32 |
const uint32_t MAX_QLOG12 = 3967; |
| 33 |
|
| 34 |
|
| 35 |
const uint32_t MAX_QLOG16 = 63487; |
| 36 |
const float MAX_QLOG16_VAL = 65504.0f; |
| 37 |
|
| 38 |
|
| 39 |
const uint32_t NUM_MODE11_ENDPOINTS = 6, NUM_MODE7_ENDPOINTS = 4; |
| 40 |
|
| 41 |
|
| 42 |
inline half_float qlog_to_half(uint32_t qlog, uint32_t bits) |
| 43 |
{ |
| 44 |
assert((bits >= 7U) && (bits <= 16U)); |
| 45 |
assert(qlog < (1U << bits)); |
| 46 |
|
| 47 |
int C = qlog << (16 - bits); |
| 48 |
return astc_helpers::qlog16_to_half(C); |
| 49 |
} |
| 50 |
|
| 51 |
void astc_hdr_core_init(); |
| 52 |
|
| 53 |
void decode_mode7_to_qlog12_ise20( |
| 54 |
const uint8_t* pEndpoints, |
| 55 |
int e[2][3], |
| 56 |
int* pScale); |
| 57 |
|
| 58 |
bool decode_mode7_to_qlog12( |
| 59 |
const uint8_t* pEndpoints, |
| 60 |
int e[2][3], |
| 61 |
int* pScale, |
| 62 |
uint32_t ise_endpoint_range); |
| 63 |
|
| 64 |
void decode_mode11_to_qlog12_ise20( |
| 65 |
const uint8_t* pEndpoints, |
| 66 |
int e[2][3]); |
| 67 |
|
| 68 |
bool decode_mode11_to_qlog12( |
| 69 |
const uint8_t* pEndpoints, |
| 70 |
int e[2][3], |
| 71 |
uint32_t ise_endpoint_range); |
| 72 |
|
| 73 |
bool transcode_bc6h_1subset(half_float h_e[3][2], const astc_helpers::log_astc_block& best_blk, bc6h_block& transcoded_bc6h_blk); |
| 74 |
bool transcode_bc6h_2subsets(uint32_t common_part_index, const astc_helpers::log_astc_block& best_blk, bc6h_block& transcoded_bc6h_blk); |
| 75 |
|
| 76 |
bool astc_hdr_transcode_to_bc6h(const astc_blk& src_blk, bc6h_block& dst_blk); |
| 77 |
bool astc_hdr_transcode_to_bc6h(const astc_helpers::log_astc_block& log_blk, bc6h_block& dst_blk); |
| 78 |
|
| 79 |
namespace astc_6x6_hdr |
| 80 |
{ |
| 81 |
const uint32_t MAX_ASTC_HDR_6X6_DIM = 32768; |
| 82 |
const int32_t REUSE_MAX_BUFFER_ROWS = 5; |
| 83 |
|
| 84 |
struct block_mode_desc |
| 85 |
{ |
| 86 |
bool m_dp; |
| 87 |
uint32_t m_cem; |
| 88 |
uint32_t m_num_partitions; |
| 89 |
uint32_t m_grid_x; |
| 90 |
uint32_t m_grid_y; |
| 91 |
|
| 92 |
|
| 93 |
uint32_t m_endpoint_ise_range; |
| 94 |
uint32_t m_weight_ise_range; |
| 95 |
|
| 96 |
|
| 97 |
uint32_t m_transcode_endpoint_ise_range; |
| 98 |
uint32_t m_transcode_weight_ise_range; |
| 99 |
|
| 100 |
uint32_t m_flags; |
| 101 |
int m_dp_channel; |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
const uint32_t BASIST_HDR_6X6_LEVEL0 = 1; |
| 106 |
const uint32_t BASIST_HDR_6X6_LEVEL1 = 2; |
| 107 |
const uint32_t BASIST_HDR_6X6_LEVEL2 = 4; |
| 108 |
|
| 109 |
const uint32_t TOTAL_BLOCK_MODE_DECS = 75; |
| 110 |
extern const block_mode_desc g_block_mode_descs[TOTAL_BLOCK_MODE_DECS]; |
| 111 |
|
| 112 |
void copy_weight_grid(bool dual_plane, uint32_t grid_x, uint32_t grid_y, const uint8_t* transcode_weights, astc_helpers::log_astc_block& decomp_blk); |
| 113 |
|
| 114 |
enum class encoding_type |
| 115 |
{ |
| 116 |
cInvalid = -1, |
| 117 |
cRun = 0, |
| 118 |
cSolid = 1, |
| 119 |
cReuse = 2, |
| 120 |
cBlock = 3, |
| 121 |
cTotal |
| 122 |
}; |
| 123 |
|
| 124 |
const uint32_t REUSE_XY_DELTA_BITS = 5; |
| 125 |
const uint32_t NUM_REUSE_XY_DELTAS = 1 << REUSE_XY_DELTA_BITS; |
| 126 |
|
| 127 |
struct reuse_xy_delta |
| 128 |
{ |
| 129 |
int8_t m_x, m_y; |
| 130 |
}; |
| 131 |
|
| 132 |
extern const reuse_xy_delta g_reuse_xy_deltas[NUM_REUSE_XY_DELTAS]; |
| 133 |
|
| 134 |
const uint32_t RUN_CODE = 0b000, RUN_CODE_LEN = 3; |
| 135 |
const uint32_t SOLID_CODE = 0b100, SOLID_CODE_LEN = 3; |
| 136 |
const uint32_t REUSE_CODE = 0b10, REUSE_CODE_LEN = 2; |
| 137 |
const uint32_t BLOCK_CODE = 0b1, BLOCK_CODE_LEN = 1; |
| 138 |
|
| 139 |
enum class endpoint_mode |
| 140 |
{ |
| 141 |
cInvalid = -1, |
| 142 |
|
| 143 |
cRaw = 0, |
| 144 |
cUseLeft, |
| 145 |
cUseUpper, |
| 146 |
cUseLeftDelta, |
| 147 |
cUseUpperDelta, |
| 148 |
|
| 149 |
cTotal |
| 150 |
}; |
| 151 |
|
| 152 |
enum class block_mode |
| 153 |
{ |
| 154 |
cInvalid = -1, |
| 155 |
|
| 156 |
cBMTotalModes = TOTAL_BLOCK_MODE_DECS |
| 157 |
}; |
| 158 |
|
| 159 |
const uint32_t NUM_ENDPOINT_DELTA_BITS = 5; |
| 160 |
|
| 161 |
const uint32_t NUM_UNIQUE_PARTITIONS2 = 521; |
| 162 |
extern const uint32_t g_part2_unique_index_to_seed[NUM_UNIQUE_PARTITIONS2]; |
| 163 |
|
| 164 |
const uint32_t NUM_UNIQUE_PARTITIONS3 = 333; |
| 165 |
extern const uint32_t g_part3_unique_index_to_seed[NUM_UNIQUE_PARTITIONS3]; |
| 166 |
|
| 167 |
bool decode_values(basist::bitwise_decoder& decoder, uint32_t total_values, uint32_t ise_range, uint8_t* pValues); |
| 168 |
|
| 169 |
void requantize_astc_weights(uint32_t n, const uint8_t* pSrc_ise_vals, uint32_t from_ise_range, uint8_t* pDst_ise_vals, uint32_t to_ise_range); |
| 170 |
|
| 171 |
void requantize_ise_endpoints(uint32_t cem, uint32_t src_ise_endpoint_range, const uint8_t* pSrc_endpoints, uint32_t dst_ise_endpoint_range, uint8_t* pDst_endpoints); |
| 172 |
|
| 173 |
const uint32_t BC6H_NUM_DIFF_ENDPOINT_MODES_TO_TRY_2 = 2; |
| 174 |
const uint32_t BC6H_NUM_DIFF_ENDPOINT_MODES_TO_TRY_4 = 4; |
| 175 |
const uint32_t BC6H_NUM_DIFF_ENDPOINT_MODES_TO_TRY_9 = 9; |
| 176 |
|
| 177 |
struct fast_bc6h_params |
| 178 |
{ |
| 179 |
uint32_t m_num_diff_endpoint_modes_to_try; |
| 180 |
uint32_t m_max_2subset_pats_to_try; |
| 181 |
|
| 182 |
bool m_hq_ls; |
| 183 |
bool m_brute_force_weight4_assignment; |
| 184 |
|
| 185 |
fast_bc6h_params() |
| 186 |
{ |
| 187 |
init(); |
| 188 |
} |
| 189 |
|
| 190 |
void init() |
| 191 |
{ |
| 192 |
m_hq_ls = true; |
| 193 |
m_num_diff_endpoint_modes_to_try = BC6H_NUM_DIFF_ENDPOINT_MODES_TO_TRY_2; |
| 194 |
m_max_2subset_pats_to_try = 1; |
| 195 |
m_brute_force_weight4_assignment = false; |
| 196 |
} |
| 197 |
}; |
| 198 |
|
| 199 |
void fast_encode_bc6h(const basist::half_float* pPixels, basist::bc6h_block* pBlock, const fast_bc6h_params ¶ms); |
| 200 |
|
| 201 |
bool decode_6x6_hdr(const uint8_t* pComp_data, uint32_t comp_data_size, basisu::vector2D<astc_helpers::astc_block>& decoded_blocks, uint32_t& width, uint32_t& height); |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
} |
| 206 |
|