4c3b11445c
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>
215 lines
7.8 KiB
Plaintext
215 lines
7.8 KiB
Plaintext
#version 450
|
|
// Copyright (c) 2025 Hans-Kristian Arntzen
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#if FP16
|
|
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
|
|
#endif
|
|
|
|
layout(local_size_x = 64) in;
|
|
layout(constant_id = 0) const bool DCShift = false;
|
|
|
|
uint local_index;
|
|
|
|
#include "dwt_common.h"
|
|
|
|
layout(set = 0, binding = 0) uniform mediump sampler2DArray uTexture;
|
|
layout(set = 0, binding = 1) writeonly mediump uniform image2D uOutput;
|
|
|
|
layout(push_constant) uniform Registers
|
|
{
|
|
ivec2 resolution;
|
|
vec2 inv_resolution;
|
|
};
|
|
|
|
vec2 generate_mirror_uv(ivec2 coord, bool even_x, bool even_y)
|
|
{
|
|
coord -= ivec2(band(bvec2(even_x, even_y), lessThan(coord, ivec2(0))));
|
|
coord += 1;
|
|
coord += ivec2(band(bvec2(!even_x, !even_y), greaterThanEqual(coord, resolution)));
|
|
vec2 uv = vec2(coord) * inv_resolution;
|
|
return uv.yx; // Transpose on load.
|
|
}
|
|
|
|
void write_shared_4x4(ivec2 coord, VEC4 texels0, VEC4 texels1, VEC4 texels2, VEC4 texels3)
|
|
{
|
|
store_shared(coord.y + 0, 2 * coord.x + 0, VEC2(texels0.x, texels2.x));
|
|
store_shared(coord.y + 0, 2 * coord.x + 1, VEC2(texels1.x, texels3.x));
|
|
store_shared(coord.y + 0, 2 * coord.x + 2, VEC2(texels0.y, texels2.y));
|
|
store_shared(coord.y + 0, 2 * coord.x + 3, VEC2(texels1.y, texels3.y));
|
|
store_shared(coord.y + 1, 2 * coord.x + 0, VEC2(texels0.z, texels2.z));
|
|
store_shared(coord.y + 1, 2 * coord.x + 1, VEC2(texels1.z, texels3.z));
|
|
store_shared(coord.y + 1, 2 * coord.x + 2, VEC2(texels0.w, texels2.w));
|
|
store_shared(coord.y + 1, 2 * coord.x + 3, VEC2(texels1.w, texels3.w));
|
|
}
|
|
|
|
void load_image_with_apron()
|
|
{
|
|
ivec2 base_coord = ivec2(gl_WorkGroupID.xy) * ivec2(BLOCK_SIZE_HALF) - APRON_HALF;
|
|
ivec2 local_coord0 = 2 * unswizzle8x8(local_index);
|
|
ivec2 coord0 = base_coord + local_coord0;
|
|
|
|
// Transpose on load.
|
|
VEC4 texels0 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(coord0, true, true), 0.0), 0)).wxzy;
|
|
VEC4 texels1 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(coord0, false, true), 2.0), 0)).wxzy;
|
|
VEC4 texels2 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(coord0, true, false), 1.0), 0)).wxzy;
|
|
VEC4 texels3 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(coord0, false, false), 3.0), 0)).wxzy;
|
|
write_shared_4x4(local_coord0, texels0, texels1, texels2, texels3);
|
|
|
|
ivec2 local_coord_horiz = ivec2(BLOCK_SIZE_HALF + 2 * (local_index % 2u), 2 * (local_index / 2u));
|
|
if (local_coord_horiz.y < BLOCK_SIZE_HALF + 2 * APRON_HALF)
|
|
{
|
|
texels0 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_horiz, true, true), 0.0), 0)).wxzy;
|
|
texels1 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_horiz, false, true), 2.0), 0)).wxzy;
|
|
texels2 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_horiz, true, false), 1.0), 0)).wxzy;
|
|
texels3 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_horiz, false, false), 3.0), 0)).wxzy;
|
|
write_shared_4x4(local_coord_horiz, texels0, texels1, texels2, texels3);
|
|
}
|
|
|
|
ivec2 local_coord_vert = local_coord_horiz.yx;
|
|
if (local_coord_vert.x < BLOCK_SIZE_HALF)
|
|
{
|
|
texels0 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_vert, true, true), 0.0), 0)).wxzy;
|
|
texels1 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_vert, false, true), 2.0), 0)).wxzy;
|
|
texels2 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_vert, true, false), 1.0), 0)).wxzy;
|
|
texels3 = VEC4(textureGather(uTexture, vec3(generate_mirror_uv(base_coord + local_coord_vert, false, false), 3.0), 0)).wxzy;
|
|
write_shared_4x4(local_coord_vert, texels0, texels1, texels2, texels3);
|
|
}
|
|
|
|
barrier();
|
|
}
|
|
|
|
void inverse_transform8x2()
|
|
{
|
|
const int SIZE = 8;
|
|
const int PADDED_SIZE = SIZE + 2 * APRON;
|
|
const int PADDED_SIZE_HALF = PADDED_SIZE / 2;
|
|
VEC2 values[PADDED_SIZE];
|
|
|
|
ivec2 local_coord = ivec2(8 * (local_index % 4u), local_index / 4u);
|
|
|
|
for (int i = 0; i < PADDED_SIZE; i += 2)
|
|
{
|
|
VEC2 v0 = load_shared(local_coord.y, local_coord.x + i + 0);
|
|
VEC2 v1 = load_shared(local_coord.y, local_coord.x + i + 1);
|
|
values[i + 0] = v0 * K;
|
|
values[i + 1] = v1 * inv_K;
|
|
}
|
|
|
|
// CDF 9/7 lifting steps.
|
|
// Arith go brrr.
|
|
for (int i = 2; i < PADDED_SIZE - 1; i += 2)
|
|
values[i] -= DELTA * (values[i - 1] + values[i + 1]);
|
|
for (int i = 3; i < PADDED_SIZE - 2; i += 2)
|
|
values[i] -= GAMMA * (values[i - 1] + values[i + 1]);
|
|
for (int i = 4; i < PADDED_SIZE - 3; i += 2)
|
|
values[i] -= BETA * (values[i - 1] + values[i + 1]);
|
|
for (int i = 5; i < PADDED_SIZE - 4; i += 2)
|
|
values[i] -= ALPHA * (values[i - 1] + values[i + 1]);
|
|
|
|
// Avoid WAR hazard.
|
|
barrier();
|
|
|
|
for (int i = APRON_HALF; i < PADDED_SIZE_HALF - APRON_HALF; i++)
|
|
{
|
|
VEC2 a = values[2 * i + 0];
|
|
VEC2 b = values[2 * i + 1];
|
|
|
|
// Transpose the 2x2 block.
|
|
VEC2 t0 = VEC2(a.x, b.x);
|
|
VEC2 t1 = VEC2(a.y, b.y);
|
|
|
|
// Transpose write
|
|
int y_coord = (local_coord.x >> 1) + (i - APRON_HALF);
|
|
store_shared(y_coord, 2 * local_coord.y + 0, t0);
|
|
store_shared(y_coord, 2 * local_coord.y + 1, t1);
|
|
}
|
|
}
|
|
|
|
void inverse_transform4x2(bool active_lane, int y_offset)
|
|
{
|
|
const int SIZE = 4;
|
|
const int PADDED_SIZE = SIZE + 2 * APRON;
|
|
const int PADDED_SIZE_HALF = PADDED_SIZE / 2;
|
|
VEC2 values[PADDED_SIZE];
|
|
|
|
ivec2 local_coord = ivec2(4 * (local_index % 8u), local_index / 8u + y_offset);
|
|
|
|
if (active_lane)
|
|
{
|
|
for (int i = 0; i < PADDED_SIZE; i += 2)
|
|
{
|
|
VEC2 v0 = load_shared(local_coord.y, local_coord.x + i + 0);
|
|
VEC2 v1 = load_shared(local_coord.y, local_coord.x + i + 1);
|
|
values[i + 0] = v0 * K;
|
|
values[i + 1] = v1 * inv_K;
|
|
}
|
|
|
|
// CDF 9/7 lifting steps.
|
|
// Arith go brrr.
|
|
for (int i = 2; i < PADDED_SIZE - 1; i += 2)
|
|
values[i] -= DELTA * (values[i - 1] + values[i + 1]);
|
|
for (int i = 3; i < PADDED_SIZE - 2; i += 2)
|
|
values[i] -= GAMMA * (values[i - 1] + values[i + 1]);
|
|
for (int i = 4; i < PADDED_SIZE - 3; i += 2)
|
|
values[i] -= BETA * (values[i - 1] + values[i + 1]);
|
|
for (int i = 5; i < PADDED_SIZE - 4; i += 2)
|
|
values[i] -= ALPHA * (values[i - 1] + values[i + 1]);
|
|
}
|
|
|
|
// Avoid WAR hazard.
|
|
barrier();
|
|
|
|
if (active_lane)
|
|
{
|
|
for (int i = APRON_HALF; i < PADDED_SIZE_HALF - APRON_HALF; i++)
|
|
{
|
|
VEC2 a = values[2 * i + 0];
|
|
VEC2 b = values[2 * i + 1];
|
|
|
|
// Transpose the 2x2 block.
|
|
VEC2 t0 = VEC2(a.x, b.x);
|
|
VEC2 t1 = VEC2(a.y, b.y);
|
|
|
|
// Transpose write
|
|
int y_coord = (local_coord.x >> 1) + (i - APRON_HALF);
|
|
store_shared(y_coord, 2 * local_coord.y + 0, t0);
|
|
store_shared(y_coord, 2 * local_coord.y + 1, t1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void main()
|
|
{
|
|
local_index = gl_LocalInvocationIndex;
|
|
|
|
load_image_with_apron();
|
|
|
|
// Horizontal transform.
|
|
inverse_transform8x2();
|
|
|
|
// Also need to transform the apron.
|
|
inverse_transform4x2(local_index < 32, BLOCK_SIZE_HALF);
|
|
|
|
barrier();
|
|
|
|
// Vertical transform.
|
|
inverse_transform8x2();
|
|
|
|
barrier();
|
|
|
|
ivec2 local_coord = unswizzle8x8(local_index);
|
|
|
|
for (int y = local_coord.y; y < BLOCK_SIZE_HALF; y += 8)
|
|
{
|
|
for (int x = local_coord.x; x < BLOCK_SIZE; x += 8)
|
|
{
|
|
VEC2 v = load_shared(y, x);
|
|
if (DCShift)
|
|
v += FLOAT(0.5);
|
|
imageStore(uOutput, ivec2(2 * y + 0, x) + BLOCK_SIZE * ivec2(gl_WorkGroupID.yx), v.xxxx);
|
|
imageStore(uOutput, ivec2(2 * y + 1, x) + BLOCK_SIZE * ivec2(gl_WorkGroupID.yx), v.yyyy);
|
|
}
|
|
}
|
|
}
|