mirror of
https://github.com/BinomialLLC/basis_universal.git
synced 2026-11-17 13:26:14 +00:00
Adding -clbench command line option, and a new API basis_benchmark_etc1s_opencl() to determine if OpenCL encoding is worthwhile on the current machine/driver/GPU.
This commit is contained in:
+31
-7
@@ -54,6 +54,7 @@ enum tool_mode
|
||||
cBench,
|
||||
cCompSize,
|
||||
cTest,
|
||||
cCLBench,
|
||||
cSplitImage,
|
||||
cCombineImages
|
||||
};
|
||||
@@ -365,6 +366,8 @@ public:
|
||||
m_mode = cCompSize;
|
||||
else if (strcasecmp(pArg, "-test") == 0)
|
||||
m_mode = cTest;
|
||||
else if (strcasecmp(pArg, "-clbench") == 0)
|
||||
m_mode = cCLBench;
|
||||
else if (strcasecmp(pArg, "-test_dir") == 0)
|
||||
{
|
||||
REMAINING_ARGS_CHECK(1);
|
||||
@@ -4266,7 +4269,7 @@ static bool test_mode(command_line_params& opts)
|
||||
size_t data_size = 0;
|
||||
|
||||
// Test ETC1S
|
||||
flags_and_quality = (opts.m_comp_params.m_multithreading ? cFlagThreaded : 0);
|
||||
flags_and_quality = (opts.m_comp_params.m_multithreading ? cFlagThreaded : 0) | cFlagPrintStats | cFlagPrintStatus;
|
||||
|
||||
void* pData = basis_compress(source_images, flags_and_quality, uastc_rdo_quality, &data_size, &stats);
|
||||
if (!pData)
|
||||
@@ -4293,7 +4296,7 @@ static bool test_mode(command_line_params& opts)
|
||||
|
||||
if (opencl_is_available())
|
||||
{
|
||||
flags_and_quality = (opts.m_comp_params.m_multithreading ? cFlagThreaded : 0) | cFlagUseOpenCL;
|
||||
flags_and_quality = (opts.m_comp_params.m_multithreading ? cFlagThreaded : 0) | cFlagUseOpenCL | cFlagPrintStats | cFlagPrintStatus;
|
||||
|
||||
pData = basis_compress(source_images, flags_and_quality, uastc_rdo_quality, &data_size, &stats);
|
||||
if (!pData)
|
||||
@@ -4329,7 +4332,7 @@ static bool test_mode(command_line_params& opts)
|
||||
}
|
||||
|
||||
// Test UASTC
|
||||
flags_and_quality = (opts.m_comp_params.m_multithreading ? cFlagThreaded : 0) | cFlagUASTC;
|
||||
flags_and_quality = (opts.m_comp_params.m_multithreading ? cFlagThreaded : 0) | cFlagUASTC | cFlagPrintStats | cFlagPrintStatus;
|
||||
|
||||
pData = basis_compress(source_images, flags_and_quality, uastc_rdo_quality, &data_size, &stats);
|
||||
if (!pData)
|
||||
@@ -4362,6 +4365,24 @@ static bool test_mode(command_line_params& opts)
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool clbench_mode(command_line_params& opts)
|
||||
{
|
||||
BASISU_NOTE_UNUSED(opts);
|
||||
|
||||
bool opencl_failed = false;
|
||||
bool use_cl = basis_benchmark_etc1s_opencl(&opencl_failed);
|
||||
if (use_cl)
|
||||
printf("OpenCL ETC1S encoding is faster on this machine\n");
|
||||
else
|
||||
{
|
||||
if (opencl_failed)
|
||||
printf("OpenCL failed!\n");
|
||||
printf("CPU ETC1S encoding is faster on this machine\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int main_internal(int argc, const char **argv)
|
||||
{
|
||||
printf("Basis Universal GPU Texture Compressor v" BASISU_TOOL_VERSION "\nCopyright (C) 2019-2022 Binomial LLC, All rights reserved\n");
|
||||
@@ -4374,7 +4395,7 @@ static int main_internal(int argc, const char **argv)
|
||||
bool opencl_force_serialization = false;
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (strcmp(argv[i], "-opencl") == 0)
|
||||
if ((strcmp(argv[i], "-opencl") == 0) || (strcmp(argv[i], "-clbench") == 0))
|
||||
use_opencl = true;
|
||||
if (strcmp(argv[i], "-opencl_serialize") == 0)
|
||||
opencl_force_serialization = true;
|
||||
@@ -4394,13 +4415,13 @@ static int main_internal(int argc, const char **argv)
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
printf("DEBUG build\n");
|
||||
#endif
|
||||
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
print_usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
command_line_params opts;
|
||||
if (!opts.parse(argc, argv))
|
||||
{
|
||||
@@ -4413,7 +4434,7 @@ static int main_internal(int argc, const char **argv)
|
||||
#else
|
||||
printf("Multithreading: %u, Zstandard support: %u, OpenCL: %u\n", (uint32_t)opts.m_comp_params.m_multithreading, basist::basisu_transcoder_supports_ktx2_zstd(), opencl_is_available());
|
||||
#endif
|
||||
|
||||
|
||||
if (!opts.process_listing_files())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
@@ -4459,6 +4480,9 @@ static int main_internal(int argc, const char **argv)
|
||||
case cTest:
|
||||
status = test_mode(opts);
|
||||
break;
|
||||
case cCLBench:
|
||||
status = clbench_mode(opts);
|
||||
break;
|
||||
case cSplitImage:
|
||||
status = split_image_mode(opts);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user