Files
punktfunk/crates/pyrowave-sys/vendor/pyrowave/shaders/yuv2rgb.frag
T
enricobuehler 4c3b11445c feat(host): vendor PyroWave + minimal Granite subset as crates/pyrowave-sys
Phase 0 of design/pyrowave-codec-plan.md — the opt-in wired-LAN ultra-low-
latency codec. Vendored at upstream 509e4f88 (API 0.4.0, Granite 44362775,
volk + vulkan-headers pins in PUNKTFUNK-VENDOR.txt), pruned to the 6.6 MB
the standalone no-renderer build needs; scripts/vendor-pyrowave.sh
reproduces the tree (a pin bump is protocol-affecting, plan §4.2).

build.rs drives the wrapper CMakeLists (static archives incl. a static
C-API lib upstream only ships shared) + bindgen over pyrowave.h; Linux and
Windows only, empty stub elsewhere (Apple gets a native Metal port, §4.7).
Offline-safe by construction: no network, no system lib, vendored Vulkan
headers — same model as the opus dep (flatpak builder has no network).

Phase-0 validation on .21 (RTX 5070 Ti, driver 610.43.03):
- upstream pyrowave-c-test + interop test (incl. dmabuf/DRM-modifier
  Vulkan<->Vulkan) pass, from the pristine AND the pruned tree
- GPU kernel times at ~1.6 bpp noise: encode/decode 0.090/0.042 ms @800p,
  0.146/0.067 @1080p, 0.226/0.103 @1440p, 0.477/0.201 @4K — order of
  magnitude under NVENC's 1-2 ms retrieve, CBR lands within ~100 B of
  target
- cargo test -p pyrowave-sys green (static link + API-version pin check)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 00:35:10 +02:00

61 lines
1.6 KiB
GLSL

#version 450
#if DELTA
layout(set = 0, binding = 0) uniform texture2D Y0;
layout(set = 0, binding = 1) uniform texture2D Y1;
#else
layout(set = 0, binding = 0) uniform texture2D Y;
layout(set = 0, binding = 1) uniform texture2D Cb;
layout(set = 0, binding = 2) uniform texture2D Cr;
#endif
layout(set = 0, binding = 3) uniform sampler Samp;
layout(location = 0) out vec3 FragColor;
layout(location = 0) in vec2 vUV;
layout(constant_id = 0) const bool BT2020 = false;
layout(constant_id = 1) const bool FullRange = false;
const mat3 yuv2rgb_bt709 = mat3(
vec3(1.0, 1.0, 1.0),
vec3(0.0, -0.13397432 / 0.7152, 1.8556),
vec3(1.5748, -0.33480248 / 0.7152, 0.0));
const mat3 yuv2rgb_bt2020 = mat3(
vec3(1.0, 1.0, 1.0),
vec3(0.0, -0.202008 / 0.587, 1.772),
vec3(1.402, -0.419198 / 0.587, 0.0));
void main()
{
#if DELTA
float y0 = textureLod(sampler2D(Y0, Samp), vUV, 0.0).x;
float y1 = textureLod(sampler2D(Y1, Samp), vUV, 0.0).x;
FragColor = vec3(abs(y0 - y1) * 10.0);
#else
float y = textureLod(sampler2D(Y, Samp), vUV, 0.0).x;
float cb = textureLod(sampler2D(Cb, Samp), vUV, 0.0).x;
float cr = textureLod(sampler2D(Cr, Samp), vUV, 0.0).x;
cb -= 0.5;
cr -= 0.5;
if (!FullRange)
{
y -= 16.0 / 255.0;
y *= 255.0 / 219.0;
const float ChromaScale = 255.0 / 224.0;
cb *= ChromaScale;
cr *= ChromaScale;
y = clamp(y, 0.0, 1.0);
cb = clamp(cb, -0.5, 0.5);
cr = clamp(cr, -0.5, 0.5);
}
if (BT2020)
FragColor = yuv2rgb_bt2020 * vec3(y, cb, cr);
else
FragColor = yuv2rgb_bt709 * vec3(y, cb, cr);
#endif
}