Skip to content

Commit 17da94b

Browse files
committed
Merge config for mode0 and refinment MSE overshoot
1 parent aa8250e commit 17da94b

3 files changed

Lines changed: 34 additions & 52 deletions

File tree

Source/astcenc.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -514,25 +514,15 @@ struct astcenc_config
514514
float tune_db_limit;
515515

516516
/**
517-
* @brief The amount of overshoot needed to early-out mode 0 fast path.
517+
* @brief The amount of MSE overshoot needed to early-out trials.
518518
*
519-
* We have a fast-path for mode 0 (1 partition, 1 plane) which uses only essential block modes
520-
* as an initial search. This can short-cut compression for simple blocks, but to avoid
521-
* short-cutting too much we force this to overshoot the MSE threshold needed to hit the
522-
* block-local db_limit e.g. 1.0 = no overshoot, 2.0 = need half the error to trigger.
523-
*/
524-
float tune_mode0_mse_overshoot;
525-
526-
/**
527-
* @brief The amount of overshoot needed to early-out refinement.
519+
* The first early-out is for 1 partition, 1 plane trials, where we try a minimal encode using
520+
* the high probability block modes. This can short-cut compression for simple blocks.
528521
*
529-
* The codec will refine block candidates iteratively to improve the encoding, based on the
530-
* @c tune_refinement_limit count. Earlier implementations will use all refinement iterations,
531-
* even if the target threshold is reached. This tuning parameter allows an early out, but with
532-
* an overshoot MSE threshold. Setting this to 1.0 will early-out as soon as the target is hit,
533-
* but does reduce image quality vs the default behavior of over-refinement.
522+
* The second early-out is for refinement trials, where we can exit refinement once quality is
523+
* reached.
534524
*/
535-
float tune_refinement_mse_overshoot;
525+
float tune_mse_overshoot;
536526

537527
/**
538528
* @brief The threshold for skipping 3.1/4.1 trials (-2partitionlimitfactor).

Source/astcenc_compress_symbolic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,13 @@ void compress_block(
12791279
// compression and slightly reduces image quality.
12801280

12811281
float errorval_mult[2] {
1282-
1.0f / ctx.config.tune_mode0_mse_overshoot,
1282+
1.0f / ctx.config.tune_mse_overshoot,
12831283
1.0f
12841284
};
12851285

1286-
static const float errorval_overshoot = 1.0f / ctx.config.tune_refinement_mse_overshoot;
1286+
static const float errorval_overshoot = 1.0f / ctx.config.tune_mse_overshoot;
12871287

1288-
// Only enable MODE0 fast path (trial 0) if 2D and more than 25 texels
1288+
// Only enable MODE0 fast path (trial 0) if 2D, and more than 25 texels
12891289
int start_trial = 1;
12901290
if ((bsd.texel_count >= TUNE_MIN_TEXELS_MODE0_FASTPATH) && (bsd.zdim == 1))
12911291
{

Source/astcenc_entry.cpp

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,89 +51,84 @@ struct astcenc_preset_config
5151
unsigned int tune_4partitioning_candidate_limit;
5252
float tune_db_limit_a_base;
5353
float tune_db_limit_b_base;
54-
float tune_mode0_mse_overshoot;
55-
float tune_refinement_mse_overshoot;
54+
float tune_mse_overshoot;
5655
float tune_2_partition_early_out_limit_factor;
5756
float tune_3_partition_early_out_limit_factor;
5857
float tune_2_plane_early_out_limit_correlation;
5958
};
6059

61-
6260
/**
63-
* @brief The static quality presets that are built-in for high bandwidth
64-
* presets (x < 25 texels per block).
61+
* @brief The static presets for high bandwidth encodings (x < 25 texels per block).
6562
*/
6663
static const std::array<astcenc_preset_config, 6> preset_configs_high {{
6764
{
6865
ASTCENC_PRE_FASTEST,
69-
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 3.5f, 1.0f, 1.0f, 0.85f
66+
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.85f
7067
}, {
7168
ASTCENC_PRE_FAST,
72-
3, 18, 10, 8, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 3.5f, 1.0f, 1.0f, 0.90f
69+
3, 18, 10, 8, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.90f
7370
}, {
7471
ASTCENC_PRE_MEDIUM,
75-
4, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 2.5f, 2.5f, 1.1f, 1.05f, 0.95f
72+
4, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 2.5f, 1.1f, 1.05f, 0.95f
7673
}, {
7774
ASTCENC_PRE_THOROUGH,
78-
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 10.0f, 1.35f, 1.15f, 0.97f
75+
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.35f, 1.15f, 0.97f
7976
}, {
8077
ASTCENC_PRE_VERYTHOROUGH,
81-
4, 256, 128, 64, 98, 4, 6, 20, 14, 8, 200.0f, 200.0f, 10.0f, 10.0f, 1.6f, 1.4f, 0.98f
78+
4, 256, 128, 64, 98, 4, 6, 20, 14, 8, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f
8279
}, {
8380
ASTCENC_PRE_EXHAUSTIVE,
84-
4, 512, 512, 512, 100, 4, 8, 32, 32, 32, 200.0f, 200.0f, 10.0f, 10.0f, 2.0f, 2.0f, 0.99f
81+
4, 512, 512, 512, 100, 4, 8, 32, 32, 32, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f
8582
}
8683
}};
8784

8885
/**
89-
* @brief The static quality presets that are built-in for medium bandwidth
90-
* presets (25 <= x < 64 texels per block).
86+
* @brief The static presets for medium bandwidth encodings (25 <= x < 64 texels per block).
9187
*/
9288
static const std::array<astcenc_preset_config, 6> preset_configs_mid {{
9389
{
9490
ASTCENC_PRE_FASTEST,
95-
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 3.5f, 1.0f, 1.0f, 0.80f
91+
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.80f
9692
}, {
9793
ASTCENC_PRE_FAST,
98-
3, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 3.5f, 1.0f, 1.0f, 0.85f
94+
3, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.85f
9995
}, {
10096
ASTCENC_PRE_MEDIUM,
101-
4, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.0f, 3.0f, 1.1f, 1.05f, 0.90f
97+
4, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.0f, 1.1f, 1.05f, 0.90f
10298
}, {
10399
ASTCENC_PRE_THOROUGH,
104-
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 10.0f, 1.4f, 1.2f, 0.95f
100+
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.4f, 1.2f, 0.95f
105101
}, {
106102
ASTCENC_PRE_VERYTHOROUGH,
107-
4, 256, 128, 64, 98, 4, 6, 12, 8, 3, 200.0f, 200.0f, 10.0f, 10.0f, 1.6f, 1.4f, 0.98f
103+
4, 256, 128, 64, 98, 4, 6, 12, 8, 3, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f
108104
}, {
109105
ASTCENC_PRE_EXHAUSTIVE,
110-
4, 256, 256, 256, 100, 4, 8, 32, 32, 32, 200.0f, 200.0f, 10.0f, 10.0f, 2.0f, 2.0f, 0.99f
106+
4, 256, 256, 256, 100, 4, 8, 32, 32, 32, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f
111107
}
112108
}};
113109

114110
/**
115-
* @brief The static quality presets that are built-in for low bandwidth
116-
* presets (64 <= x texels per block).
111+
* @brief The static presets for low bandwidth encodings (64 <= x texels per block).
117112
*/
118113
static const std::array<astcenc_preset_config, 6> preset_configs_low {{
119114
{
120115
ASTCENC_PRE_FASTEST,
121-
2, 10, 6, 4, 40, 2, 2, 2, 2, 2, 85.0f, 63.0f, 3.5f, 3.5f, 1.0f, 1.0f, 0.80f
116+
2, 10, 6, 4, 40, 2, 2, 2, 2, 2, 85.0f, 63.0f, 3.5f, 1.0f, 1.0f, 0.80f
122117
}, {
123118
ASTCENC_PRE_FAST,
124-
2, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.0f, 63.0f, 3.5f, 3.5f, 1.0f, 1.0f, 0.85f
119+
2, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.0f, 63.0f, 3.5f, 1.0f, 1.0f, 0.85f
125120
}, {
126121
ASTCENC_PRE_MEDIUM,
127-
3, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.5f, 3.5f, 1.1f, 1.05f, 0.90f
122+
3, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.5f, 1.1f, 1.05f, 0.90f
128123
}, {
129124
ASTCENC_PRE_THOROUGH,
130-
4, 82, 60, 30, 93, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 10.0f, 1.3f, 1.2f, 0.97f
125+
4, 82, 60, 30, 93, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.3f, 1.2f, 0.97f
131126
}, {
132127
ASTCENC_PRE_VERYTHOROUGH,
133-
4, 256, 128, 64, 98, 4, 6, 9, 5, 2, 200.0f, 200.0f, 10.0f, 10.0f, 1.6f, 1.4f, 0.98f
128+
4, 256, 128, 64, 98, 4, 6, 9, 5, 2, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f
134129
}, {
135130
ASTCENC_PRE_EXHAUSTIVE,
136-
4, 256, 256, 256, 100, 4, 8, 32, 32, 32, 200.0f, 200.0f, 10.0f, 10.0f, 2.0f, 2.0f, 0.99f
131+
4, 256, 256, 256, 100, 4, 8, 32, 32, 32, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f
137132
}
138133
}};
139134

@@ -444,8 +439,7 @@ static astcenc_error validate_config(
444439
config.tune_3partitioning_candidate_limit = astc::clamp(config.tune_3partitioning_candidate_limit, 1u, TUNE_MAX_PARTITIIONING_CANDIDATES);
445440
config.tune_4partitioning_candidate_limit = astc::clamp(config.tune_4partitioning_candidate_limit, 1u, TUNE_MAX_PARTITIIONING_CANDIDATES);
446441
config.tune_db_limit = astc::max(config.tune_db_limit, 0.0f);
447-
config.tune_mode0_mse_overshoot = astc::max(config.tune_mode0_mse_overshoot, 1.0f);
448-
config.tune_refinement_mse_overshoot = astc::max(config.tune_refinement_mse_overshoot, 1.0f);
442+
config.tune_mse_overshoot = astc::max(config.tune_mse_overshoot, 1.0f);
449443
config.tune_2_partition_early_out_limit_factor = astc::max(config.tune_2_partition_early_out_limit_factor, 0.0f);
450444
config.tune_3_partition_early_out_limit_factor = astc::max(config.tune_3_partition_early_out_limit_factor, 0.0f);
451445
config.tune_2_plane_early_out_limit_correlation = astc::max(config.tune_2_plane_early_out_limit_correlation, 0.0f);
@@ -568,8 +562,7 @@ astcenc_error astcenc_config_init(
568562
config.tune_db_limit = astc::max((*preset_configs)[start].tune_db_limit_a_base - 35 * ltexels,
569563
(*preset_configs)[start].tune_db_limit_b_base - 19 * ltexels);
570564

571-
config.tune_mode0_mse_overshoot = (*preset_configs)[start].tune_mode0_mse_overshoot;
572-
config.tune_refinement_mse_overshoot = (*preset_configs)[start].tune_refinement_mse_overshoot;
565+
config.tune_mse_overshoot = (*preset_configs)[start].tune_mse_overshoot;
573566

574567
config.tune_2_partition_early_out_limit_factor = (*preset_configs)[start].tune_2_partition_early_out_limit_factor;
575568
config.tune_3_partition_early_out_limit_factor =(*preset_configs)[start].tune_3_partition_early_out_limit_factor;
@@ -611,8 +604,7 @@ astcenc_error astcenc_config_init(
611604
config.tune_db_limit = astc::max(LERP(tune_db_limit_a_base) - 35 * ltexels,
612605
LERP(tune_db_limit_b_base) - 19 * ltexels);
613606

614-
config.tune_mode0_mse_overshoot = LERP(tune_mode0_mse_overshoot);
615-
config.tune_refinement_mse_overshoot = LERP(tune_refinement_mse_overshoot);
607+
config.tune_mse_overshoot = LERP(tune_mse_overshoot);
616608

617609
config.tune_2_partition_early_out_limit_factor = LERP(tune_2_partition_early_out_limit_factor);
618610
config.tune_3_partition_early_out_limit_factor = LERP(tune_3_partition_early_out_limit_factor);

0 commit comments

Comments
 (0)