Skip to content

Commit a428388

Browse files
committed
lookback param in blocks
1 parent b28da8d commit a428388

5 files changed

+65
-54
lines changed

Source/astcenc.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,9 @@ struct astcenc_config
587587
float rdo_quality;
588588

589589
/**
590-
* @brief RDO dictionary size in bytes.
590+
* @brief RDO lookback size in blocks.
591591
*/
592-
unsigned int rdo_dict_size;
592+
unsigned int rdo_lookback;
593593

594594
/**
595595
* @brief RDO task partitions.

Source/astcenc_entry.cpp

+23-25
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ struct astcenc_preset_config
5656
float tune_3partition_early_out_limit_factor;
5757
float tune_2plane_early_out_limit_correlation;
5858
float tune_search_mode0_enable;
59-
float rdo_quality;
60-
unsigned int rdo_dict_size;
59+
unsigned int rdo_lookback;
6160
};
6261

6362
/**
@@ -66,22 +65,22 @@ struct astcenc_preset_config
6665
static const std::array<astcenc_preset_config, 6> preset_configs_high {{
6766
{
6867
ASTCENC_PRE_FASTEST,
69-
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.85f, 0.0f, 4.0f, 256
68+
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.85f, 0.0f, 64
7069
}, {
7170
ASTCENC_PRE_FAST,
72-
3, 18, 10, 8, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.90f, 0.0f, 2.0f, 1024
71+
3, 18, 10, 8, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.90f, 0.0f, 128
7372
}, {
7473
ASTCENC_PRE_MEDIUM,
75-
4, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 2.5f, 1.1f, 1.05f, 0.95f, 0.0f, 1.0f, 4096
74+
4, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 2.5f, 1.1f, 1.05f, 0.95f, 0.0f, 256
7675
}, {
7776
ASTCENC_PRE_THOROUGH,
78-
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.35f, 1.15f, 0.97f, 0.0f, 0.5f, 4096
77+
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.35f, 1.15f, 0.97f, 0.0f, 256
7978
}, {
8079
ASTCENC_PRE_VERYTHOROUGH,
81-
4, 256, 128, 64, 98, 4, 6, 8, 6, 4, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f, 0.0f, 0.4f, 4096
80+
4, 256, 128, 64, 98, 4, 6, 8, 6, 4, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f, 0.0f, 256
8281
}, {
8382
ASTCENC_PRE_EXHAUSTIVE,
84-
4, 512, 512, 512, 100, 4, 8, 8, 8, 8, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f, 0.0f, 0.2f, 4096
83+
4, 512, 512, 512, 100, 4, 8, 8, 8, 8, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f, 0.0f, 256
8584
}
8685
}};
8786

@@ -91,22 +90,22 @@ static const std::array<astcenc_preset_config, 6> preset_configs_high {{
9190
static const std::array<astcenc_preset_config, 6> preset_configs_mid {{
9291
{
9392
ASTCENC_PRE_FASTEST,
94-
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.80f, 1.0f, 4.0f, 256
93+
2, 10, 6, 4, 43, 2, 2, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.80f, 1.0f, 64
9594
}, {
9695
ASTCENC_PRE_FAST,
97-
3, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.85f, 1.0f, 2.0f, 1024
96+
3, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.2f, 63.2f, 3.5f, 1.0f, 1.0f, 0.85f, 1.0f, 128
9897
}, {
9998
ASTCENC_PRE_MEDIUM,
100-
3, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.0f, 1.1f, 1.05f, 0.90f, 1.0f, 1.0f, 4096
99+
3, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.0f, 1.1f, 1.05f, 0.90f, 1.0f, 256
101100
}, {
102101
ASTCENC_PRE_THOROUGH,
103-
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.4f, 1.2f, 0.95f, 0.0f, 0.5f, 4096
102+
4, 82, 60, 30, 94, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.4f, 1.2f, 0.95f, 0.0f, 256
104103
}, {
105104
ASTCENC_PRE_VERYTHOROUGH,
106-
4, 256, 128, 64, 98, 4, 6, 8, 6, 3, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f, 0.0f, 0.4f, 4096
105+
4, 256, 128, 64, 98, 4, 6, 8, 6, 3, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f, 0.0f, 256
107106
}, {
108107
ASTCENC_PRE_EXHAUSTIVE,
109-
4, 256, 256, 256, 100, 4, 8, 8, 8, 8, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f, 0.0f, 0.2f, 4096
108+
4, 256, 256, 256, 100, 4, 8, 8, 8, 8, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f, 0.0f, 256
110109
}
111110
}};
112111

@@ -116,22 +115,22 @@ static const std::array<astcenc_preset_config, 6> preset_configs_mid {{
116115
static const std::array<astcenc_preset_config, 6> preset_configs_low {{
117116
{
118117
ASTCENC_PRE_FASTEST,
119-
2, 10, 6, 4, 40, 2, 2, 2, 2, 2, 85.0f, 63.0f, 3.5f, 1.0f, 1.0f, 0.80f, 1.0f, 4.0f, 256
118+
2, 10, 6, 4, 40, 2, 2, 2, 2, 2, 85.0f, 63.0f, 3.5f, 1.0f, 1.0f, 0.80f, 1.0f, 64
120119
}, {
121120
ASTCENC_PRE_FAST,
122-
2, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.0f, 63.0f, 3.5f, 1.0f, 1.0f, 0.85f, 1.0f, 2.0f, 1024
121+
2, 18, 12, 10, 55, 3, 3, 2, 2, 2, 85.0f, 63.0f, 3.5f, 1.0f, 1.0f, 0.85f, 1.0f, 128
123122
}, {
124123
ASTCENC_PRE_MEDIUM,
125-
3, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.5f, 1.1f, 1.05f, 0.90f, 1.0f, 1.0f, 4096
124+
3, 34, 28, 16, 77, 3, 3, 2, 2, 2, 95.0f, 70.0f, 3.5f, 1.1f, 1.05f, 0.90f, 1.0f, 256
126125
}, {
127126
ASTCENC_PRE_THOROUGH,
128-
4, 82, 60, 30, 93, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.3f, 1.2f, 0.97f, 1.0f, 0.5f, 4096
127+
4, 82, 60, 30, 93, 4, 4, 3, 2, 2, 105.0f, 77.0f, 10.0f, 1.3f, 1.2f, 0.97f, 1.0f, 256
129128
}, {
130129
ASTCENC_PRE_VERYTHOROUGH,
131-
4, 256, 128, 64, 98, 4, 6, 8, 5, 2, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f, 1.0f, 0.4f, 4096
130+
4, 256, 128, 64, 98, 4, 6, 8, 5, 2, 200.0f, 200.0f, 10.0f, 1.6f, 1.4f, 0.98f, 1.0f, 256
132131
}, {
133132
ASTCENC_PRE_EXHAUSTIVE,
134-
4, 256, 256, 256, 100, 4, 8, 8, 8, 8, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f, 1.0f, 0.2f, 4096
133+
4, 256, 256, 256, 100, 4, 8, 8, 8, 8, 200.0f, 200.0f, 10.0f, 2.0f, 2.0f, 0.99f, 1.0f, 256
135134
}
136135
}};
137136

@@ -415,7 +414,7 @@ static astcenc_error validate_config(
415414
config.tune_2plane_early_out_limit_correlation = astc::max(config.tune_2plane_early_out_limit_correlation, 0.0f);
416415

417416
config.rdo_quality = astc::clamp(config.rdo_quality, 0.001f, 50.0f);
418-
config.rdo_dict_size = astc::clamp(config.rdo_dict_size, 64u, 65536u);
417+
config.rdo_lookback = astc::clamp(config.rdo_lookback, 4u, 4096u);
419418
config.rdo_max_smooth_block_error_scale = astc::clamp(config.rdo_max_smooth_block_error_scale, 1.0f, 300.0f);
420419
config.rdo_max_smooth_block_std_dev = astc::clamp(config.rdo_max_smooth_block_std_dev, 0.01f, 65536.0f);
421420

@@ -535,8 +534,7 @@ astcenc_error astcenc_config_init(
535534
config.tune_3partition_early_out_limit_factor = (*preset_configs)[start].tune_3partition_early_out_limit_factor;
536535
config.tune_2plane_early_out_limit_correlation = (*preset_configs)[start].tune_2plane_early_out_limit_correlation;
537536
config.tune_search_mode0_enable = (*preset_configs)[start].tune_search_mode0_enable;
538-
config.rdo_quality = (*preset_configs)[start].rdo_quality;
539-
config.rdo_dict_size = (*preset_configs)[start].rdo_dict_size;
537+
config.rdo_lookback = (*preset_configs)[start].rdo_lookback;
540538
}
541539
// Start and end node are not the same - so interpolate between them
542540
else
@@ -576,13 +574,13 @@ astcenc_error astcenc_config_init(
576574
config.tune_3partition_early_out_limit_factor = LERP(tune_3partition_early_out_limit_factor);
577575
config.tune_2plane_early_out_limit_correlation = LERP(tune_2plane_early_out_limit_correlation);
578576
config.tune_search_mode0_enable = LERP(tune_search_mode0_enable);
579-
config.rdo_quality = LERP(rdo_quality);
580-
config.rdo_dict_size = LERPUI(rdo_dict_size);
577+
config.rdo_lookback = LERPUI(rdo_lookback);
581578
#undef LERP
582579
#undef LERPI
583580
#undef LERPUI
584581
}
585582

583+
config.rdo_quality = 0.5f;
586584
config.rdo_max_smooth_block_error_scale = 10.0f;
587585
config.rdo_max_smooth_block_std_dev = 18.0f;
588586

Source/astcenc_rate_distortion.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static uint32_t init_rdo_context(
9292
// Generate quality parameters
9393
auto& ert_params = rdo_ctx.m_ert_params;
9494
ert_params.m_lambda = ctx.config.rdo_quality;
95-
ert_params.m_lookback_window_size = ctx.config.rdo_dict_size;
95+
ert_params.m_lookback_window_size = ctx.config.rdo_lookback * ASTCENC_BYTES_PER_BLOCK;
9696
ert_params.m_smooth_block_max_mse_scale = ctx.config.rdo_max_smooth_block_error_scale;
9797
ert_params.m_max_smooth_block_std_dev = ctx.config.rdo_max_smooth_block_std_dev;
9898

@@ -422,7 +422,7 @@ void rate_distortion_optimize(
422422
uint32_t blocks_per_task = total_blocks;
423423
if (!ctx.config.rdo_no_multithreading)
424424
{
425-
blocks_per_task = astc::min(ctx.config.rdo_dict_size / ASTCENC_BYTES_PER_BLOCK, total_blocks);
425+
blocks_per_task = astc::min(ctx.config.rdo_lookback, total_blocks);
426426
// There is no way to losslessly partition the job (sequentially dependent on previous output)
427427
// So we reserve only one task for each thread to minimize the quality impact.
428428
uint32_t partitions = ctx.config.rdo_partitions ? ctx.config.rdo_partitions : ctx.thread_count;

Source/astcenccli_toplevel.cpp

+26-9
Original file line numberDiff line numberDiff line change
@@ -1179,12 +1179,6 @@ static int edit_astcenc_config(
11791179
{
11801180
argidx += 1;
11811181
config.rdo_enabled = true;
1182-
1183-
// Unpacking RDO trials blocks requires full initialization
1184-
if (static_cast<bool>(config.flags & ASTCENC_FLG_SELF_DECOMPRESS_ONLY))
1185-
{
1186-
config.flags &= ~ASTCENC_FLG_SELF_DECOMPRESS_ONLY;
1187-
}
11881182
}
11891183
else if (!strcmp(argv[argidx], "-rdo-no-multithreading"))
11901184
{
@@ -1200,6 +1194,7 @@ static int edit_astcenc_config(
12001194
return 1;
12011195
}
12021196

1197+
config.rdo_enabled = true;
12031198
config.rdo_quality = static_cast<float>(atof(argv[argidx - 1]));
12041199
}
12051200
else if (!strcmp(argv[argidx], "-rdo-dict-size"))
@@ -1211,7 +1206,20 @@ static int edit_astcenc_config(
12111206
return 1;
12121207
}
12131208

1214-
config.rdo_dict_size = atoi(argv[argidx - 1]);
1209+
config.rdo_enabled = true;
1210+
config.rdo_lookback = atoi(argv[argidx - 1]) / 16;
1211+
}
1212+
else if (!strcmp(argv[argidx], "-rdo-lookback"))
1213+
{
1214+
argidx += 2;
1215+
if (argidx > argc)
1216+
{
1217+
print_error("ERROR: -rdo-dict-size switch with no argument\n");
1218+
return 1;
1219+
}
1220+
1221+
config.rdo_enabled = true;
1222+
config.rdo_lookback = atoi(argv[argidx - 1]);
12151223
}
12161224
else if (!strcmp(argv[argidx], "-rdo-partitions"))
12171225
{
@@ -1222,6 +1230,7 @@ static int edit_astcenc_config(
12221230
return 1;
12231231
}
12241232

1233+
config.rdo_enabled = true;
12251234
config.rdo_partitions = atoi(argv[argidx - 1]);
12261235
}
12271236
else if (!strcmp(argv[argidx], "-rdo-max-smooth-block-error-scale"))
@@ -1233,6 +1242,7 @@ static int edit_astcenc_config(
12331242
return 1;
12341243
}
12351244

1245+
config.rdo_enabled = true;
12361246
config.rdo_max_smooth_block_error_scale = static_cast<float>(atof(argv[argidx - 1]));
12371247
}
12381248
else if (!strcmp(argv[argidx], "-rdo-max-smooth-block-std-dev"))
@@ -1244,6 +1254,7 @@ static int edit_astcenc_config(
12441254
return 1;
12451255
}
12461256

1257+
config.rdo_enabled = true;
12471258
config.rdo_max_smooth_block_std_dev = static_cast<float>(atof(argv[argidx - 1]));
12481259
}
12491260
else // check others as well
@@ -1341,10 +1352,10 @@ static void print_astcenc_config(
13411352
{
13421353
printf(" RDO multithreading: %s\n", config.rdo_no_multithreading ? "Disabled" : "Enabled");
13431354
printf(" RDO quality: %g\n", static_cast<double>(config.rdo_quality));
1344-
printf(" RDO dictionary size: %u bytes\n", config.rdo_dict_size);
1355+
printf(" RDO lookback: %u blocks\n", config.rdo_lookback);
13451356
printf(" RDO max error scale: %g\n", static_cast<double>(config.rdo_max_smooth_block_error_scale));
13461357
printf(" RDO max standard deviation: %g\n", static_cast<double>(config.rdo_max_smooth_block_std_dev));
1347-
if (config.rdo_partitions) printf(" RDO partitions: %u\n", cli_config.thread_count);
1358+
if (config.rdo_partitions) printf(" RDO partitions: %u\n", config.rdo_partitions);
13481359
}
13491360
printf("\n");
13501361
}
@@ -2070,6 +2081,12 @@ int astcenc_main(
20702081
return 1;
20712082
}
20722083

2084+
// Unpacking RDO trials blocks requires full initialization
2085+
if (config.rdo_enabled && static_cast<bool>(config.flags & ASTCENC_FLG_SELF_DECOMPRESS_ONLY))
2086+
{
2087+
config.flags &= ~ASTCENC_FLG_SELF_DECOMPRESS_ONLY;
2088+
}
2089+
20732090
// Enable progress callback if not in silent mode and using a terminal
20742091
#if defined(_WIN32)
20752092
int stdoutfno = _fileno(stdout);

Source/astcenccli_toplevel_help.cpp

+12-16
Original file line numberDiff line numberDiff line change
@@ -396,25 +396,21 @@ ADVANCED COMPRESSION
396396
RDO quality scalar (lambda). Lower values yield higher
397397
quality/larger LZ compressed files, higher values yield lower
398398
quality/smaller LZ compressed files. A good range to try is [.2,4].
399-
Full range is [.001,50.0]. Preset defaults are:
399+
Full range is [.001,50.0]. Default to 0.5.
400400
401-
-fastest : 4.0
402-
-fast : 2.0
403-
-medium : 1.0
404-
-thorough : 0.5
405-
-verythorough : 0.4
406-
-exhaustive : 0.2
401+
-rdo-lookback <number>
402+
RDO look back size in blocks. Lower values=faster,
403+
but give less compression. Range is [4,4096]. Preset defaults are:
404+
405+
-fastest : 64
406+
-fast : 128
407+
-medium : 256
408+
-thorough : 256
409+
-verythorough : 256
410+
-exhaustive : 256
407411
408412
-rdo-dict-size <number>
409-
RDO dictionary size in bytes. Lower values=faster,
410-
but give less compression. Range is [64,65536]. Preset defaults are:
411-
412-
-fastest : 256
413-
-fast : 1024
414-
-medium : 4096
415-
-thorough : 4096
416-
-verythorough : 4096
417-
-exhaustive : 4096
413+
Same as rdo-lookback, but in bytes.
418414
419415
-rdo-partitions <number>
420416
RDO task partitions. Default to current number of threads.

0 commit comments

Comments
 (0)