Skip to content
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

toktx: Zstd deflation failed; KTX error: Out of memory. #512

Closed
c2matrix opened this issue Dec 24, 2021 · 3 comments · Fixed by #527
Closed

toktx: Zstd deflation failed; KTX error: Out of memory. #512

c2matrix opened this issue Dec 24, 2021 · 3 comments · Fixed by #527

Comments

@c2matrix
Copy link

c2matrix commented Dec 24, 2021

when I try toktx --uastc 4 --zcmp 3 N.ktx2 N.png, it fail with message "toktx: Zstd deflation failed; KTX error: Out of memory."
if i remove --zcmp 3 option it will be ok.
I tried many images all with the same format (1024*1024 rgba png), just one image has this problem.
I'm use OSX Monterey 12.0.1, toktx is 4.0.0~6
the image is attached below.
N
.

@MarkCallow
Copy link
Collaborator

This is happening because the "deflated" image is larger than the UASTC image. Investigation into why is necessary.

@MarkCallow
Copy link
Collaborator

I plan to consult the zstd experts but it looks to me as though the nature of the data in this image means it does not compress well with lossless techniques. Running zstd, with default compression level of 3, on the .png file results in a larger file. Of course that already has internal Deflate compression which makes it tougher for any subsequent compression steps.

You can try increasing the zstd compression level, --zcmp <n> or enabling RDO --uastc_rdo_l <n>. I haven't tried increasing the zmp level. An RDO value of 5 or greater results in the compressed being a little smaller. Even with the maximum RDO value of 10, the size reduction is minimal so you may as well skip the zstd step.

libktx should probably handle this case by aborting the zstd compression and not changing the input ktxTexture2. If it does so, I have to figure out how to notify the caller.

MarkCallow added a commit that referenced this issue Jan 30, 2022
And fix asserts in DeflateZstd so they fire as intended.

Fixes #512.
@MarkCallow
Copy link
Collaborator

The fix in PR #527 ensures there is enough space for the output so there will no longer be an out of memory error. Using the default compression level, 3, and no RDO the result is a handful of bytes larger than the original. To make it smaller you can use RDO, as suggested in an earlier comment or you can raise the zstd compression level. --zcmp 20 is needed in this case. Using both RDO and an increased compression level will be better.

I think this image is a struggle for zstd due to the random nature of the pattern.

KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 21, 2024
And fix asserts in DeflateZstd so they fire as intended.

Fixes KhronosGroup#512.
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
And fix asserts in DeflateZstd so they fire as intended.

Fixes KhronosGroup#512.
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
And fix asserts in DeflateZstd so they fire as intended.

Fixes KhronosGroup#512.
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
And fix asserts in DeflateZstd so they fire as intended.

Fixes KhronosGroup#512.
KaperD pushed a commit to KaperD/KTX-Software that referenced this issue Feb 22, 2024
And fix asserts in DeflateZstd so they fire as intended.

Fixes KhronosGroup#512.
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 a pull request may close this issue.

2 participants