Files
punktfunk/crates/pyrowave-sys/patches/0001-payload-data-444-sizing.patch
enricobuehlerandClaude Fable 5 97cf15e3b7 fix(pyrowave-sys): vendor patch — size the encoder's payload_data staging for 4:4:4
Upstream sizes the raw quantized-payload worst-case buffer at
aligned_width*aligned_height*2 bytes: real headroom for 4:2:0's 1.5
samples/px, but half of what 4:4:4's 3 samples/px can produce. Busy 4:4:4
content overruns the buffer on the GPU and corrupts the adjacent meta/bucket
suballocations — nondeterministic corrupt bitstreams and encoder crashes at
ANY target bitrate (smooth content never trips it, which is why 4:2:0 and
simple 4:4:4 both look fine). Found by the Phase-0 measurement matrix for
design/pyrowave-444-hdr.md; fix validated alone via upstream's own devel
tools on the RTX 5070 Ti: deterministic byte-identical outputs across runs,
1080p + 4K, 8- and 16-bit, PSNR at the expected operating points.

Patch lives in crates/pyrowave-sys/patches/ and vendor-pyrowave.sh now
re-applies patches on re-vendor; PUNKTFUNK-VENDOR.txt records it. Upstream
report to follow. No wire/ABI change; 4:2:0 sizing unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-18 12:16:56 +02:00

21 lines
1.1 KiB
Diff

diff --git a/crates/pyrowave-sys/vendor/pyrowave/pyrowave_encoder.cpp b/crates/pyrowave-sys/vendor/pyrowave/pyrowave_encoder.cpp
index f5ac6dcc..ad4e9746 100644
--- a/crates/pyrowave-sys/vendor/pyrowave/pyrowave_encoder.cpp
+++ b/crates/pyrowave-sys/vendor/pyrowave/pyrowave_encoder.cpp
@@ -187,8 +187,13 @@ void Encoder::Impl::init_block_meta()
meta_buffer = device->create_buffer(info);
device->set_name(*meta_buffer, "meta-buffer");
- // Worst case estimate.
- info.size = aligned_width * aligned_height * 2;
+ // Worst case estimate. PUNKTFUNK PATCH (patches/0001-payload-data-444-sizing.patch):
+ // 4:4:4 carries 3 samples per pixel vs 4:2:0's 1.5 — the same per-sample headroom
+ // needs twice the bytes, or busy 4:4:4 content overruns this buffer on the GPU and
+ // corrupts the adjacent meta/bucket allocations (nondeterministic bad bitstreams and
+ // crashes at ANY target bitrate). Validated on RTX 5070 Ti @1080p/4K, 8/16-bit.
+ info.size = VkDeviceSize(aligned_width) * aligned_height *
+ (chroma == ChromaSubsampling::Chroma444 ? 4 : 2);
payload_data = device->create_buffer(info);
device->set_name(*payload_data, "payload-data");