From c009f708e631700fb1d65ccba2c8229c10054528 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 06:13:50 -0300 Subject: examples/live: the README, the language on one page examples/live/README.md: what the sketch is, how to run it (keys, the console's replay verbs, capture, crossfade, the test and probe steps), the language (its grammar and every builtin a line, from Lang.builtins), the capacities, what it cannot say (no state between samples or frames: no filters, feedback or reverb; the price of computing each sample alone on the GPU and of exact replays) and how it works, with the probe's numbers. Its example program parses (out 22 instructions, color 38). The sketchbook README lists the example. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'README.md') diff --git a/README.md b/README.md index 733cc3d..a6358d8 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ The standalone example packages live in [`examples/`](examples/): - [`vecanim`](examples/vecanim/): vector animation scenes. Select one with `-Dscene=scenes/live.zig`. - [`micscope`](examples/micscope/): records the microphone or opens sound files, plays them either way, and shows waveform, spectrogram and spectrum; a tuner. - [`spheres`](examples/spheres/): the three-body problem on the GPU, each body a voice synthesised by a compute shader. +- [`live`](examples/live/): a tiny language for sound and picture, typed over its own picture: every line that parses is compiled to a tape one GPU interpreter runs per pixel and per sample. - [`talk.zig`](examples/talk.zig): a talk with a slider in it, a sketch that runs its own `anim.Deck` (`zig build test-talk` plays it). - [`manual.zig`](examples/manual.zig): Figure 2-1 of the Intel SDM comes alive, then ADD's opcode table is written row by row and its `80 /0 ib` turns into SUB's `80 /5 ib`: PDF pages as vector shapes and parts of them (`zig build manual -Dmanual=PDF`; see Animation, PDF pages and parts). -- cgit v1.3 From f0c4ef1a771f6b13cbd86cccdb56accfd39bbd69 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 08:01:22 -0300 Subject: gpu: a uniform block over 4096 bytes fails to compile SDL_GPU's Vulkan backend binds 4 KiB of a uniform block (its descriptors' range, MAX_UBO_SECTION_SIZE in SDL_gpu_vulkan.c) and a larger block was cut off without a word, the rest of it read as nothing: examples/live met it with its two tapes in one block. glsl.assertStd140, which `gpu.uniform` and the GLSL layouts of a `.uniform` type both run, now refuses a block past `max_uniform_block` (4096) at compile time, the error naming the type, its size and the storage buffer to use instead. The README says so where it says std140 is checked. Test: a 4096-byte block passes (glsl.zig); a 4112-byte one fails to compile with the message, checked by hand (there is no harness for compile errors). zig build test: 186 of 186 steps, 148 of 148 tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- README.md | 4 +++- src/glsl.zig | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index a6358d8..ebf49a0 100644 --- a/README.md +++ b/README.md @@ -433,7 +433,9 @@ just a new pipeline after a reload. No sketch touches a graphics API. The shaders are GLSL; the build turns them into SPIR-V for native and WGSL for the web, and each build imports the form its host reads (see Build API). `abi.gpu.pipeline(Vertex, ...)` derives the vertex layout from a struct, and `abi.gpu.uniform` checks std140 at -compile time. A pipeline without attributes makes its own vertices from +compile time, and the size: a uniform block is 4096 bytes at most, all +SDL_GPU's Vulkan backend binds of one (a larger one was cut off without a +word), so more goes in a storage buffer. A pipeline without attributes makes its own vertices from `gl_VertexIndex` (a full-screen triangle, for shader-toy style views). Compute is data too. `host.newBuffer(size)` makes a GPU storage buffer, diff --git a/src/glsl.zig b/src/glsl.zig index a1cd2d6..974f566 100644 --- a/src/glsl.zig +++ b/src/glsl.zig @@ -98,12 +98,19 @@ pub fn generate(comptime root: type, comptime paths: []const []const u8, io: std } } +/// The most bytes a uniform block holds: what SDL_GPU's Vulkan backend +/// binds of one (its descriptors' range, MAX_UBO_SECTION_SIZE); a larger +/// block was cut off without a word (examples/live's two tapes met it). +pub const max_uniform_block = 4096; + /// Fails to compile unless `U` lays out exactly as a std140 uniform block /// with the same members in GLSL: scalars at 4 bytes, `vec2` at 8, -/// `vec3`/`vec4` at 16, arrays and nested structs at 16 with 16-byte strides. +/// `vec3`/`vec4` at 16, arrays and nested structs at 16 with 16-byte strides; +/// and fits `max_uniform_block`. pub fn assertStd140(comptime U: type) void { comptime { if (@typeInfo(U).@"struct".layout != .@"extern") @compileError(@typeName(U) ++ " must be extern to be a uniform block"); + if (@sizeOf(U) > max_uniform_block) @compileError(std.fmt.comptimePrint("{s} is {d} bytes: a uniform block is {d} at most (SDL_GPU's Vulkan backend binds 4 KiB of one, MAX_UBO_SECTION_SIZE, and the rest reads as nothing); put the rest in a storage buffer", .{ @typeName(U), @sizeOf(U), max_uniform_block })); const s = @typeInfo(U).@"struct"; for (s.field_names, s.field_types) |name, F| { const want = std140Align(F); @@ -136,6 +143,10 @@ fn std140Align(comptime T: type) usize { }; } +test "a uniform block of 4096 bytes is one (4112 fails to compile, as a lone check showed)" { + comptime assertStd140(extern struct { a: [256][4]f32 }); +} + test "uniform blocks and vertex inputs from structs" { const Root = struct { pub const Paint = extern struct { -- cgit v1.3