summaryrefslogtreecommitdiff
path: root/examples/live/shaders
Commit message (Collapse)AuthorAge
* examples/live: square units, x and y from the centre in half the heightGabriel Schneider2 hours
| | | | | | | | | | | | | | | | | picture.frag gives the tape x and y in half the target's height, 0 at its centre and y up (`y` -1 to 1, `x` -1.78 to 1.78 on 16:9), so a circle is round on any window, half resolution included. Lang.builtins and the README's table say so; the README's program draws its ring about the centre (`r = sqrt(x * x + y * y)`, the ring's radius and width doubled into the new unit). Test: test/live.script replaces the text (`%`, `c`) with a disc of radius 0.5, `step(x * x + y * y, 0.25)`, and reads its edge 180 pixels from the centre across and up: white at 170, black at 190, each way. zig build test: 85 of 85 steps. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
* examples/live: the scripted proof, a session played back and soughtGabriel Schneider2 hours
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | test/live.script now ends with the run's own session replayed: `play session 0` from its start, then `seek` to the two moments marked as they happened (the gradient just typed, and the end after an edit, a broken line and its mend). At each, the State equals the mark leaf by leaf (`expect-snapshot`: the text, both tapes, the problem, the time), and at the first the screenshot equals the live one over the text and the picture (0,0 1000x600, without the scope and the status line). `stop` then goes on live from that moment: the typed program, before its edit. What a script could not do: a `record` clip ends at the first mark (Console.zig's `save` stops it), so the clip cannot be marked while it is made: the session is replayed instead. A mark is State before its frame's tick, so its time is the printed time less a frame, and `seek MS` lands on the last frame at or before MS: the script seeks 5 ms past each mark's time (272 and 488). The sound at a jump: `want` counted the queue the clear is about to drop, so a seek starved the device for a frame; now it counts from empty. And the block after a jump crosses from the old tape at where the device was (the clock less what was queued) to the tape at the new time (Synth.old_start). Not measured: a capture records every block made, including the tail the jump drops, so it cannot show what was heard across a seek. zig build test: 68 of 68 steps, 6 of 6 tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
* examples/live: the sound, the out tape on the GPU per sampleGabriel Schneider2 hours
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `pub const audio_pull = 256`; each frame `draw` runs synth.comp over as many samples as keep the host's lead queued (`in.lead -| queued`, 8192 at most) and streams the block with f.audioBuffer, as spheres does. Time is a sample clock in Session: set from State's time at every jump (a seek, a step, a replay's start; the queue is dropped then, so the jump is heard at once), and free-running otherwise, so a paused replay keeps sounding its moment. When the out tape differs from the one the last block played, the block crosses from the old tape to the new over its length (`set crossfade false` turns that off, to hear what it saves). The blocks are read back for the scope (an oscilloscope and a spectrum along the bottom) and, after the console's `capture`, appended to the sketch's capture.f32 beside its save. The status line shows the lead. The tapes reach synth.comp in a storage buffer, uploaded per block: two tapes are 4 KiB, and SDL_GPU's Vulkan backend binds a uniform block 4 KiB at a time (MAX_UBO_SECTION_SIZE), so a 4128-byte Synth block read its count as 0 past the cut and the kernel wrote nothing, silently: the probe's first synth numbers timed that. Measured again (RTX 3050, Debug host, two runs): every synth dispatch 0.08-0.14 ms, 60 or 128 instructions, 256 or 1024 samples, fading or not, the empty pass's cost alone; the 4 KiB upload 0.07-0.08. Measured on SDL's dummy driver (nothing audible) from captures: out = 0.3 * sin(t * tau * 220): peak 0.3000, RMS 0.2121, fundamental 220.000 Hz; edited to 330 in one keystroke, 330.000 Hz. The largest sample-to-sample step across the edit: 0.0131 with the crossfade (a 330 Hz sine's own steepest step is 0.0130), 0.3725 without; into the first sound, 0.0011 and 0.2967. The survey's program: peak 0.50, RMS 0.16, its bass at 55.0 Hz. Test: live.script also expects the stream to receive the GPU's blocks, and compares screenshots above the scope. zig build test: 68 of 68 steps. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
* examples/live: the language, text in, a tape and a problem outGabriel Schneider2 hours
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Lang.compile reads lines of `name = expression` over t, x and y (+ - * /, unary minus, parentheses, numbers, # comments) and returns either a Program, the out and color tapes, or a Problem: a byte of the text and words. The builtins are one table, `builtins` (call, op, arity, value, doc): the survey's sin, cos, exp, log, pow, sqrt, abs, floor, fract, min, max, clamp, mix, step, smoothstep, atan2, noise, saw, sqr, tri, seq, hsv, rgb, tau and pi, and the inputs t, x, y. A name is defined once, before it is used; builtins cannot be renamed; hsv and rgb are colours, so only the whole color line can be one. Each tape is emitted from its line's root, depth first, each term once, so it holds only what the line reaches; t, x and y are a term each however often named, and a negative number is a number. seq's values go in registers side by side: as emitted when they are fresh numbers, else copied. noise's missing arguments are 0. Nothing is allocated: the compiler is a struct on the stack, 512 terms, 128 names, 32 levels of nesting, 17 arguments (seq's 16 values), 128 instructions a tape, about 28 KiB in all; past any of them is a problem in words ("the out line needs more than 128 instructions", at the line). vm.glsl's smoothstep is written out: GLSL leaves lo > hi undefined, and the survey's ring is smoothstep(0.03, 0, ...). Tests: a tone instruction by instruction; the survey's 20-line program (out 54 instructions, color 46, neither holding the other's terms, every operand an earlier register); every builtin; precedence, comments and numbers; 24 problems, each with its byte and words; each capacity, met and passed. zig build test: 6 of 6. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
* examples/live: the interpreter of a tape, and its probeGabriel Schneider2 hours
Demo 1's route: a program becomes a flat tape of at most 128 instructions (src/Lang.zig: the ops, the instruction, the tape and the two uniform blocks that carry it; build.zig writes Lang.Op out as ops.glsl, so the op numbers have one definition), and ONE interpreter, shaders/vm.glsl, runs it per pixel (picture.frag) and per sample (synth.comp, crossing from the tape it replaces over the first `fade` samples). Instruction i writes register i; the tape is pushed as uniforms. The probe measures it before anything else is built: `zig build probe` plays made-up tapes (every instruction reaching the last, a noise in ten) under --profile-gpu. RTX 3050 (driver 620.70.06), Debug host, means of 601 frames, three runs agreeing within 0.07 ms: picture, empty tape 720p 0.14-0.23 1080p 0.19-0.28 (a pass's cost) picture, 60 720p 1.38-1.45 1080p 2.89-2.96 picture, 128 720p 2.71-2.81 1080p 5.86-5.95 picture, 128 at 640x360 0.85-0.94 The budget, under 2 ms at 1280x720: 60 instructions meet it, 128 do not. The cheap fixes, on 128 at 720p: the tape in a storage buffer 2.97-3.03 (worse); the registers as an array of 16 (kept in registers, indexing turned into selects) 5.82-5.93 (twice as slow); the 128-array with only 16 slots used 2.11-2.34 (cache footprint: a register allocator would buy about a sixth); half resolution 0.85-0.94. So the sketch will draw a tape longer than 64 instructions at half resolution, scaled up. The variants are kept outside the tree. The synth's numbers taken here were of a kernel that wrote nothing (its uniform block was past SDL's 4 KiB): the sound's change measures it again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T