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

Improve quantization utilities #598

Merged
merged 7 commits into from
Aug 25, 2023
Merged

Improve quantization utilities #598

merged 7 commits into from
Aug 25, 2023

Conversation

zeux
Copy link
Owner

@zeux zeux commented Aug 24, 2023

  • Move larger quantization functions to a .cpp file to make sure we can add more advanced quantizers in the future without inflating the header size
  • Add meshopt_dequantizeHalf which can be used to reverse float->half quantization in cases when the result is needed on the CPU
  • Document manual dequantization process a little better

Fixes #597.

meshopt_quantizeFloat and meshopt_quantizeHalf are moved to the new
file. These are larger (esp. float->half), not as commonly used as
unorm/snorm, don't benefit as much from inlining as it's more rare that
they are used with constant arguments in perf-sensitive context, and
also not used anywhere inside meshoptimizer itself, which means we still
get to keep the independence between different translation units (we'll
need to be careful with this in the future...).

A new file makes for a convenient place to add more quantization
utilities in the future as well.

These are used in gltfpack, which doesn't see a noticeable perf
degradation on geometry-heavy meshes that use quantizeFloat.
We now test both quantizeFloat and quantizeHalf fairly thoroughly via
unit tests.
Also convert C comments to C++ - this is no longer part of
meshoptimizer.h so it doesn't need to be C89 compatible.
This function reverses the transformation by meshopt_quantizeHalf; the
reverse conversion is easier since exponent and mantissa just need to be
expanded into the larger range. We still need to handle denormals and
specials; unlike quantization, here we choose to preserve NaN payload
because that allows us to fold inf and nan cases into a single
conditional add.
meshopt_quantizeFloat does not require dequantization;
meshopt_quantizeHalf now has a dequantize function; Snorm/Unorm variants
have a trivial (divide-by-scale) dequantizer.
@zeux zeux merged commit c9a13c3 into master Aug 25, 2023
11 checks passed
@zeux zeux deleted the quant branch August 25, 2023 00:15
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.

Add dequantization functions
1 participant