// SPDX-License-Identifier: Apache-2.0 // ---------------------------------------------------------------------------- // Copyright 2011-2023 Arm Limited // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at: // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. // ---------------------------------------------------------------------------- /** * @brief Functions to generate block size descriptor and decimation tables. */ #include "astcenc_internal.h" /** * @brief Decode the properties of an encoded 2D block mode. * * @param block_mode The encoded block mode. * @param[out] x_weights The number of weights in the X dimension. * @param[out] y_weights The number of weights in the Y dimension. * @param[out] is_dual_plane True if this block mode has two weight planes. * @param[out] quant_mode The quantization level for the weights. * @param[out] weight_bits The storage bit count for the weights. * * @return Returns true if a valid mode, false otherwise. */ static bool decode_block_mode_2d( unsigned int block_mode, unsigned int& x_weights, unsigned int& y_weights, bool& is_dual_plane, unsigned int& quant_mode, unsigned int& weight_bits ) { … } /** * @brief Decode the properties of an encoded 3D block mode. * * @param block_mode The encoded block mode. * @param[out] x_weights The number of weights in the X dimension. * @param[out] y_weights The number of weights in the Y dimension. * @param[out] z_weights The number of weights in the Z dimension. * @param[out] is_dual_plane True if this block mode has two weight planes. * @param[out] quant_mode The quantization level for the weights. * @param[out] weight_bits The storage bit count for the weights. * * @return Returns true if a valid mode, false otherwise. */ static bool decode_block_mode_3d( unsigned int block_mode, unsigned int& x_weights, unsigned int& y_weights, unsigned int& z_weights, bool& is_dual_plane, unsigned int& quant_mode, unsigned int& weight_bits ) { … } /** * @brief Create a 2D decimation entry for a block-size and weight-decimation pair. * * @param x_texels The number of texels in the X dimension. * @param y_texels The number of texels in the Y dimension. * @param x_weights The number of weights in the X dimension. * @param y_weights The number of weights in the Y dimension. * @param[out] di The decimation info structure to populate. * @param[out] wb The decimation table init scratch working buffers. */ static void init_decimation_info_2d( unsigned int x_texels, unsigned int y_texels, unsigned int x_weights, unsigned int y_weights, decimation_info& di, dt_init_working_buffers& wb ) { … } /** * @brief Create a 3D decimation entry for a block-size and weight-decimation pair. * * @param x_texels The number of texels in the X dimension. * @param y_texels The number of texels in the Y dimension. * @param z_texels The number of texels in the Z dimension. * @param x_weights The number of weights in the X dimension. * @param y_weights The number of weights in the Y dimension. * @param z_weights The number of weights in the Z dimension. * @param[out] di The decimation info structure to populate. @param[out] wb The decimation table init scratch working buffers. */ static void init_decimation_info_3d( unsigned int x_texels, unsigned int y_texels, unsigned int z_texels, unsigned int x_weights, unsigned int y_weights, unsigned int z_weights, decimation_info& di, dt_init_working_buffers& wb ) { … } /** * @brief Assign the texels to use for kmeans clustering. * * The max limit is @c BLOCK_MAX_KMEANS_TEXELS; above this a random selection is used. * The @c bsd.texel_count is an input and must be populated beforehand. * * @param[in,out] bsd The block size descriptor to populate. */ static void assign_kmeans_texels( block_size_descriptor& bsd ) { … } /** * @brief Allocate a single 2D decimation table entry. * * @param x_texels The number of texels in the X dimension. * @param y_texels The number of texels in the Y dimension. * @param x_weights The number of weights in the X dimension. * @param y_weights The number of weights in the Y dimension. * @param bsd The block size descriptor we are populating. * @param wb The decimation table init scratch working buffers. * @param index The packed array index to populate. */ static void construct_dt_entry_2d( unsigned int x_texels, unsigned int y_texels, unsigned int x_weights, unsigned int y_weights, block_size_descriptor& bsd, dt_init_working_buffers& wb, unsigned int index ) { … } /** * @brief Allocate block modes and decimation tables for a single 2D block size. * * @param x_texels The number of texels in the X dimension. * @param y_texels The number of texels in the Y dimension. * @param can_omit_modes Can we discard modes that astcenc won't use, even if legal? * @param mode_cutoff Percentile cutoff in range [0,1]. Low values more likely to be used. * @param[out] bsd The block size descriptor to populate. */ static void construct_block_size_descriptor_2d( unsigned int x_texels, unsigned int y_texels, bool can_omit_modes, float mode_cutoff, block_size_descriptor& bsd ) { … } /** * @brief Allocate block modes and decimation tables for a single 3D block size. * * TODO: This function doesn't include all of the heuristics that we use for 2D block sizes such as * the percentile mode cutoffs. If 3D becomes more widely used we should look at this. * * @param x_texels The number of texels in the X dimension. * @param y_texels The number of texels in the Y dimension. * @param z_texels The number of texels in the Z dimension. * @param[out] bsd The block size descriptor to populate. */ static void construct_block_size_descriptor_3d( unsigned int x_texels, unsigned int y_texels, unsigned int z_texels, block_size_descriptor& bsd ) { … } /* See header for documentation. */ void init_block_size_descriptor( unsigned int x_texels, unsigned int y_texels, unsigned int z_texels, bool can_omit_modes, unsigned int partition_count_cutoff, float mode_cutoff, block_size_descriptor& bsd ) { … }