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

Add support for ZIMs in texture replacements #14467

Merged
merged 3 commits into from May 24, 2021

Conversation

unknownbrackets
Copy link
Collaborator

@unknownbrackets unknownbrackets commented May 16, 2021

This makes zimtool (built as ext\native\tools\build\ZimTool.exe on Windows) able to compress using ZSTD, and then supports such images in texture replacements. Only 8888 is supported.

I realize we could support more exotic formats, but this was a very easy format to support given our codebase already handles it.

To test, I hacked replacements to always reload the texture and went to an area with primarily a single 512x512 texture upscaled to 1024x1024. Then I measured different image types:

  • PNG: 1x speed
  • ZIM, ZSTD level 22: 2.75x speed
  • ZIM, ZSTD level 12: 3x speed
  • ZIM, uncompressed: 4x speed

Most of the time was in fread() when uncompressed. Importantly, this was the same image over and over again - so this doesn't measure the stresses of a large texture pack accurately. Still, ZIMs load much faster.

In my tests, ZIMs were about 25% larger on disk at level 22 (keep in mind there are no PNG filters at play here), and less than 50% larger at level 12. Uncompressed was obviously much larger.

-[Unknown]

Larger, but can be ZSTD compressed and load much faster.
There's decompression speed tradeoffs at some levels.
@unknownbrackets unknownbrackets added this to the v1.12.0 milestone May 16, 2021
@hrydgard
Copy link
Owner

Cool. I wonder whether it would make sense to try something extremely light and SIMD-able as a preprocess, like deltas just between lines, or something. Or maybe not, since being within 25% of png isn't too bad. We still have free flags though so could easily experiment with variants if we can be bothered :)

The Basis codec has been standardized into KTX 2.0 btw, that's another one that would be cool to support now that it'll hopefully get some more tool support...

I'll take a closer look and probably merge tomorrow.

@unknownbrackets
Copy link
Collaborator Author

Yeah, I also saw https://github.com/catid/Zpng which was someone's experimental thing. I think it would be easy to apply some fast filters that could be applied during a copy. But then I'm inventing a new format and maybe basis is better.

I suppose there's this:
https://github.com/KhronosGroup/KTX-Software/blob/master/lib/basis_transcode.cpp

I was a bit scared away by the repo saying it requires LFS, which I'm not sure if means it's not a great submodule candidate...

-[Unknown]

@hrydgard
Copy link
Owner

Well basis is a different thing, it's lossy. However doubling the resolution while using lossy compression can look better than lossless at original resolution, if you're talking quality per byte...

@unknownbrackets
Copy link
Collaborator Author

Right, and it'll use less or same VRAM still as long as the GPU supports some compressed format. This was just easy because I'd previously added ZSTD for the UI texture ZIM (which was previously gzip.)

Since this is 2.75x PNG, if it significantly improves hitching for people experiencing it, that should confirm the likely benefits of Basis support and potential preloading options. I don't necessarily intend for everyone to create ZIM texture packs, but someone trying it will give useful information and it's easy to keep support anyway.

-[Unknown]

@hrydgard
Copy link
Owner

OK :) That's a good reason.

@hrydgard hrydgard merged commit 8d08991 into hrydgard:master May 24, 2021
@unknownbrackets unknownbrackets deleted the texreplace-zim branch May 24, 2021 05:54
ghost referenced this pull request in kharij/Tekken-6-HD-Texture-Pack Oct 4, 2021
@hrydgard
Copy link
Owner

Although KTX2 is now the recommended choice for most textures. For fonts and other things that need to be pixel-perfect though, ZIM is a good alternative.

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.

None yet

2 participants