Skip to content

Add BCn encoders/decoders with RDO support#1167

Draft
walcht wants to merge 6 commits intoKhronosGroup:mainfrom
walcht:add-BCn-decoder
Draft

Add BCn encoders/decoders with RDO support#1167
walcht wants to merge 6 commits intoKhronosGroup:mainfrom
walcht:add-BCn-decoder

Conversation

@walcht
Copy link
Copy Markdown

@walcht walcht commented May 7, 2026

As discussed in #1159: ktxTexture2_CompressBCn and ktxTexture2_DecodeBCn are introduced in this PR to allow libktx users/consumers to encode/decode BCn textures from/to raw decompressed formats.

I still haven't added the RDO post processing step and I will once I finalize testing (which is currently just partial).
https://github.com/richgel999/bc7enc_rdo does not support BC6HU/BC6HS encoding/decoding and also no BC2 (this format is essentially dead since BC3 replaces it). Anyways, even though the names are ktxTexture2_CompressBCn and ktxTexture2_DecodeBCn only BC1, BC3, BC4, BC5, and BC7 are supported (I can add BC6HU/BC6HS support in another PR).

This is still a somewhat early PR. Please feel free to give feedback, edit, and nitpick as much as possible.

Some context: I am adding KTX2 support to OIIO (PR: AcademySoftwareFoundation/OpenImageIO#5185) and having libktx encode/decode BCn formats significantly simplifies things (also ETC encoding/decoding which I can also open a PR for - if approved).

I haven't updated the KTX-Software-CTS with the added BCn test files.

Once this is finalized, this will address issue #587.

Current TODOs:

  • add CTS test files from a primary platform. As far as I understand, I shouldn't create/transcode KTX2 test files on non-primary platfroms (non arm64). I did do the testing on my local machine (see https://github.com/walcht/KTX-Software-CTS).
  • add RDO post processing step
  • add multithreading (only for encoder part; RDO already has multithreading integrated so here we are talking about the pre-processing step of encoding blocks).
  • add BCn encoding support for ktx encode command
  • add BCn decoding to PNG support for ktx extract command
  • agree on which parameters to expose in ktxBCnParams struct (apparently there are many and I am not qualified to know which subset to expose or to expose them all). For the moment I will just expose them all.
  • fix bc7enc_rdo compiler warnings (very simple to do, before merging git diff with original files so that we are 100% that we haven't changed anything).
  • finalize test cases (not CLI tests but rather libktx tests - e.g., texturetests, etc.).
  • enable SIMD acceleration for BC7 encoder (using ISPC - see https://github.com/ispc/ispc) (this should be straightforward and should be enabled by default via a CMake flag; e.g., BC7_SIMD).
  • test LIBKTX_FEATURE_BCN_DECODER CMake flag option

Note1: no LLMs/AI coding tools were used in any capacity whatsoever in writing or aiding in the writing of this PR.
Note2: I am an individual contributor (main reason I am contributing here is to add support for KTX2 in Blender).

Edit: TODO list edits

walcht and others added 4 commits May 5, 2026 17:01
Signed-off-by: Walid Chtioui <walid.chtioui.main@gmail.com>
Signed-off-by: Walid Chtioui <walid.chtioui.main@gmail.com>
*Add encode/decode tests (that use both CompressBCn/DecodeBCn)
*Add BCn ktx2 test files (transcoded from
tests/resources/ktx2/color_grid_uastc_zstd_5.ktx2)
*Cleanup BCn test fixtures
*Remove `std::cout` statement

Signed-off-by: Walid Chtioui <walid.chtioui.main@gmail.com>
@walcht walcht marked this pull request as draft May 7, 2026 14:11
@walcht
Copy link
Copy Markdown
Author

walcht commented May 7, 2026

There are also a lot of compiler warnings from bc7enc_rdo dependency. These should be straightforward to address directly in copied files from bc7enc_rdo.

walcht added 2 commits May 8, 2026 09:13
*Add BC1, BC3, BC4, BC5, and BC7 encoding support to "ktx encode"
command.
*Cleanup ktxBCnParams and add BC1/BC3 quality and mode params.
*Add docstrings/documentation to newly added enums/structs in ktx.h.

Signed-off-by: Walid Chtioui <walid.chtioui.main@gmail.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 8, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants