From 74f52b340158c5ed9ec90ffe07365c4bc723aefc Mon Sep 17 00:00:00 2001 From: zhaonan287 Date: Thu, 20 Jun 2024 22:39:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9Eastc-encoder=E5=9C=A8?= =?UTF-8?q?=E7=BC=BA=E5=B0=91astcCustomizedEncode=E5=BA=93=E6=97=B6?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E8=BF=94=E5=9B=9E=E9=A2=84=E6=9C=9F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaonan287 --- Source/astcenc.h | 5 ++++- Source/astcenc_block_sizes.cpp | 17 +++++++++++---- Source/astcenc_compress_symbolic.cpp | 9 ++++---- Source/astcenc_entry.cpp | 31 +++++++++++++++++++++------- Source/astcenc_internal.h | 4 ++-- 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Source/astcenc.h b/Source/astcenc.h index ffce903..8d8a816 100644 --- a/Source/astcenc.h +++ b/Source/astcenc.h @@ -264,7 +264,10 @@ enum astcenc_error { ASTCENC_ERR_DTRACE_FAILURE, #endif #if QUALITY_CONTROL - ASTCENC_ERR_BAD_QUALITY_CHECK + ASTCENC_ERR_BAD_QUALITY_CHECK, +#endif +#ifdef ASTC_CUSTOMIZED_ENABLE + ASTCENC_ERR_DLOPEN_FAILED #endif }; diff --git a/Source/astcenc_block_sizes.cpp b/Source/astcenc_block_sizes.cpp index 9e53ff2..23623e6 100644 --- a/Source/astcenc_block_sizes.cpp +++ b/Source/astcenc_block_sizes.cpp @@ -789,7 +789,7 @@ static void construct_dt_entry_2d( * @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( +static bool construct_block_size_descriptor_2d( QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -862,7 +862,11 @@ static void construct_block_size_descriptor_2d( g_astcCustomizedSoManager.isCustomizedBlockModeFunc_ == nullptr) { printf("astcenc customized so dlopen failed or isCustomizedBlockModeFunc_ is nullptr!\n"); - return; + delete wb; +#if !defined(ASTCENC_DECOMPRESS_ONLY) + delete[] percentiles; +#endif + return false; } if ((privateProfile == CUSTOMIZED_PROFILE) && (!g_astcCustomizedSoManager.isCustomizedBlockModeFunc_(i))) { @@ -997,6 +1001,7 @@ static void construct_block_size_descriptor_2d( assign_kmeans_texels(bsd); delete wb; + return true; } /** @@ -1182,7 +1187,7 @@ static void construct_block_size_descriptor_3d( } /* See header for documentation. */ -void init_block_size_descriptor( +bool init_block_size_descriptor( QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -1198,8 +1203,12 @@ void init_block_size_descriptor( } else { - construct_block_size_descriptor_2d(privateProfile, x_texels, y_texels, can_omit_modes, mode_cutoff, bsd); + if (!construct_block_size_descriptor_2d(privateProfile, x_texels, y_texels, can_omit_modes, mode_cutoff, bsd)) + { + return false; + } } init_partition_tables(bsd, can_omit_modes, partition_count_cutoff); + return true; } diff --git a/Source/astcenc_compress_symbolic.cpp b/Source/astcenc_compress_symbolic.cpp index df55d05..f1617a5 100644 --- a/Source/astcenc_compress_symbolic.cpp +++ b/Source/astcenc_compress_symbolic.cpp @@ -1175,7 +1175,7 @@ static float prepare_block_statistics( } /* See header for documentation. */ -void compress_block( +bool compress_block( const astcenc_contexti& ctx, const image_block& blk, uint8_t pcb[16], @@ -1219,7 +1219,7 @@ void compress_block( g_astcCustomizedSoManager.customizedMaxPartitionsFunc_ == nullptr) { printf("astcenc customized so dlopen failed or customizedMaxPartitionsFunc_ is nullptr!\n"); - return; + return false; } max_partitions = g_astcCustomizedSoManager.customizedMaxPartitionsFunc_(); } @@ -1299,7 +1299,7 @@ void compress_block( g_astcCustomizedSoManager.customizedBlockModeFunc_ == nullptr) { printf("astcenc customized so dlopen failed or customizedBlockModeFunc_ is nullptr!\n"); - return; + return false; } scb.block_mode = g_astcCustomizedSoManager.customizedBlockModeFunc_(); } @@ -1322,7 +1322,7 @@ void compress_block( *mseBlock[R_COM] = *mseBlock[G_COM] = *mseBlock[B_COM] = *mseBlock[A_COM] = 0; } #endif - return; + return true; } #if !defined(ASTCENC_DIAGNOSTICS) @@ -1556,6 +1556,7 @@ END_OF_TESTS: *mseBlock[A_COM] = colorSumDiff.lane<3>(); } #endif + return true; } #endif diff --git a/Source/astcenc_entry.cpp b/Source/astcenc_entry.cpp index 2126588..dc98655 100644 --- a/Source/astcenc_entry.cpp +++ b/Source/astcenc_entry.cpp @@ -706,11 +706,15 @@ astcenc_error astcenc_context_alloc( } bool can_omit_modes = static_cast(config.flags & ASTCENC_FLG_SELF_DECOMPRESS_ONLY); - init_block_size_descriptor(ctx->config.privateProfile, config.block_x, config.block_y, config.block_z, + if (!init_block_size_descriptor(ctx->config.privateProfile, config.block_x, config.block_y, config.block_z, can_omit_modes, config.tune_partition_count_limit, static_cast(config.tune_block_mode_limit) / 100.0f, - *ctx->bsd); + *ctx->bsd)) + { + delete ctxo; + return ASTCENC_ERR_DLOPEN_FAILED; + } #if !defined(ASTCENC_DECOMPRESS_ONLY) // Do setup only needed by compression @@ -788,7 +792,7 @@ void astcenc_context_free( * @param swizzle The input swizzle. * @param[out] buffer The output array for the compressed data. */ -static void compress_image( +static bool compress_image( astcenc_context& ctxo, unsigned int thread_index, const astcenc_image& image, @@ -947,14 +951,21 @@ static void compress_image( mseBlock[B_COM] = mse[B_COM] + offset; mseBlock[A_COM] = mse[A_COM] + offset; } - compress_block(ctx, blk, bp, temp_buffers, calQualityEnable, mseBlock); + if (!compress_block(ctx, blk, bp, temp_buffers, calQualityEnable, mseBlock)) + { + return false; + } #else - compress_block(ctx, blk, bp, temp_buffers); + if (!compress_block(ctx, blk, bp, temp_buffers)) + { + return false; + } #endif } ctxo.manage_compress.complete_task_assignment(count); } + return true; } /** @@ -1108,9 +1119,15 @@ astcenc_error astcenc_compress_image( // Wait for compute_averages to complete before compressing ctxo->manage_avg.wait(); #if QUALITY_CONTROL - compress_image(*ctxo, thread_index, image, *swizzle, data_out, calQualityEnable, mse); + if (!compress_image(*ctxo, thread_index, image, *swizzle, data_out, calQualityEnable, mse)) + { + return ASTCENC_ERR_DLOPEN_FAILED; + } #else - compress_image(*ctxo, thread_index, image, *swizzle, data_out); + if (!compress_image(*ctxo, thread_index, image, *swizzle, data_out)) + { + return ASTCENC_ERR_DLOPEN_FAILED; + } #endif // Wait for compress to complete before freeing memory ctxo->manage_compress.wait(); diff --git a/Source/astcenc_internal.h b/Source/astcenc_internal.h index 4d31a5f..eee376b 100644 --- a/Source/astcenc_internal.h +++ b/Source/astcenc_internal.h @@ -1262,7 +1262,7 @@ struct astcenc_contexti * @param mode_cutoff The block mode percentile cutoff [0-1]. * @param[out] bsd The descriptor to initialize. */ -void init_block_size_descriptor( +bool init_block_size_descriptor( QualityProfile privateProfile, unsigned int x_texels, unsigned int y_texels, @@ -2056,7 +2056,7 @@ void compute_angular_endpoints_2planes( * @param[out] pcb The physical compressed block output. * @param[out] tmpbuf Preallocated scratch buffers for the compressor. */ -void compress_block( +bool compress_block( const astcenc_contexti& ctx, const image_block& blk, uint8_t pcb[16], -- Gitee From 3d2ab7fb5580bda5d82cdd1b5a34a6c90eb9da0a Mon Sep 17 00:00:00 2001 From: zhaonan287 Date: Fri, 21 Jun 2024 10:50:23 +0800 Subject: [PATCH 2/2] Support MAC platform for astc-encoder customized profile Signed-off-by: zhaonan287 --- Source/astcenc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/astcenc.h b/Source/astcenc.h index 8d8a816..c948112 100644 --- a/Source/astcenc.h +++ b/Source/astcenc.h @@ -916,6 +916,8 @@ ASTCENC_PUBLIC const char* astcenc_get_error_string( #ifdef ASTC_CUSTOMIZED_ENABLE #if defined(_WIN32) && !defined(__CYGWIN__) const LPCSTR g_astcCustomizedSo = "libastcCustomizedEncode.dll"; +#elif defined(__APPLE__) +const std::string g_astcCustomizedSo = "libastcCustomizedEncode.dylib"; #elif defined(BUILD_HMOS_SDK) const std::string g_astcCustomizedSo = "libastcCustomizedEncode.so"; #else -- Gitee