-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Encode astc support #810
Closed
Closed
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
74a8199
Add missing backslahes to build_macos.sh
wasimabbas-arm 9000e0c
Move astc options out of create
wasimabbas-arm 4263d61
Add encode-astc support
wasimabbas-arm c4cc963
Shuffle around doxygen snippet and remove CMAKE_EXPORT_COMPILE_COMMANDS
wasimabbas-arm 24d0fee
Add decode method for astc textures that is used by psnr and ssim met…
wasimabbas-arm a925f3f
Remove tabs, replacing with 4 spaces each, fix bug with vkformat in a…
wasimabbas-arm b8ccb41
Minor typo fix
wasimabbas-arm c1b8938
Fix merge conflicts
wasimabbas-arm ba5a425
Fix SRGB asserts
wasimabbas-arm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Copyright 2022-2023 The Khronos Group Inc. | ||
// Copyright 2022-2023 RasterGrid Kft. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "command.h" | ||
#include "utility.h" | ||
#include <thread> | ||
|
||
namespace ktx { | ||
|
||
/** | ||
//! [command options_astc] | ||
<dl> | ||
<dt>\--astc-quality <level></dt> | ||
<dd>The quality level configures the quality-performance | ||
tradeoff for the compressor; more complete searches of the | ||
search space improve image quality at the expense of | ||
compression time. Default is 'medium'. The quality level can be | ||
set between fastest (0) and exhaustive (100) via the | ||
following fixed quality presets: | ||
<table> | ||
<tr><th>Level </th> <th> Quality </th></tr> | ||
<tr><td>fastest </td> <td>(equivalent to quality = 0) </td></tr> | ||
<tr><td>fast </td> <td>(equivalent to quality = 10) </td></tr> | ||
<tr><td>medium </td> <td>(equivalent to quality = 60) </td></tr> | ||
<tr><td>thorough </td> <td>(equivalent to quality = 98) </td></tr> | ||
<tr><td>exhaustive </td> <td>(equivalent to quality = 100) </td></tr> | ||
</table> | ||
</dd> | ||
<dt>\--astc-perceptual</dt> | ||
<dd>The codec should optimize for perceptual error, instead of | ||
direct RMS error. This aims to improve perceived image quality, | ||
but typically lowers the measured PSNR score. Perceptual | ||
methods are currently only available for normal maps and RGB | ||
color data.</dd> | ||
</dl> | ||
//! [command options_astc] | ||
*/ | ||
struct OptionsASTC : public ktxAstcParams { | ||
inline static const char* kAstcQuality = "astc-quality"; | ||
inline static const char* kAstcPerceptual = "astc-perceptual"; | ||
|
||
std::string astcOptions{}; | ||
bool encodeASTC = false; | ||
ClampedOption<ktx_uint32_t> qualityLevel{ktxAstcParams::qualityLevel, 0, KTX_PACK_ASTC_QUALITY_LEVEL_MAX}; | ||
|
||
OptionsASTC() : ktxAstcParams() { | ||
threadCount = std::thread::hardware_concurrency(); | ||
if (threadCount == 0) | ||
threadCount = 1; | ||
structSize = sizeof(ktxAstcParams); | ||
normalMap = false; | ||
for (int i = 0; i < 4; i++) | ||
inputSwizzle[i] = 0; | ||
qualityLevel.clear(); | ||
} | ||
|
||
void init(cxxopts::Options& opts) { | ||
opts.add_options("Encode ASTC") | ||
(kAstcQuality, | ||
"The quality level configures the quality-performance tradeoff for " | ||
"the compressor; more complete searches of the search space " | ||
"improve image quality at the expense of compression time. Default " | ||
"is 'medium'. The quality level can be set between fastest (0) and " | ||
"exhaustive (100) via the following fixed quality presets:\n\n" | ||
" Level | Quality\n" | ||
" ---------- | -----------------------------\n" | ||
" fastest | (equivalent to quality = 0)\n" | ||
" fast | (equivalent to quality = 10)\n" | ||
" medium | (equivalent to quality = 60)\n" | ||
" thorough | (equivalent to quality = 98)\n" | ||
" exhaustive | (equivalent to quality = 100)", | ||
cxxopts::value<std::string>(), "<level>") | ||
(kAstcPerceptual, | ||
"The codec should optimize for perceptual error, instead of direct " | ||
"RMS error. This aims to improve perceived image quality, but " | ||
"typically lowers the measured PSNR score. Perceptual methods are " | ||
"currently only available for normal maps and RGB color data."); | ||
} | ||
|
||
void captureASTCOption(const char* name) { | ||
astcOptions += fmt::format(" --{}", name); | ||
} | ||
|
||
template <typename T> | ||
T captureASTCOption(cxxopts::ParseResult& args, const char* name) { | ||
const T value = args[name].as<T>(); | ||
astcOptions += fmt::format(" --{} {}", name, value); | ||
return value; | ||
} | ||
|
||
void process(cxxopts::Options&, cxxopts::ParseResult& args, Reporter& report) { | ||
if (args[kAstcQuality].count()) { | ||
static std::unordered_map<std::string, ktx_pack_astc_quality_levels_e> astc_quality_mapping{ | ||
{"fastest", KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST}, | ||
{"fast", KTX_PACK_ASTC_QUALITY_LEVEL_FAST}, | ||
{"medium", KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM}, | ||
{"thorough", KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH}, | ||
{"exhaustive", KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE} | ||
}; | ||
const auto qualityLevelStr = to_lower_copy(captureASTCOption<std::string>(args, kAstcQuality)); | ||
const auto it = astc_quality_mapping.find(qualityLevelStr); | ||
if (it == astc_quality_mapping.end()) | ||
report.fatal_usage("Invalid astc-quality: \"{}\"", qualityLevelStr); | ||
qualityLevel = it->second; | ||
} else { | ||
qualityLevel = KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM; | ||
} | ||
|
||
if (args[kAstcPerceptual].count()) { | ||
captureASTCOption(kAstcPerceptual); | ||
perceptual = KTX_TRUE; | ||
} | ||
} | ||
}; | ||
|
||
} // namespace ktx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the <dl> should be here. Is it in the other snippets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In encode_utils.h it has, and from the source c4cc963#diff-8ca48860d1bd768774f38f0f522ba91ef7dbb887e660917c74b7088da850752aL604 where I brought this from, it had it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. When this PR is further along we can build the docs and check what it looks like. I'll leave this conversation open to remind us.