From 9bd77e54943d954291b5faef287ccca5dcebd7a4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:15:15 -0300 Subject: examples: micscope and spheres come home, as they were, building Both lived outside any repository, beside sketchbook, with manifests that pointed at ../01-drat-meout/lib/sketchbook, which no longer exists. They are copied into examples/micscope and examples/spheres (their sources, shaders, tests, test material and web icons; not their caches, builds, packages, state files or .gitignore, which the root's covers), their manifests depend on "../.." as the other examples do, and their READMEs link sketchbook there. Nothing else changed: both build against today's library and pass their own zig build test (micscope 62/62 steps, 11/11 tests, its transport, record, render and tuner scripts; spheres 75/75 steps, 3/3 tests, its play script). The originals are untouched. micscope's test/reference.flac (3.7 MiB, CC BY-SA 3.0, credited in its test/README.md) is the rendering reference its render script opens. The README lists both examples. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- examples/micscope/shaders/tuner_difference.comp | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 examples/micscope/shaders/tuner_difference.comp (limited to 'examples/micscope/shaders/tuner_difference.comp') diff --git a/examples/micscope/shaders/tuner_difference.comp b/examples/micscope/shaders/tuner_difference.comp new file mode 100644 index 0000000..c7d1b6e --- /dev/null +++ b/examples/micscope/shaders/tuner_difference.comp @@ -0,0 +1,49 @@ +#version 450 +#extension GL_GOOGLE_include_directive : require +// YIN's difference function for tuner.comp, spread over many workgroups: +// d(tau) = sum over the newest W samples of (x[j] - x[j - tau])^2. Each +// workgroup takes LAGS_PER_GROUP lags, with THREADS / LAGS_PER_GROUP +// threads summing every so-many term of each, then adding up. +layout(local_size_x = 256) in; + +#include "TunerParams.glsl" + +layout(set = 0, binding = 0) readonly buffer Tape { float tape[]; }; +layout(set = 1, binding = 0) buffer Difference { float d[]; }; + +// Match layouts.zig and tuner.comp. +const uint W = 2048; +const uint LAGS = 1700; +const uint THREADS = 256; +const uint LAGS_PER_GROUP = 16; +const uint PER_LAG = THREADS / LAGS_PER_GROUP; + +shared float x[W + LAGS]; +shared float partial[THREADS]; + +void main() { + uint t = gl_LocalInvocationID.x; + int first = int(u.end) - int(W + LAGS); + for (uint i = t; i < W + LAGS; i += THREADS) { + int at = first + int(i); + x[i] = at >= 0 && at < int(u.samples) ? tape[u.offset + uint(at)] : 0.0; + } + barrier(); + + uint tau = gl_WorkGroupID.x * LAGS_PER_GROUP + t / PER_LAG; + uint lane = t % PER_LAG; + float sum = 0.0; + if (tau < LAGS) { + for (uint j = lane; j < W; j += PER_LAG) { + float diff = x[LAGS + j] - x[LAGS + j - tau]; + sum += diff * diff; + } + } + partial[t] = sum; + barrier(); + for (uint stride = PER_LAG / 2u; stride > 0u; stride >>= 1u) { + if (lane < stride) partial[t] += partial[t + stride]; + barrier(); + } + if (lane == 0u && tau < LAGS) d[tau] = partial[t]; +} -- cgit v1.3