Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrechette committed Feb 8, 2024
1 parent 27a5186 commit ae17b1e
Show file tree
Hide file tree
Showing 3 changed files with 16,442 additions and 17 deletions.
74 changes: 74 additions & 0 deletions includes/acl/compression/impl/quantize.transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "acl/math/vector4_packing.h"
#include "acl/compression/impl/track_bit_rate_database.h"
#include "acl/compression/impl/transform_bit_rate_permutations.h"
#include "acl/compression/impl/transform_bit_rate_permutations2.h"
#include "acl/compression/impl/clip_context.h"
#include "acl/compression/impl/compression_stats.h"
#include "acl/compression/impl/sample_streams.h"
Expand Down Expand Up @@ -866,6 +867,8 @@ namespace acl
return rtm::scalar_cast(max_error);
}

#define ACL_IMPL_USE_DOF_QUANTIZATION

inline void calculate_local_space_bit_rates(quantization_context& context)
{
// To minimize the bit rate, we first start by trying every permutation in local space
Expand Down Expand Up @@ -897,6 +900,76 @@ namespace acl
uint32_t prev_transform_size = ~0U;
bool is_error_good_enough = false;

#if defined(ACL_IMPL_USE_DOF_QUANTIZATION)
const uint8_t* const bit_rate_permutations_per_dofs[] =
{
&acl_impl::k_local_bit_rate_permutations_1_dof[0][0],
&acl_impl::k_local_bit_rate_permutations_2_dof[0][0],
&acl_impl::k_local_bit_rate_permutations_3_dof[0][0],
};
const size_t num_bit_rate_permutations_per_dofs[] =
{
get_array_size(acl_impl::k_local_bit_rate_permutations_1_dof),
get_array_size(acl_impl::k_local_bit_rate_permutations_2_dof),
get_array_size(acl_impl::k_local_bit_rate_permutations_3_dof),
};

// Determine how many degrees of freedom we have to optimize our bit rates
uint32_t num_dof = 0;
num_dof += bone_bit_rates.rotation != k_invalid_bit_rate ? 1 : 0;
num_dof += bone_bit_rates.translation != k_invalid_bit_rate ? 1 : 0;
num_dof += bone_bit_rates.scale != k_invalid_bit_rate ? 1 : 0;

const uint8_t* bit_rate_permutations_per_dof = bit_rate_permutations_per_dofs[num_dof];
const size_t num_bit_rate_permutations = num_bit_rate_permutations_per_dofs[num_dof];

// Our desired bit rates start with the initial value
transform_bit_rates desired_bit_rates = bone_bit_rates;

size_t permutation_offset = 0;
for (size_t permutation_index = 0; permutation_index < num_bit_rate_permutations; ++permutation_index)
{
// If a bit rate is variable, grab a permutation for it
// We'll only consume as many bit rates as we have degrees of freedom

if (desired_bit_rates.rotation != k_invalid_bit_rate)
desired_bit_rates.rotation = bit_rate_permutations_per_dof[permutation_offset++];

if (desired_bit_rates.translation != k_invalid_bit_rate)
desired_bit_rates.translation = bit_rate_permutations_per_dof[permutation_offset++];

if (desired_bit_rates.scale != k_invalid_bit_rate)
desired_bit_rates.scale = bit_rate_permutations_per_dof[permutation_offset++];

const uint32_t rotation_size = get_num_bits_at_bit_rate(desired_bit_rates.rotation);
const uint32_t translation_size = get_num_bits_at_bit_rate(desired_bit_rates.translation);
const uint32_t scale_size = get_num_bits_at_bit_rate(desired_bit_rates.scale);
const uint32_t transform_size = rotation_size + translation_size + scale_size;

if (transform_size != prev_transform_size && is_error_good_enough)
{
// We already found the lowest transform size and we tried every permutation with that same size
break;
}

prev_transform_size = transform_size;

context.bit_rate_per_bone[bone_index] = desired_bit_rates;

const float error = calculate_max_error_at_bit_rate_local(context, bone_index, error_scan_stop_condition::until_error_too_high);

#if ACL_IMPL_DEBUG_VARIABLE_QUANTIZATION >= ACL_IMPL_DEBUG_LEVEL_VERBOSE_INFO
printf("%u: %u | %u | %u (%u) = %f\n", bone_index, desired_bit_rates.rotation, desired_bit_rates.translation, desired_bit_rates.scale, transform_size, error);
#endif

if (error < best_error)
{
best_error = error;
best_bit_rates = desired_bit_rates;
is_error_good_enough = error < error_threshold;
}
}
#else
if (context.has_scale)
{
const size_t num_permutations = get_array_size(acl_impl::k_local_bit_rate_permutations);
Expand Down Expand Up @@ -1027,6 +1100,7 @@ namespace acl
}
}
}
#endif

#if ACL_IMPL_DEBUG_VARIABLE_QUANTIZATION >= ACL_IMPL_DEBUG_LEVEL_BASIC_INFO
printf("%u: Best bit rates: %u | %u | %u\n", bone_index, best_bit_rates.rotation, best_bit_rates.translation, best_bit_rates.scale);
Expand Down
Loading

0 comments on commit ae17b1e

Please sign in to comment.