-
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
Add RDO support to the ASTC encoder. #588
Comments
The astcenc block unpack should be standard-conformant - returning either max-magenta (unorm output) or NaN (float output) for any invalid encodings. It's a bug if it isn't, so if anyone finds cases where it's being too lenient please raise a bug upstream on the astcenc project. |
Thanks @solidpixel that is good to know. The person who gave me the information I wrote above had tried various block unpackers and was reporting his observations. Not sure if he tried the one in astcenc. When we implement RDO, we'll be sure to use that one. |
A few issues were fixed during the development of the 3.x series, so there have definitely historically been cases where it's not been doing the right thing here, but for 4.x these have all been fixed (at least the ones we know about;). |
Here's one possible way to do it: |
Thank you @YunHsiao. From what I can see it looks good. Since there does not appear to be a PR to the ASTC encoder source yet, I will post my question here.
Do any of these correspond to the It would be great if ASTC and UASTC RDO had the same set of parameters so users only have to understand one set. |
Thanks for the feedback, Afaics the parameters can be completely the same since they all got routed to the ERT solver, I'll see what I can do here. As for PRs the implementation is considered in-progress and may still have some rough edges to be ironed out, we're not there yet ;) |
So the difference is one is specified in bytes and the other in blocks, correct? I think I prefer blocks. Unfortunately libktx has long been released so changing uastcRDODictSize is difficult. Some source-code compatibility path is needed.
Please post something here when you open a PR. Please add a "licence" to |
Yes but for compatability's sake I'd rather go with bytes.
I'll keep here updated. Note that I'm not affiliated in any way with the astc encoder dev team and I'm doing this on my own, so no promises! But I would love to see how far I can go with this so I'll try to do what's right here. |
Okay. But the KTX documentation should explain more clearly what this parameter is. I like your name of rdo-lookback. So the doc should say something like "Buffer for recording previous blocks for look back. Should be a multiple of the blocksize."
I'd figured that out but thanks for letting me know. I am excited that you are working on it. It should bring a good reduction in the zstd-deflated sizes of ASTC textures in KTX v2 files. |
Yeah... There's definitely room for improvements. Although technically it does not really need to be multiples of the block size, just name it "dictionary size" is indeed a bit misleading.
Glad to help, let's see how this goes. I've updated my branch with following changes:
|
A draft PR has been opened here: |
The simplest way is to take the output of the ASTC encoder and pass it through the ERT (Entropy Reduction Transform) in this repo:
https://github.com/richgel999/bc7enc_rdo
See this class:
https://github.com/richgel999/bc7enc_rdo/blob/master/ert.h
The ERT is format agnostic. It just cares about block bytes, the original block's RGBA pixels, and a block unpack function.
You pass it an array of encoded blocks, an array of original block pixels, some parameters, and a pointer to a block unpack function. It does the rest. We need to find a good ASTC block unpacker. (There may be one with astc-encoder repo that is included in this repo. I haven't confirmed.) The main problem is the ASTC specification is so complex that some block unpackers wouldn't always catch invalid blocks, which the ERT will sometimes create as it injects trial matches into blocks. These blocks would fail to be unpacked by some unpackers, but would be unpacked by others, which is an issue.
The ERT is really simple and not much code, so it should be a good place to start.
A possible improvement is to encode a texture to ASTC multiple times, and use that as the source into the ERT. Each encode can use a different encoding that achieves more or less the same error.
The text was updated successfully, but these errors were encountered: