-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
enable zstddec decode in web worker in KTX2Loader #21984
Conversation
Related #19650. |
@donmccurdy @zeux looks good? |
My understanding is that the files in
I'm unsure how (or if) to compare this to #19650. I really like that the WorkerPool abstraction here is very lightweight, and I wouldn't want to see this change blocked on a longer-term project, so other than the question above about file location, this change looks good to me. 👍 |
@donmccurdy i think creating another PR to export wasm string will be better, because my next PR will use both zstddec and zstddec worker version, in few imgs cases decoding in UI thread is better then decode in worker. gltf-gpu-compressed-texture |
So I don't want to block this PR in any way, and I'm fuzzy on why exactly we ended up with the separate zstd and basis Wasm modules, but an observation is that this is strictly less efficient than it should be: What I'd expect the flow to be is
What we have instead after this PR, when zstd is used, is:
As a result, we need two thread pools, 2x Wasm instances, more temporary memory, extra latency on passing buffers between worker, and extra redundant copies between Wasm -> JS -> Wasm. This is all suboptimal. Fixing this requires a single wasm transcoder that supports zstd. I don't remember the history here, but at this point I'd expect basis transcoder to support zstd+uastc inputs without extra configuration, so I feel like the current setup isn't good long term. edit As a consequence of the "right" fix I'd probably expect zstd decoding to move fully inside Basis loader (unless we need to support non-Basis zstd KTX2 for some reason?), so this change wouldn't be necessary. |
@zeux my work in progress project gltf-gpu-compressed-texture is using zstd + (astc|bc7|dxt|etc1|pvrtc), because basis encoder's dependences are not small, and a lite basis transcoder Basis-Universal-Transcoders supports too few format |
I'll try to have a closer look at https://github.com/deepkolos/gltf-gpu-compressed-texture in the future — for the moment Google Translate is not cutting it for me to understand what's going on there sorry! 😅 My hope has been that in some longer-term time horizon, lightweight Khronos transcoders will be available for both ETC1S and UASTC. At the moment they're UASTC-only. When that happens I'd like to switch over (entirely) to those transcoders. In the meantime it seemed like too much hassle to switch between two transcoders depending on the input format. Agreed with @zeux that separate worker pools for ZSTD and Basis are not optimal... but I don't think it's any worse than what we have now, either. Perhaps we could retain an option of running zstd decoding on the main thread? At least then we know for sure there's no regression...
The reason this isn't easy now is a combination of code history and (my) laziness... the
Maybe it's time to deprecate BasisTextureLoader? 🤔 I don't think there's any remaining reason to use (/cc @lexaknyazev FYI) |
Yeah what it looks like is: a) This fix is intended to be applied to KTX2 loader without the use of transcoding. So it stands on its own - my comment above assumed the transcoding use case but it looks like this is not the case here. |
And maybe with this change we can rely on the same web worker infrastructure at least between zstd-only and full zstd+basis decoding in the future? |
if two wasm instance in the same web worker is acceptable,maybe i can do that |
the code is not well tested, the example ktx2 is not zstd compressed, i will test it later. sample_uastc.zstd.ktx2 added |
@zeux @donmccurdy KTX2Loader's pipeline has changed, but the way to share code between BasisTextureLoader and zstddec.worker.module maybe is not a good way or maybe a prototype to share wasm worker code. from
to
|
It turns out that the latest builds of Binomial's Basis transcoder (https://github.com/BinomialLLC/basis_universal/tree/master/webgl/transcoder/build) include both KTX2 parsing and ZSTD decompression — in the same WASM build — and the size is similar to the {old transcoder + zstd} size anyway. This simplifies things considerably, as we don't need @deepkolos if you're open to it, my suggestions for this PR would be:
Is this OK? Thanks again for this PR and for looking into the performance here! |
@donmccurdy ok, i will make the change in this weekend. |
…n demand & add sample_uastc_zstd.ktx2
WorkPool’s api is chenged to enbale locating Worker on demand. |
@donmccurdy hi, modification is done which needs a code review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simplifies things nicely and looks more efficient – thanks!
Thanks! |
Is there a way to mark this in advance as a 'breaking change' for the release notes? It will require users to update their We may be able to detect this and show a warning when |
@donmccurdy Feel free to add a note here 👍 |
Done, and opened #22314. |
Description
in my WIP GLTFGPUCompressedTexture, i found that zstddec decode in web worker can have great load time improvement. so i migrate to KTX2Loader too.