diff options
| author | user <user@clank> | 2026-08-14 22:39:18 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-14 22:39:18 +0200 |
| commit | c0b88416fc9543fa348b63be07905f7a33fdbcc3 (patch) | |
| tree | f669fdf1066b2ffeed7d61baae572f4834b7ce62 /config | |
| parent | sl0ppty: a tab is something you can name and move (diff) | |
| download | slosh-c0b88416fc9543fa348b63be07905f7a33fdbcc3.tar.gz slosh-c0b88416fc9543fa348b63be07905f7a33fdbcc3.tar.xz slosh-c0b88416fc9543fa348b63be07905f7a33fdbcc3.zip | |
sl0ppty: a shader's strength can be an expression
Adding an effect meant writing C -- in the binary, or since D15 in a shared
library. Both are a lot of ceremony for "dim every other row".
So: `amount` may be an expression, compiled to bytecode when the config is
read and evaluated per cell.
shaders {
dim amount="(y % 2) * 40" // scanlines
dim amount="(x > cols - 10) * 120" // a right margin
tint amount="255 - dist(x, y, curx, cury) * 12" color="#ff5fd7"
}
The scope is the argument, and that is the whole design. Every built-in here
is already colour_op(amount) with the amount a pure function of position --
vignette, zebra, ruler, margin and spotlight differ only in that function --
so the part worth handing to a config is the *number*, not the colour maths.
Three things follow at once: the mixing stays in C where it is fast and
correct; an expression cannot produce an invalid cell, because it produces
one byte; and that byte is cacheable.
The cache is what makes an interpreter affordable, and the numbers are why
this exists at all. Measured on a 200x50 pane, one pass:
native vignette 6.1 ns/cell
constant expression, folded 5.6 ns/cell
positional expression, mapped 5.2 ns/cell
animated (reads the clock) 35.0 ns/cell
A shader you wrote in your config costs what a compiled one does. A program
that does not read the clock is evaluated once per cell into a byte map and
reused until something it reads changes; one that does read the clock is
interpreted per cell, per frame, which is the honest price of animation and
is opt-in. (The earlier measurement of 56ns for interpretation was per
evaluation -- correct, and the reason the map exists rather than an argument
against the language.)
What a program reads is derived by the compiler rather than declared, and
that dependency set *is* the cache key. A stale map is therefore
unrepresentable rather than merely unlikely -- the same rule the layout
follows, arrived at from the other direction. A unit test caught the first
violation of it before anything else did: `cols` and `rows` carried no
dependency flag, on the theory that the key always contains the rect, and so
a program reading only the size looked constant and was folded at compile
time, where every size is zero.
The language is deliberately total. No loops, no recursion, no jumps: even
`?:` compiles to evaluating both sides and selecting, because nothing in it
has an effect. Evaluation is O(program length), so a config cannot spin, and
there is nothing to sandbox. Division by zero is 0 rather than a trap: an
expression that is wrong should look wrong, not take the session with it. One
that does not compile drops that one shader with a warning -- not the config,
and not the half-strength version of what you asked for, which is what the
number path did with garbage and is now also fixed.
shader_t gained the compiled program, so the plugin ABI goes to 2. A plugin
built against 1 is refused with "shader ABI 1, we speak 2" and needs nothing
but a rebuild -- the check earning its keep the first time it was asked to.
Diffstat (limited to 'config')
| -rw-r--r-- | config/config.kdl | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/config/config.kdl b/config/config.kdl index 1bc866c..099c34d 100644 --- a/config/config.kdl +++ b/config/config.kdl @@ -246,6 +246,42 @@ states { // margin amount at=100 everything from that column recedes // spotlight amount radius=12 brightness falls away from the cursor // +// `amount` can also be an *expression* instead of a number, evaluated for +// every cell. That is how you get an effect nobody built in, without building +// anything: +// +// shaders { +// dim amount="(y % 2) * 40" // scanlines +// dim amount="(x > cols - 10) * 120" // the right margin +// tint amount="255 - dist(x, y, curx, cury) * 12" color="#ff5fd7" +// } +// +// The expression produces the *strength*, never the colour: the mixing stays +// in C, so an expression cannot make an invalid cell, and its result is one +// byte per cell -- which is what lets the whole program be evaluated once into +// a per-cell map and then reused. A user-written positional shader therefore +// costs about what a compiled one does. One that reads the clock cannot be +// cached and is evaluated per cell per frame, which is the price of animation. +// +// variables x y the cell, inside the pane's content rect +// cols rows the size of that rect +// curx cury the cursor, and `cursor` (0 or 1) for whether +// this pane has it +// focused 0 or 1 +// t milliseconds, for animation +// operators + - * / % integer only; division by zero is 0, not a crash +// < > <= >= == != and && || !, which give 0 or 1 -- so +// `(x < 10) * 200` is how you write a rule +// ? : both sides are evaluated, then one is chosen +// functions min(a,b) max(a,b) abs(a) clamp(v,lo,hi) +// dist(x1,y1,x2,y2) counts a row double, because a cell is +// about twice as tall as it is wide +// +// There are no loops and no recursion, on purpose: a config cannot spin, and +// there is nothing to sandbox. An expression that does not compile drops that +// one shader with a warning -- never the config, and never a half-strength +// version of what you asked for. +// // Empty by default: these are yours to ask for, not opinions we hold. // // shaders { |
