-
Notifications
You must be signed in to change notification settings - Fork 263
Refactor common options #817
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
Merged
MarkCallow
merged 21 commits into
KhronosGroup:main
from
wasimabbas-arm:refactor_common_options
May 1, 2024
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f557966
Abstract encode common options
wasimabbas-arm db37f0d
Removes OptionsCodec because these are all just basis options
wasimabbas-arm 4dc1223
Rename EncodeCodec to BasisCodec in preparation for separating encode…
wasimabbas-arm f77c969
Finally rename the utils file to basis_utils.h
wasimabbas-arm ca5113d
Updae cts tests part of rebase
wasimabbas-arm ac7446a
Rename compress_utils.h to deflate_utils.h
wasimabbas-arm 5a43fdf
Rename OptionsCodec to OptionsBasis
wasimabbas-arm 870f2f9
Fix bug, now the program will use ktxBasisParam's noSSE directly
wasimabbas-arm 844705e
Update cts tests
wasimabbas-arm 5de36e7
Rename encode_utils.h to basis_utils.h in doxygen
wasimabbas-arm f616910
Put noSSE back into common options
wasimabbas-arm 8475985
Fill codec common options separately for astc and basis in create
wasimabbas-arm dd12a5e
Further changes related to compress to deflate
wasimabbas-arm b33f540
Move astc options into astc_encode.h
wasimabbas-arm 4595078
Change options_codec to options_codec_basis after changing it in the …
wasimabbas-arm 3691222
Refactor Option names
wasimabbas-arm 8c6cb1d
Fix build issues
wasimabbas-arm 3bc9bfd
Merge branch 'main' into refactor_common_options
wasimabbas-arm 93f6d1f
Rename validateEncodeCodec to validateBasisCodec
wasimabbas-arm 1018e31
Rename captureCodeOption to captureCommonOption
wasimabbas-arm cf0617e
Documentation adition for no-sse
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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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,114 @@ | ||
// Copyright 2022-2023 The Khronos Group Inc. | ||
// Copyright 2022-2023 RasterGrid Kft. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "command.h" | ||
#include "utility.h" | ||
|
||
#include <thread> | ||
#include <unordered_map> | ||
|
||
// ------------------------------------------------------------------------------------------------- | ||
|
||
namespace ktx { | ||
|
||
/** | ||
//! [command options_codec_common] | ||
<dt> | ||
common: | ||
</dt> | ||
<dd> | ||
Common options. | ||
</dd> | ||
|
||
<dl> | ||
<dt>\--normal-mode</dt> | ||
<dd>Only valid for linear textures with two or more components. | ||
If the input texture has three or four linear components it is | ||
assumed to be a three component linear normal map storing unit | ||
length normals as (R=X, G=Y, B=Z). A fourth component will be | ||
ignored. The map will be converted to a two component X+Y | ||
normal map stored as (RGB=X, A=Y) prior to encoding. If unsure | ||
that your normals are unit length, use @b --normalize. If the | ||
input has 2 linear components it is assumed to be an X+Y map | ||
of unit normals. | ||
|
||
The Z component can be recovered programmatically in shader | ||
code by using the equations: | ||
<pre> | ||
nml.xy = texture(...).ga; // Load in [0,1] | ||
nml.xy = nml.xy * 2.0 - 1.0; // Unpack to [-1,1] | ||
nml.z = sqrt(1 - dot(nml.xy, nml.xy)); // Compute Z | ||
</pre> | ||
For ETC1S / BasisLZ encoding, @b '--encode basis-lz', RDO is disabled | ||
(no selector RDO, no endpoint RDO) to provide better quality.</dd> | ||
<dt>\--threads <count></dt> | ||
<dd>Explicitly set the number of threads to use during | ||
compression. By default, ETC1S / BasisLZ will use the number of | ||
threads reported by thread::hardware_concurrency or 1 if value | ||
returned is 0.</dd> | ||
</dl> | ||
//! [command options_codec_common] | ||
*/ | ||
struct OptionsCodecCommon { | ||
inline static const char* kNormalMode = "normal-mode"; | ||
inline static const char* kThreads = "threads"; | ||
|
||
std::string commonOptions{}; | ||
bool normalMap{false}; | ||
ktx_uint32_t threadCount{1}; | ||
|
||
OptionsCodecCommon() { | ||
threadCount = std::clamp<ktx_uint32_t>(threadCount, std::thread::hardware_concurrency(), 10000); | ||
} | ||
|
||
void init(cxxopts::Options& opts) { | ||
opts.add_options("Encode common") | ||
(kNormalMode, "Optimizes for encoding textures with normal data. If the input texture has " | ||
"three or four linear components it is assumed to be a three component linear normal " | ||
"map storing unit length normals as (R=X, G=Y, B=Z). A fourth component will be ignored. " | ||
"The map will be converted to a two component X+Y normal map stored as (RGB=X, A=Y) " | ||
"prior to encoding. If unsure that your normals are unit length, use --normalize. " | ||
"If the input has 2 linear components it is assumed to be an X+Y map of unit normals.\n" | ||
"The Z component can be recovered programmatically in shader code by using the equations:\n" | ||
" nml.xy = texture(...).ga; // Load in [0,1]\n" | ||
" nml.xy = nml.xy * 2.0 - 1.0; // Unpack to [-1,1]\n" | ||
" nml.z = sqrt(1 - dot(nml.xy, nml.xy)); // Compute Z\n" | ||
"ETC1S / BasisLZ encoding, RDO is disabled (no selector RDO, no endpoint RDO) to provide better quality.") | ||
(kThreads, "Sets the number of threads to use during encoding. By default, encoding " | ||
"will use the number of threads reported by thread::hardware_concurrency or 1 if " | ||
"value returned is 0.", cxxopts::value<uint32_t>(), "<count>"); | ||
} | ||
|
||
void captureCodecOption(const char* name) { | ||
MarkCallow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
commonOptions += fmt::format(" --{}", name); | ||
} | ||
|
||
template <typename T> | ||
T captureCodecOption(cxxopts::ParseResult& args, const char* name) { | ||
const T value = args[name].as<T>(); | ||
commonOptions += fmt::format(" --{} {}", name, value); | ||
return value; | ||
} | ||
|
||
void process(cxxopts::Options&, cxxopts::ParseResult& args, Reporter&) { | ||
if (args[kNormalMode].count()) { | ||
captureCodecOption(kNormalMode); | ||
normalMap = true; | ||
} | ||
|
||
if (args[kThreads].count()) { | ||
threadCount = captureCodecOption<uint32_t>(args, kThreads); | ||
} | ||
} | ||
}; | ||
|
||
template <typename Options, typename Codec> | ||
void fillCodecOptions(Options &options) { | ||
options.Codec::threadCount = options.OptionsCodecCommon::threadCount; | ||
options.Codec::normalMap = options.OptionsCodecCommon::normalMap; | ||
} | ||
|
||
} // namespace ktx |
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.
Uh oh!
There was an error while loading. Please reload this page.