-
Notifications
You must be signed in to change notification settings - Fork 306
Add BCn encoders/decoders with RDO support #1167
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
Open
walcht
wants to merge
93
commits into
KhronosGroup:main
Choose a base branch
from
walcht:add-BCn-decoder
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
306b578
Add initial BC1 decoder
walcht 12ab662
Add BC1, BC3, BC4, BC5, and BC7 decoding support to ktx extract command
walcht d3fdab2
Add BC1, BC3, BC4, BC5 and BC7 encoders and add encoder/decode tests
walcht 67facb3
Merge branch 'main' into add-BCn-decoder
walcht b036239
Add BCn encoding support for CLI command encode
walcht 6848b82
Merge branch 'add-BCn-decoder' of github.com:walcht/KTX-Software into…
walcht e569fc4
Fix/Suppress bc7enc_rdo warnings and point to forked CTS
walcht 4a6580d
Fix/Suppress unused variables/functions compilier warnings
walcht 9d0b0c2
Add BCn encoder support for command create and add additional tests
walcht bf153ca
Update CTS submodule commit pointer
walcht b2eec1b
Update CTS submodule
walcht 68bb0de
Temporary pre-integration of bc7enc_rdo as a 'subrepo'
walcht 7833c75
git subrepo clone --branch=changes_for_ktx https://github.com/Khronos…
walcht c04d97f
Add proper bc7enc_rdo 'subrepo' and add bc7enc_rdo to SPX reuse
walcht 236cc4d
Merge branch 'KhronosGroup:main' into add-BCn-decoder
walcht 389fa06
Merge branch 'add-BCn-decoder' of github.com:walcht/KTX-Software into…
walcht 81c2147
Add initial RDO support for BC1, BC3, and BC7 and fix encoder
walcht 8fcfe86
Remove bc7decomp_ref from external bc7enc_rdo dependency.
walcht a5a908e
Merge branch 'KhronosGroup:main' into add-BCn-decoder
walcht 185e09e
Use bc7f from basis universal instead of bc7enc_rdo's BC7 encoder.
walcht a94e536
Fix BC4, BC5 decoder issues; add BC4 RDO; Refactor bcn_codec.h\.cpp
walcht 39c868c
Add BC4 RDO support
walcht 109f301
Add BCn encoder multithreading (no RDO MT yet).
walcht c258c17
Add RDO multithreading; remove stack-allocated struct poitners from w…
walcht be98a77
Add initial BC6HU deconding and encoding support.
walcht f45f48c
Fix error message for BC6HU encoder format.
walcht b5f5900
Cleanup and refactor code; fix docstrings; add ktxBC1UnpackParams
walcht e819fb1
Refactor code; fix BC1 decoding/encoding; remove unsupported formats;…
walcht 208c52e
Remove bc7enc_rdo bc7decomp dependency and use Basisu's BC7 decoder
walcht d32bc78
Remove BC6HU/BC6HS decoders dependency and use Basisu's decoders instead
walcht 2874b44
Restructure bc7enc dependency; fix unused variable warnings; add BC2 …
walcht ee5c511
Fix ktxBCnParams initialization in testsuite; Add bc6hu test case
walcht fc7ce9c
Add proper BCn arguments handling/docs for ktx create/encode
walcht 0a7be33
Add RDO ultrasmooth block handling; add BC2 decoder to ktx extract
walcht 192a4cf
Fix BC1 encoder; Fix encoding of non-multiple-of-4 textures; Refactor…
walcht a526369
Add HDR cleanup for BC6HU encoder
walcht 8a95806
Update CTS tests
walcht b1b862f
Revert CTS tests submodule commit
walcht f66cd21
Merge branch 'main' into add-BCn-decoder
walcht d5bc0d9
Replace inconsistent use of size_t with uint32_t
walcht f7b3853
Fix Windows-related build issues
walcht bc7495a
Revert erroneous int to uint32_t conversion
walcht 31c5147
Fix BC1 RDO
walcht 5cd60a5
Update CTS submodule commit pointer
walcht 5224758
Fix warning C4201 on Windows platforms
walcht a23c016
Revert "Fix warning C4201 on Windows platforms"
walcht 4124521
Suppress warning C4201 on Windows platforms
walcht 9f74a0c
Remove xcpretty installation from MacOS CI
walcht a6799e9
Merge branch 'KhronosGroup:main' into add-BCn-decoder
walcht 2ed1708
Remove xcpretty and use "xcodebuild --quiet" instead
walcht b231714
Merge branch 'KhronosGroup:main' into add-BCn-decoder
walcht 7e22b39
Suppress deprecated warnings on Windows platforms
walcht 71d7efb
Add explicit uint64_t to uint32_t casts
walcht 5f58b7a
Update CTS submodule commit pointer
walcht 0903730
Fix types and update docstrings/cli docs
walcht 18f8451
Update CTS submodule commit pointer
walcht 57073f2
Update CTS submodule commit pointer
walcht f05f76f
Fix erroneous array access in RDO ultrasmooth blocks handling
walcht 93a7f34
Disable strict aliasing for bc7enc_rdo dependency
walcht ec4344c
Merge branch 'KhronosGroup:main' into add-BCn-decoder
walcht 8b18835
Add CI step to upload CTS output files if CTS fails
walcht 4e0d183
Record BCn options in ktx encode
walcht 905b224
Address strict aliasing violations that cause UBs
walcht fd08dcd
Fix BC3 RDO decoder; Disable strict aliasing
walcht 1e600f7
Add BCn create RDO tests
walcht a5b8e8f
Fix ktx encode BCn threadcount option
walcht 2a7a7bf
Increase tolerance for BCn encode-then-decode tests
walcht 29537d8
Fix BC1 texturetests
walcht 528fcee
Record missing options; Add ktx encode BCn documentation
walcht 9f49a9a
Add strict aliasing compilation note
walcht 69746fd
Fix RDO MT non determinism; Add extensive tests
walcht 03c12e5
Merge branch 'main' into add-BCn-decoder
walcht d73a216
Address reviews; Fix typos; Misc cleanup/refactoring
walcht 48c731c
Remove useless floor call
walcht 132e275
Add missing KTX_DECOMPRESS_FAILURE error string
walcht ffb7719
Only add -fno-strict-aliasing to non-MSVC compilers
walcht 0e15009
Clarify insert/extract block diagrams
walcht db54360
Fix upload CTS files on failure build steps
walcht 4e93ee3
Handle pending data load in BCn decoder
walcht 36f075a
Copy typeSize member in BCn decoder
walcht 88e8a18
Add '--skip-kvd' to ktxdiff
walcht 6103227
Convert BCn PNG UNORM input to linear colorspace
walcht dc1590e
Add ktxdiff to texturetests' BCn decode tests
walcht 7f568f3
Add '--normal-mode' to BC5 differential test file generation
walcht ce1e147
Add '--bcn-rdo-m' option to disable RDO multithreading
walcht ad74524
Update CTS submodule commit pointer
walcht e152314
Merge branch 'main' into add-BCn-decoder
walcht c563c84
Address misc review comments
walcht 2476fb6
Fix syntax error in texturetests and update CTS
walcht 41ea660
Merge branch 'main' into add-BCn-decoder
walcht 3cb6540
Update CTS submodule commit
walcht a4035f2
Add missing <algorithm> include
walcht 2b41ff9
Fix texturetests issues on Windows
walcht 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Copyright 2019-2020 The Khronos Group Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| add_library(bc7enc_rdo) | ||
| target_compile_features(bc7enc_rdo PUBLIC cxx_std_17) | ||
|
|
||
| # original bc7enc_rdo disables strict aliasing (see https://github.com/richgel999/bc7enc_rdo/blob/master/CMakeLists.txt) | ||
| # basisu also emphasises on compiling with '-fno-strict-aliasing' | ||
| if (NOT MSVC) | ||
| target_compile_options(bc7enc_rdo PRIVATE -fno-strict-aliasing) | ||
| endif() | ||
|
|
||
| target_sources(bc7enc_rdo | ||
| PRIVATE | ||
| ${CMAKE_CURRENT_LIST_DIR}/rgbcx.cpp # BC1, BC3, BC4 and BC5 encoders/decoders | ||
| ${CMAKE_CURRENT_LIST_DIR}/ert.cpp # RDO post processing step and some utils | ||
| ) | ||
|
|
||
| target_include_directories(bc7enc_rdo | ||
| PUBLIC | ||
| ${CMAKE_CURRENT_LIST_DIR}/ | ||
| ) |
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,19 @@ | ||
| MIT License Copyright (c) <year> <copyright holders> | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is furnished | ||
| to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice (including the next | ||
| paragraph) shall be included in all copies or substantial portions of the | ||
| Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS | ||
| OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF | ||
| OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,88 @@ | ||
| # About | ||
|
|
||
| This branch of bc7enc_rdo forked from [bc7enc_rdo][bc7enc_rdo] contains two | ||
| components used by KTX-Software with some changes: | ||
|
|
||
| - rgbcx: BC1, BC3, BC4, and BC5 encoders/decoders (+ added BC2 decoder). | ||
| - ert: rate distortion optimization (RDO) (agnostic to encoders/decoders). | ||
|
|
||
| Changes: | ||
|
|
||
| - added [[maybe_unused]] to silence compiler warnings about unused variables | ||
|
|
||
| Essentially: only what is absolutely necessary and not already provided by Basis | ||
| Universal is left. The following components have been removed: | ||
|
|
||
| - bc7 encoder/decoder. See [Notes][#Notes] below. | ||
| - CLI components. | ||
| - utils.h/cpp because it relies on some heavy classes. | ||
|
|
||
| Currently, the remaining two components are compiled together under a single | ||
| STATIC library bc7enc_rdo (if the need arises where only the RDO component is needed, | ||
| this will be separated into multiple libraries). | ||
|
|
||
| ## Building | ||
|
|
||
| This is intended to be built as a static library dependency (see minimal | ||
| CMakeLists.txt). | ||
|
|
||
| Somewhere in your project's CMakeLists: | ||
|
|
||
| ```bash | ||
| # Make sure bc7enc_rdo is built as a STATIC library | ||
| set(BUILD_SHARED_LIBS OFF) | ||
| add_subdirectory(path-to-bc7enc_rdo) | ||
| set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_RESET}) | ||
|
|
||
| # Then append it to your target's link dependencies | ||
| target_link_libraries(your_target PRIVATE bc7enc_rdo) | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| BC2 encoder is currently not implemented because practically it is very rarely | ||
| used (if at all) and can almost always be replaced with the more capable BC3 | ||
| format (which offers same color RGB block encoding as BC1 but with added alpha | ||
| support that is usually better than the one implemented by BC2). | ||
|
|
||
| BC6HU/BC6HS HDR formats are already originally not supported by this repo. | ||
| Basis Universal provides bc6hu (emphasis on the **u**) encoder and bc6hu/bc6hs decoders. | ||
|
|
||
| BC7 encoder/decoder is not included because Basis Universal already provides a | ||
| much more capable encoder (bc7f). | ||
|
|
||
| Notes about choice with BC1 vs. BC3 vs. BC7 (from Basisu wiki): | ||
|
|
||
| > bc7f encodes so rapidly (on average), that apart from lower VRAM consumption | ||
| > (4bpp vs. 8bpp) and better GPU texture cache efficiency, there's little need | ||
| > to use BC1 now. BC3 still has an advantage vs. BC7, because it very strongly | ||
| > separates how RGB is encoded from the alpha channel, in a predictable way. | ||
|
|
||
| ## Compilation Notes | ||
|
|
||
| **Makes sure to compile with `-fno-strict-aliasing`** since the original | ||
| bc7enc_rdo repo was mainly developed and tested on MSVC (which doesn't do | ||
| excessive optimizations including strict aliasing). | ||
|
|
||
| There are pointer conversions all over the place and if strict aliasing is | ||
| enabled, these conversions are most likely UB (see strict aliasing rule or type | ||
| punning). | ||
|
|
||
| This can be re-written a way that complies with strict aliasing but a lot of | ||
| `memcpy`s have to be added which will result in the code being significantly | ||
| less readable (also questionable if there is any benefit to this whatsoever). | ||
|
|
||
| ## TODOs | ||
|
|
||
| There are some features that I'd like to add (from most important to least): | ||
|
|
||
| 1. [] HDR RDO (this is possible but need to be extremely careful when changing | ||
| ert.cpp/h code to handle uint16_t instead of chars/uint8_t) | ||
| 1. [] BC2 encoder (even though it is seldom used) | ||
| 1. [] BC6HS encoder | ||
|
|
||
| ## License | ||
|
|
||
| MIT License Rich Geldreich. | ||
|
|
||
| [bc7enc_rdo]: https://github.com/richgel999/bc7enc_rdo.git) |
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,9 @@ | ||
| version = 1 | ||
| SPDX-PackageName = "bc7enc_rdo" | ||
| SPDX-PackageDownloadLocation = "https://github.com/richgel999/bc7enc_rdo" | ||
|
|
||
| [[annotations]] | ||
| path = "**" | ||
| precedence = "aggregate" | ||
| SPDX-FileCopyrightText = "2020-2021 Richard Geldreich, Jr. <richgel99@gmail.com>" | ||
| SPDX-License-Identifier = "MIT" |
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.
Uh oh!
There was an error while loading. Please reload this page.