Skip to content

fix(metal): seed never-included code-blocks with zero in the zero-bitplane tree - #302

Merged
jcwal1516 merged 1 commit into
mainfrom
fix/metal-zero-bitplane-seed
Oct 29, 2026
Merged

jcwal1516 merged 1 commit into
mainfrom
fix/metal-zero-bitplane-seed

Conversation

@jcwal1516

Copy link
Copy Markdown
Member

Stacked on #301. Makes all-stage Metal lossy encodes byte-identical to the CPU encoder.

The Metal packetizer gave a code-block with no coding passes its own zero-bitplane count (all bitplanes) in the zero-bitplane tag tree, while the CPU packetizer seeds it with zero. Decoders never read that leaf, but it lowers or raises its parent's minimum, so packet headers with an empty block beside coded ones differed: the codestreams were valid but not byte-identical to the CPU's. The Metal tree, in both the host-fed and resident classic packetizers, now seeds such blocks with zero as the CPU does.

Testing

  • New test metal_all_stage_lossy_encodes_match_cpu_bytes_with_empty_code_blocks encodes a 256 × 256 RGB image whose flat half leaves empty code-blocks beside coded ones, and compares Metal and CPU codestreams byte for byte for HT (default and qfactor 60) and classic. It fails on the previous kernel ("HighThroughput None": header bytes differ) and passes with this change.
  • J2K_REQUIRE_METAL_RUNTIME=1 cargo test -p j2k-metal (587 passed) and cargo xtask metal-compile pass.

…plane tree

The Metal packetizer gave a code-block with no coding passes its own
zero-bitplane count (all bitplanes) in the zero-bitplane tag tree,
while the CPU packetizer seeds it with zero. Decoders never read that
leaf, but it lowers or raises the parent minimum, so headers with an
empty block beside coded ones differed: all-stage Metal lossy encodes
were valid but not byte-identical to the CPU (mosaic qfactor 86: 2
bytes shorter). The Metal tree now seeds such blocks as the CPU does.

(cherry picked from commit 575f6d2e2f3b3743d71ce91fbf60c660d55c2873)
(cherry picked from commit 6341a18dd2c33d30ece345ddb1b8a2b0c946706b)
@jcwal1516
jcwal1516 force-pushed the fix/metal-zero-bitplane-seed branch from 431cdf3 to a8e8748 Compare October 29, 2026 05:09
Base automatically changed from fix/cpu-batch-region-windows to main October 29, 2026 12:26
@jcwal1516
jcwal1516 merged commit a8e8748 into main Oct 29, 2026
16 of 32 checks passed
@jcwal1516
jcwal1516 deleted the fix/metal-zero-bitplane-seed branch October 29, 2026 12:26
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