Skip to content

Commit 142e7ff

Browse files
committed
Use packed 2 plane weights in compression_working_buffers
1 parent d1f869a commit 142e7ff

4 files changed

Lines changed: 52 additions & 33 deletions

File tree

Source/astcenc_compress_symbolic.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -644,15 +644,15 @@ static float compress_symbolic_block_for_partition_2planes(
644644
ei1,
645645
eix1[i],
646646
di,
647-
dec_weights_ideal_value + (2 * i) * BLOCK_MAX_WEIGHTS,
648-
dec_weights_ideal_sig + (2 * i) * BLOCK_MAX_WEIGHTS);
647+
dec_weights_ideal_value + i * BLOCK_MAX_WEIGHTS,
648+
dec_weights_ideal_sig + i * BLOCK_MAX_WEIGHTS);
649649

650650
compute_ideal_weights_for_decimation(
651651
ei2,
652652
eix2[i],
653653
di,
654-
dec_weights_ideal_value + (2 * i + 1) * BLOCK_MAX_WEIGHTS,
655-
dec_weights_ideal_sig + (2 * i + 1) * BLOCK_MAX_WEIGHTS);
654+
dec_weights_ideal_value + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
655+
dec_weights_ideal_sig + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET);
656656
}
657657

658658
// Compute maximum colors for the endpoints and ideal weights, then for each endpoint and ideal
@@ -737,27 +737,27 @@ static float compress_symbolic_block_for_partition_2planes(
737737
di,
738738
weight_low_value1[i],
739739
weight_high_value1[i],
740-
dec_weights_ideal_value + BLOCK_MAX_WEIGHTS * (2 * decimation_mode),
741-
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * (2 * i),
742-
dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * (2 * i),
740+
dec_weights_ideal_value + BLOCK_MAX_WEIGHTS * decimation_mode,
741+
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * i,
742+
dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * i,
743743
bm.get_weight_quant_mode());
744744

745745
compute_quantized_weights_for_decimation(
746746
di,
747747
weight_low_value2[i],
748748
weight_high_value2[i],
749-
dec_weights_ideal_value + BLOCK_MAX_WEIGHTS * (2 * decimation_mode + 1),
750-
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * (2 * i + 1),
751-
dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * (2 * i + 1),
749+
dec_weights_ideal_value + BLOCK_MAX_WEIGHTS * decimation_mode + WEIGHTS_PLANE2_OFFSET,
750+
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * i + WEIGHTS_PLANE2_OFFSET,
751+
dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * i + WEIGHTS_PLANE2_OFFSET,
752752
bm.get_weight_quant_mode());
753753

754754
// Compute weight quantization errors for the block mode
755755
qwt_errors[i] = compute_error_of_weight_set_2planes(
756756
eix1[decimation_mode],
757757
eix2[decimation_mode],
758758
di,
759-
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * (2 * i),
760-
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * (2 * i + 1));
759+
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * i,
760+
dec_weights_quant_uvalue + BLOCK_MAX_WEIGHTS * i + WEIGHTS_PLANE2_OFFSET);
761761
}
762762

763763
// Decide the optimal combination of color endpoint encodings and weight encodings
@@ -806,8 +806,8 @@ static float compress_symbolic_block_for_partition_2planes(
806806

807807
symbolic_compressed_block workscb;
808808

809-
uint8_t* u8_weight1_src = dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * (2 * bm_packed_index);
810-
uint8_t* u8_weight2_src = dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * (2 * bm_packed_index + 1);
809+
uint8_t* u8_weight1_src = dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * bm_packed_index;
810+
uint8_t* u8_weight2_src = dec_weights_quant_pvalue + BLOCK_MAX_WEIGHTS * bm_packed_index + WEIGHTS_PLANE2_OFFSET;
811811

812812
for (int j = 0; j < di.weight_count; j++)
813813
{

Source/astcenc_ideal_endpoints_and_weights.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,8 @@ void recompute_ideal_colors_2planes(
13221322

13231323
const quantization_and_transfer_table *qat = &(quant_and_xfer_tables[weight_quant_mode]);
13241324

1325-
float dec_weights_quant_uvalue_plane1[BLOCK_MAX_WEIGHTS];
1326-
float dec_weights_quant_uvalue_plane2[BLOCK_MAX_WEIGHTS];
1325+
float dec_weights_quant_uvalue_plane1[BLOCK_MAX_WEIGHTS_2PLANE];
1326+
float dec_weights_quant_uvalue_plane2[BLOCK_MAX_WEIGHTS_2PLANE];
13271327

13281328
for (int i = 0; i < weight_count; i++)
13291329
{

Source/astcenc_internal.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ static constexpr uint8_t BLOCK_MAX_KMEANS_TEXELS { 64 };
8484
/** @brief The maximum number of weights a block can support. */
8585
static constexpr unsigned int BLOCK_MAX_WEIGHTS { 64 };
8686

87+
/** @brief The maximum number of weights a block can support per plane in 2 plane mode. */
88+
static constexpr unsigned int BLOCK_MAX_WEIGHTS_2PLANE { BLOCK_MAX_WEIGHTS / 2 };
89+
8790
/** @brief The minimum number of weight bits a candidate encoding must encode. */
8891
static constexpr unsigned int BLOCK_MIN_WEIGHT_BITS { 24 };
8992

@@ -97,7 +100,7 @@ static constexpr uint16_t BLOCK_BAD_BLOCK_MODE { 0xFFFFu };
97100
static constexpr unsigned int PARTITION_INDEX_BITS { 10 };
98101

99102
/** @brief The offset of the plane 2 weights in shared weight arrays. */
100-
static constexpr unsigned int WEIGHTS_PLANE2_OFFSET { BLOCK_MAX_WEIGHTS / 2 };
103+
static constexpr unsigned int WEIGHTS_PLANE2_OFFSET { BLOCK_MAX_WEIGHTS_2PLANE };
101104

102105
/** @brief The sum of quantized weights for one texel. */
103106
static constexpr float WEIGHTS_TEXEL_SUM { 16.0f };
@@ -1071,17 +1074,33 @@ struct alignas(ASTCENC_VECALIGN) compression_working_buffers
10711074
/** @brief The error weight block for the current thread. */
10721075
error_weight_block ewb;
10731076

1074-
/** @brief Decimated ideal weight values. */
1075-
alignas(ASTCENC_VECALIGN) float dec_weights_ideal_value[2 * WEIGHTS_MAX_DECIMATION_MODES * BLOCK_MAX_WEIGHTS];
1077+
/**
1078+
* @brief Decimated ideal weight values.
1079+
*
1080+
* For two plane encodings, second plane weights start at @c WEIGHTS_PLANE2_OFFSET offsets.
1081+
*/
1082+
alignas(ASTCENC_VECALIGN) float dec_weights_ideal_value[WEIGHTS_MAX_DECIMATION_MODES * BLOCK_MAX_WEIGHTS];
10761083

1077-
/** @brief Decimated ideal weight significance. */
1078-
alignas(ASTCENC_VECALIGN) float dec_weights_ideal_sig[2 * WEIGHTS_MAX_DECIMATION_MODES * BLOCK_MAX_WEIGHTS];
1084+
/**
1085+
* @brief Decimated ideal weight significance.
1086+
*
1087+
* For two plane encodings, second plane weights start at @c WEIGHTS_PLANE2_OFFSET offsets.
1088+
*/
1089+
alignas(ASTCENC_VECALIGN) float dec_weights_ideal_sig[WEIGHTS_MAX_DECIMATION_MODES * BLOCK_MAX_WEIGHTS];
10791090

1080-
/** @brief Decimated and quantized weight values stored in the unpacked quantized weight range. */
1081-
alignas(ASTCENC_VECALIGN) float dec_weights_quant_uvalue[2 * WEIGHTS_MAX_BLOCK_MODES * BLOCK_MAX_WEIGHTS];
1091+
/**
1092+
* @brief Decimated and quantized weight values stored in the unpacked quantized weight range.
1093+
*
1094+
* For two plane encodings, second plane weights start at @c WEIGHTS_PLANE2_OFFSET offsets.
1095+
*/
1096+
alignas(ASTCENC_VECALIGN) float dec_weights_quant_uvalue[WEIGHTS_MAX_BLOCK_MODES * BLOCK_MAX_WEIGHTS];
10821097

1083-
/** @brief Decimated and quantized weight values stored in the packed quantized weight range. */
1084-
alignas(ASTCENC_VECALIGN) uint8_t dec_weights_quant_pvalue[2 * WEIGHTS_MAX_BLOCK_MODES * BLOCK_MAX_WEIGHTS];
1098+
/**
1099+
* @brief Decimated and quantized weight values stored in the packed quantized weight range.
1100+
*
1101+
* For two plane encodings, second plane weights start at @c WEIGHTS_PLANE2_OFFSET offsets.
1102+
*/
1103+
alignas(ASTCENC_VECALIGN) uint8_t dec_weights_quant_pvalue[WEIGHTS_MAX_BLOCK_MODES * BLOCK_MAX_WEIGHTS];
10851104
};
10861105

10871106
/**

Source/astcenc_weight_align.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -607,28 +607,28 @@ void compute_angular_endpoints_2planes(
607607
{
608608
compute_angular_endpoints_for_quant_levels_lwc(
609609
weight_count,
610-
dec_weight_quant_uvalue + 2 * i * BLOCK_MAX_WEIGHTS,
611-
dec_weight_quant_sig + 2 * i * BLOCK_MAX_WEIGHTS,
610+
dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS,
611+
dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS,
612612
dm.maxprec_2planes, low_values1[i], high_values1[i]);
613613

614614
compute_angular_endpoints_for_quant_levels_lwc(
615615
weight_count,
616-
dec_weight_quant_uvalue + (2 * i + 1) * BLOCK_MAX_WEIGHTS,
617-
dec_weight_quant_sig + (2 * i + 1) * BLOCK_MAX_WEIGHTS,
616+
dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
617+
dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
618618
dm.maxprec_2planes, low_values2[i], high_values2[i]);
619619
}
620620
else
621621
{
622622
compute_angular_endpoints_for_quant_levels(
623623
weight_count,
624-
dec_weight_quant_uvalue + 2 * i * BLOCK_MAX_WEIGHTS,
625-
dec_weight_quant_sig + 2 * i * BLOCK_MAX_WEIGHTS,
624+
dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS,
625+
dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS,
626626
dm.maxprec_2planes, low_values1[i], high_values1[i]);
627627

628628
compute_angular_endpoints_for_quant_levels(
629629
weight_count,
630-
dec_weight_quant_uvalue + (2 * i + 1) * BLOCK_MAX_WEIGHTS,
631-
dec_weight_quant_sig + (2 * i + 1) * BLOCK_MAX_WEIGHTS,
630+
dec_weight_quant_uvalue + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
631+
dec_weight_quant_sig + i * BLOCK_MAX_WEIGHTS + WEIGHTS_PLANE2_OFFSET,
632632
dm.maxprec_2planes, low_values2[i], high_values2[i]);
633633
}
634634
}

0 commit comments

Comments
 (0)