Skip to content

Commit

Permalink
rdo-partitions precedes no-multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
YunHsiao committed Apr 9, 2024
1 parent a428388 commit f09cf0a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 44 deletions.
5 changes: 0 additions & 5 deletions Source/astcenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,6 @@ struct astcenc_config
*/
bool rdo_enabled;

/**
* @brief Disable RDO multithreading (slightly higher compression, deterministic).
*/
bool rdo_no_multithreading;

/**
* @brief RDO quality scalar (lambda).
*/
Expand Down
38 changes: 8 additions & 30 deletions Source/astcenc_rate_distortion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,12 @@ static constexpr uint32_t ASTCENC_BYTES_PER_BLOCK = 16;

template<typename T> T sqr(T v) { return v * v; }

extern "C" void progress_emitter(float value);

extern "C" void rdo_progress_emitter(
float value
) {
static float previous_value = 100.0f;
const uint32_t bar_size = 25;
auto parts = static_cast<uint32_t>(value / 4.0f);

char buffer[bar_size + 3];
buffer[0] = '[';

for (uint32_t i = 0; i < parts; i++)
{
buffer[i + 1] = '=';
}

for (uint32_t i = parts; i < bar_size; i++)
{
buffer[i + 1] = ' ';
}

buffer[bar_size + 1] = ']';
buffer[bar_size + 2] = '\0';

if (previous_value == 100.0f)
{
printf("\n\n");
Expand All @@ -69,8 +52,7 @@ extern "C" void rdo_progress_emitter(
}
previous_value = value;

printf(" Progress: %s %03.1f%%\r", buffer, static_cast<double>(value));
fflush(stdout);
progress_emitter(value);
}

static uint32_t init_rdo_context(
Expand Down Expand Up @@ -419,15 +401,11 @@ void rate_distortion_optimize(
uint32_t zblocks = (image.dim_z + ctx.bsd->zdim - 1u) / ctx.bsd->zdim;
uint32_t total_blocks = xblocks * yblocks * zblocks;

uint32_t blocks_per_task = total_blocks;
if (!ctx.config.rdo_no_multithreading)
{
blocks_per_task = astc::min(ctx.config.rdo_lookback, total_blocks);
// There is no way to losslessly partition the job (sequentially dependent on previous output)
// So we reserve only one task for each thread to minimize the quality impact.
uint32_t partitions = ctx.config.rdo_partitions ? ctx.config.rdo_partitions : ctx.thread_count;
blocks_per_task = astc::max(blocks_per_task, (total_blocks - 1) / partitions + 1);
}
uint32_t blocks_per_task = astc::min(ctx.config.rdo_lookback, total_blocks);
// There is no way to losslessly partition the job (sequentially dependent on previous output)
// So we reserve up to one task for each thread to minimize the quality impact.
uint32_t partitions = ctx.config.rdo_partitions ? ctx.config.rdo_partitions : ctx.thread_count;
blocks_per_task = astc::max(blocks_per_task, (total_blocks - 1) / partitions + 1);

uint32_t total_modified = 0;
while (true)
Expand Down
6 changes: 0 additions & 6 deletions Source/astcenccli_toplevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,11 +1180,6 @@ static int edit_astcenc_config(
argidx += 1;
config.rdo_enabled = true;
}
else if (!strcmp(argv[argidx], "-rdo-no-multithreading"))
{
argidx += 1;
config.rdo_no_multithreading = true;
}
else if (!strcmp(argv[argidx], "-rdo-quality"))
{
argidx += 2;
Expand Down Expand Up @@ -1350,7 +1345,6 @@ static void print_astcenc_config(
printf(" Rate-distortion opt: %s\n", config.rdo_enabled ? "Enabled" : "Disabled");
if (config.rdo_enabled)
{
printf(" RDO multithreading: %s\n", config.rdo_no_multithreading ? "Disabled" : "Enabled");
printf(" RDO quality: %g\n", static_cast<double>(config.rdo_quality));
printf(" RDO lookback: %u blocks\n", config.rdo_lookback);
printf(" RDO max error scale: %g\n", static_cast<double>(config.rdo_max_smooth_block_error_scale));
Expand Down
3 changes: 0 additions & 3 deletions Source/astcenccli_toplevel_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ ADVANCED COMPRESSION
-rdo
Enable Rate Distortion Optimization (RDO) post-processing.
-rdo-no-multithreading
Disable RDO multithreading (slightly higher compression, deterministic).
-rdo-quality <factor>
RDO quality scalar (lambda). Lower values yield higher
quality/larger LZ compressed files, higher values yield lower
Expand Down

0 comments on commit f09cf0a

Please sign in to comment.