From 8b3da8589a8ed971afbbf162836e01bc5037f5be Mon Sep 17 00:00:00 2001 From: zhaonan287 Date: Tue, 21 May 2024 22:10:05 +0800 Subject: [PATCH] Fix astc-encoder4.7.0 bug Signed-off-by: zhaonan287 --- Source/astcenc_symbolic_physical.cpp | 76 ++++++++++++++-------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/Source/astcenc_symbolic_physical.cpp b/Source/astcenc_symbolic_physical.cpp index 21803e0..5f0db89 100644 --- a/Source/astcenc_symbolic_physical.cpp +++ b/Source/astcenc_symbolic_physical.cpp @@ -107,43 +107,8 @@ void symbolic_to_physical( uint8_t pcb[16] ) { assert(scb.block_type != SYM_BTYPE_ERROR); - const auto& bm = bsd.get_block_mode(scb.block_mode); - const auto& di = bsd.get_decimation_info(bm.decimation_mode); - int weight_count = di.weight_count; - quant_method weight_quant_method = bm.get_weight_quant_mode(); - float weight_quant_levels = static_cast(get_quant_level(weight_quant_method)); - const auto& qat = quant_and_xfer_tables[weight_quant_method]; - if (scb.privateProfile == HIGH_SPEED_PROFILE) - { - uint8_t weights[64]; - for (int i = 0; i < weight_count; i++) - { - float uqw = static_cast(scb.weights[i]); - float qw = (uqw / 64.0f) * (weight_quant_levels - 1.0f); - int qwi = static_cast(qw + 0.5f); - weights[i] = qat.scramble_map[qwi]; - } - uint8_t weightbuf[HIGH_SPEED_PROFILE_WEIGHT_BYTES] = {0}; - encode_ise(QUANT_6, HIGH_SPEED_PROFILE_WEIGHT_BYTES, weights, weightbuf, 0); - for (int i = 0; i < HIGH_SPEED_PROFILE_WEIGHT_BYTES; i++) - { - pcb[i] = static_cast(bitrev8(weightbuf[HIGH_SPEED_PROFILE_WEIGHT_BYTES - 1 - i])); - } - pcb[0] = 0x43; // the first byte of every block stream is 0x43 for HIGH_SPEED_PROFILE - pcb[1] = 0x80; // the second byte of every block stream is 0x80 for HIGH_SPEED_PROFILE - pcb[2] = 0x01; // the third (2 idx) byte of every block stream is 0x01 for HIGH_SPEED_PROFILE - uint8_t values_to_encode[HIGH_SPEED_PROFILE_COLOR_BYTES]; - for (int j = 0; j < HIGH_SPEED_PROFILE_COLOR_BYTES; j++) - { - values_to_encode[j] = scb.color_values[0][j]; - } - encode_ise(scb.get_color_quant_mode(), HIGH_SPEED_PROFILE_COLOR_BYTES, - values_to_encode, pcb, 17); // the color is starting from 17th bit for HIGH_SPEED_PROFILE - return; - } - // Constant color block using UNORM16 colors - if (scb.block_type == SYM_BTYPE_CONST_U16) + if (scb.block_type == SYM_BTYPE_CONST_U16 && scb.privateProfile != HIGH_SPEED_PROFILE) { // There is currently no attempt to coalesce larger void-extents static const uint8_t cbytes[8] { 0xFC, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; @@ -162,7 +127,7 @@ void symbolic_to_physical( } // Constant color block using FP16 colors - if (scb.block_type == SYM_BTYPE_CONST_F16) + if (scb.block_type == SYM_BTYPE_CONST_F16 && scb.privateProfile != HIGH_SPEED_PROFILE) { // There is currently no attempt to coalesce larger void-extents static const uint8_t cbytes[8] { 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; @@ -185,9 +150,44 @@ void symbolic_to_physical( // Compress the weights. // They are encoded as an ordinary integer-sequence, then bit-reversed uint8_t weightbuf[16] { 0 }; - + + const auto& bm = bsd.get_block_mode(scb.block_mode); + const auto& di = bsd.get_decimation_info(bm.decimation_mode); + int weight_count = di.weight_count; + quant_method weight_quant_method = bm.get_weight_quant_mode(); + float weight_quant_levels = static_cast(get_quant_level(weight_quant_method)); int is_dual_plane = bm.is_dual_plane; + const auto& qat = quant_and_xfer_tables[weight_quant_method]; + + if (scb.privateProfile == HIGH_SPEED_PROFILE) + { + uint8_t weights[64]; + for (int i = 0; i < weight_count; i++) + { + float uqw = static_cast(scb.weights[i]); + float qw = (uqw / 64.0f) * (weight_quant_levels - 1.0f); + int qwi = static_cast(qw + 0.5f); + weights[i] = qat.scramble_map[qwi]; + } + encode_ise(QUANT_6, HIGH_SPEED_PROFILE_WEIGHT_BYTES, weights, weightbuf, 0); + for (int i = 0; i < HIGH_SPEED_PROFILE_WEIGHT_BYTES; i++) + { + pcb[i] = static_cast(bitrev8(weightbuf[HIGH_SPEED_PROFILE_WEIGHT_BYTES - 1 - i])); + } + pcb[0] = 0x43; // the first byte of every block stream is 0x43 for HIGH_SPEED_PROFILE + pcb[1] = 0x80; // the second byte of every block stream is 0x80 for HIGH_SPEED_PROFILE + pcb[2] = 0x01; // the third (2 idx) byte of every block stream is 0x01 for HIGH_SPEED_PROFILE + uint8_t values_to_encode[HIGH_SPEED_PROFILE_COLOR_BYTES]; + for (int j = 0; j < HIGH_SPEED_PROFILE_COLOR_BYTES; j++) + { + values_to_encode[j] = scb.color_values[0][j]; + } + encode_ise(scb.get_color_quant_mode(), HIGH_SPEED_PROFILE_COLOR_BYTES, + values_to_encode, pcb, 17); // the color is starting from 17th bit for HIGH_SPEED_PROFILE + return; + } + int real_weight_count = is_dual_plane ? 2 * weight_count : weight_count; int bits_for_weights = get_ise_sequence_bitcount(real_weight_count, weight_quant_method); -- Gitee