From 591bdaf08ab5e43b14667fafce08b91b90dfd1f4b56434f61475ec8de6fd8e0a Mon Sep 17 00:00:00 2001 From: Ben_Kosytorz Date: Sat, 22 Aug 2026 23:02:53 +0200 Subject: [PATCH] More --- src/gpu/shaders/thumbnail.wgsl | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/gpu/shaders/thumbnail.wgsl diff --git a/src/gpu/shaders/thumbnail.wgsl b/src/gpu/shaders/thumbnail.wgsl new file mode 100644 index 0000000..868a59e --- /dev/null +++ b/src/gpu/shaders/thumbnail.wgsl @@ -0,0 +1,36 @@ +// Stage-1 companion kernel: build a tiny grayscale luma thumbnail on the GPU. +// +// One thread per thumbnail pixel. Each thread nearest-samples a source pixel +// and writes its luma (0..255) into `thumb[ty * tw + tx]`. This lets the motion +// (parallax) proxy be computed on the GPU instead of the CPU reading the full +// RGBA frame, so extraction leans on the GPU rather than the CPU. + +struct Params { + w: u32, + h: u32, + tw: u32, + th: u32, + pad0: u32, +} + +@group(0) @binding(0) var params: Params; +@group(0) @binding(1) var src_tex: texture_2d; +@group(0) @binding(2) var thumb: array; + +fn luma(c: vec4) -> f32 { + return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b; +} + +@compute @workgroup_size(256, 1, 1) +fn main(@builtin(global_invocation_id) gid: vec3) { + let i = gid.x; + if (i >= params.tw * params.th) { + return; + } + let tx = i % params.tw; + let ty = i / params.tw; + let sx = i32(tx * params.w / params.tw); + let sy = i32(ty * params.h / params.th); + // Scale to 0..255 to match the CPU thumbnail / motion-diff convention. + thumb[i] = luma(textureLoad(src_tex, vec2(sx, sy), 0)) * 255.0; +}