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

Precompute g_bc7_mode_N tables for solid color blocks #384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zeux
Copy link
Contributor

@zeux zeux commented Nov 3, 2024

uastc_init takes 140ms in Chrome; this delays time-to-first-paint with textures by 140ms per worker. The tables are just 2KB and 1KB respectively; additionally, errors for mode 5 are all 0, and errors for mode 6 are all 0 except for two values (0 and 255), so we can avoid storing the errors and compute them from color values. This allows us to cut both tables in half (1KB and 0.5KB respectively).

This reduces uastc_init cost to 30ms. The .wasm file goes from 525 KB to 526 KB with this change (846 extra bytes of overhead).

Not sure if this is similar to any existing pattern; feel free to close this if there's a better way to do this.

uastc_init takes 140ms in Chrome; this delays time-to-first-paint with
textures by 140ms per worker. The tables are just 2KB and 1KB
respectively; additionally, errors for mode 5 are all 0, and errors for
mode 6 are all 0 except for two values (0 and 255), so we can avoid
storing the errors and compute them from color values.

This reduces uastc_init cost to 30ms.
@zeux
Copy link
Contributor Author

zeux commented Nov 3, 2024

Actually, also, BC7 mode 5 can perfectly encode any solid color block, right? So you shouldn't even need mode 6 selection in the first place. This would simplify the code further. I'm going to add a separate commit that does this.

Mode 5 already has zero errors on all solid blocks, so there's no point
in using mode 6; this makes transcoding a little faster and simpler, and
removes an extra table.
@zeux
Copy link
Contributor Author

zeux commented Nov 4, 2024

With removal of mode 6 table, the .wasm binary is 525 KB (-516 bytes from master).

@lexaknyazev
Copy link
Contributor

FYI, #232.

@zeux
Copy link
Contributor Author

zeux commented Nov 4, 2024

Yeah that's also a good solution, but we'd still need to remove the mode 6 table (as it's slow to compute - iirc it was ~35ms for mode 5 and ~70ms for mode 6 - and not useful), or precompute it like this PR does, minus the second commit.

@lexaknyazev
Copy link
Contributor

Mode 6 path was added for very specific non-web use cases. It could be wrapped with macros when compiling with emscripten to not remove that functionality altogether.

The expressions in #232 give exact Mode 5 endpoints for any solid color so neither static tables nor init routines are needed.

@zeux
Copy link
Contributor Author

zeux commented Nov 4, 2024

I agree you shouldn't need tables here in the first place for mode 5. As for mode 6, I've read the linked issue and I am not sure I understand the value (why would LZ be able to identify shared patterns between a solid color mode 6 block and some other mode 6 block?), but if there's data that suggests that this is necessary for some other use case, the mode 6 table could be kept precomputed, as the first commit in this PR does, possibly with a define to keep that optional/opt-in.

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