Skip to content

meshletcodec: Revise encoding format for slightly more compression - #1006

Merged
zeux merged 2 commits into
masterfrom
mlc-formatrev
Jan 24, 2026
Merged

zeux merged 2 commits into
masterfrom
mlc-formatrev

Conversation

@zeux

@zeux zeux commented Jan 23, 2026

Copy link
Copy Markdown
Owner

Warning

The data format continues to be highly experimental. Until a library point release, data compatibility is not guaranteed.

  • Instead of using 0 as the initial delta state, we now use -1; with the offset-by-1 delta encoding that makes the first vertex reference "free" to encode if it's 0. This does not matter when the vertex references are encoded as absolute values, but it's common for engines to store a per-meshlet offset and rebase the references relative to that offset, in which case the first reference is often 0.
  • Place triangle codes at the end of the encoded data, after the vertex control bits. This aligns the data order between fixed-size and variable-sized sections, and can compress 0.5-1% better with zstd.

This contribution is sponsored by Valve.

zeux added 2 commits January 21, 2026 15:27
Instead of storing vertex control bits last, we now store triangle codes
last in the encoded meshlet.

This is mostly motivated by a slight improvement in the resulting
compression rates (~1%) after zstd/zlib compression gets applied, but
it's also beneficial in other ways: this order now matches the order of
variable data encoding, and because the first triangle must start with a
restart code, it may make it easier to validate or potentially version
data in the future (although other changes might be necessary for that
to happen).
Because our deltas are offset by 1, it takes one byte to encode the
delta value of 0, and zero bytes to encode the delta value of 1. If
meshlets encode absolute vertex references, this only affects the first
meshlet so it's inconseqeuential. However, it's common to use relative
encoding, storing a single base per meshlet - in which case, optimally
ordered meshlets usually start with vertex reference 0.

Starting the state with -1 means we can encode first vertex reference
with zero bytes if it's 0; previously it would be encoded with zero bytes
if it's 1, which is much less likely. This saves ~0.1 bits/tri in
affected scenarios at zero cost.
@zeux
zeux merged commit f67b15b into master Jan 24, 2026
13 checks passed
@zeux
zeux deleted the mlc-formatrev branch January 24, 2026 00:11
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.

1 participant