-
Notifications
You must be signed in to change notification settings - Fork 622
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
[Codecs] BC4 support #1495
[Codecs] BC4 support #1495
Conversation
Right now our GPU compressed texture handling is really not all that great. For decoding we don't support any of the newer formats like BC6, BC7 or ASTC, And for encoding, our code is slow, low quality, and doesn't support any of the newer formats. I think it is definitely worth having a conversation about how we should be handling GPU texture formats in |
Is there any established process for doing that?
Would the feature
Could you give examples of good GPU encoding libraries? The only one I spoted is the GPUOpen Compressonators BCN common kernel. Is there a policy about licensing issues? I would be willing to take part in the following steps:
That means I am hesitant to say wether or not I would provide any more format implementations in the future. |
The steps you list sound good to me.
I'd be in favor of deprecating and eventually removing dxt, once we have an alternative crate we can point people to who still need the functionality (though to be honest I'm not sure anyone is using it). @HeroicKatora what do you think? |
👍 on deprecation from codecs when a crate is ready but I'd be slightly more cautious on removal. It would be great if we could change the implementation without directly touching the interface. My rationale is that while ImageDecoder is a rather awkward manner of exposing DXT decoding we don't have a mechanism for converting any block-based formats either. I would keep it around until we have a better interface ready that addresses the need directly. |
Actually, looking at crates.io there's already a couple other DXT crates. There's tbc which supports pure Rust encoding (but not decoding) of BC1, BC3, and BC4 using similar algorithms to what we do. And there's squish-rs which is a Rust port of the C++ library with the same name supporting BC1-3 encoding/decoding. It hasn't been updated in a while but implements considerably higher quality algorithms than ours. |
This crate looks quite reasonable (and the last update is not a year old), although there might be issues. It also seems to use RGBA byte buffers only, which is somewhat laborious for BC4s and BC5s one and two channels respectively. What would be the preferred way? The current implementation pulled into a separate crate or using a third party crate for that job? For the latter part, I can think of these three points for starting a discussion:
|
Squish-rs maintainer here. Support for the other BC variants (including BC6H and BC7) is something I've been meaning to add for a while now. As you can probably see from the commit activity I have also been working on improving the API. I am open to suggestions for the direction of the API design if there are wishes regarding that on the image-rs side. As for the linked issue, I probably made some small mistake while transcribing the libsquish C++ code, I'll have to go over that and see if I can spot a difference. On an unrelated note, I'd also like to see KTX support in image-rs. It's a similar format to DDS but with an open specification from Khronos (the organization maintaining OpenGL and Vulkan specifications). There is a ktx crate but it needs some streamlining (using rust enums with repr(u32) instead of plain u32 everywhere) and does not have write support yet, although there appears to be an open PR regarding that. |
FWIW I've just pushed BC4 and BC5 support to squish-rs |
This pull request adds support for the BC4 (ATI1) block compression encoding and decoding to the
dxt
module. Since the BC4 is similar to the BC3 (DXT5), the existing encoding and decoding of BC3 implementation is reused. More information about BC3 and BC4 can be found in Texture Compression Techniques (T. Paltashev and I. Perminov; 2014) and Texture Block Compression in Direct3D 11 (Microsoft).The output format is a single channel and therefore the color type
L8
was chosen. Additionaly, the FourCC codeATI1
that corresponds to this compression in the DDS format is included.As this is my first pull request for this project, feel free to start a discussion. Some thoughts I had during development:
dxt
module. I added mine indxt
, but is there a better spot for this?decode_dxt1_row
,decode_dxt3_row
,decode_dxt5_row
anddecode_bc4_row
). Should I refactor parts of the module to reduce such code duplication?DXTVariant
enum is not non-exhaustive. I added BC4 here for now, but there is propably a better solution?I license past and future contributions under the dual MIT/Apache-2.0 license,
allowing licensees to chose either at their option.