onejs-sl 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +43 -2
- package/goldens/goldens.json +480 -0
- package/package.json +5 -2
- package/src/body.ts +202 -0
- package/src/core.ts +1 -1
- package/src/emit/hlsl-body.ts +6 -0
- package/src/encode.ts +3 -24
- package/src/hlsl.ts +34 -143
- package/src/ir.ts +49 -2
- package/src/lang/lower.ts +6 -3
- package/src/serial.ts +3 -1
- package/src/sl.ts +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
A host can now supply its own frame for a program's body and get goldens for the pictures it should draw. Nothing an existing program draws changes, and OneJS's generated Unity shader is byte for byte what 0.1.0 printed.
|
|
6
|
+
|
|
7
|
+
- `onejs-sl/emit/hlsl-body`: `emitBody` and `BodyTarget`, the body in the HLSL and Metal shared subset
|
|
8
|
+
- The Unity shader is printed through `emitBody`
|
|
9
|
+
- `UniformDecl.colour` marks a uniform with a hex default, and `sl.uniform.colour` declares one
|
|
10
|
+
- `inputsUsed` lists the inputs a program reads
|
|
11
|
+
- `goldens/goldens.json`: every corpus fixture as a Linear game stores it, drawn by `npm run goldens`
|
|
12
|
+
|
|
3
13
|
## 0.1.0
|
|
4
14
|
|
|
5
15
|
The shader language compiler as its own package, moved out of `onejs-unity` with its history and its tests. It behaves exactly as `onejs-unity` 0.5.15's `sl` did, at IR version 2 and VM wire version 2.
|
package/README.md
CHANGED
|
@@ -40,11 +40,52 @@ only what it calls.
|
|
|
40
40
|
| `onejs-sl/tables` | `BUILTINS`, `SL_HLSL`, `INPUTS`, `SL_SDF_SHAPES`, `SL_SDF_PARAMS`: what completion and highlighting read |
|
|
41
41
|
| `onejs-sl/limits` | `vmFit(program)`: whether the VM runs it, and why not, without encoding |
|
|
42
42
|
| `onejs-sl/vm` | `encode`, `SL_WIRE_VERSION` |
|
|
43
|
-
| `onejs-sl/emit/
|
|
43
|
+
| `onejs-sl/emit/hlsl-body` | `emitBody`: a program as a function body for a host's own frame |
|
|
44
|
+
| `onejs-sl/emit/unity` | `emitShader`: the `.shader` a Unity editor generates, a frame over `emitBody` |
|
|
44
45
|
| `onejs-sl/emit/web` | `emitWGSL`, `emitGLSL`: OneJS's web frame |
|
|
45
46
|
|
|
46
47
|
`src/entries.test.ts` pins every name, since removing one breaks a host.
|
|
47
48
|
|
|
49
|
+
## A host's own frame: `emitBody`
|
|
50
|
+
|
|
51
|
+
`emitBody(program, target)` prints the body only: one local per node, in the
|
|
52
|
+
HLSL and Metal shared subset (HLSL spelling, `fmod`, no `mul`, no `static`, no
|
|
53
|
+
derivatives). The `BodyTarget` says what differs between hosts: an expression
|
|
54
|
+
for each input, the float4 holding a uniform slot, a texture sample, whether
|
|
55
|
+
`toLinear` is real (`colour: "linear"`) or the identity (`"gamma"`), and
|
|
56
|
+
optionally a local to assign the result to. It returns the uniform and texture
|
|
57
|
+
slots the body uses and the library functions it calls. OneJS's Unity shader is
|
|
58
|
+
one frame over it (`hlsl.ts`); Magerie's compute kernel is another, and its
|
|
59
|
+
target is in `src/body.test.ts` so an opcode cannot change without the text
|
|
60
|
+
Magerie compiles changing in front of a test. The library functions' own text
|
|
61
|
+
arrives with the translator (`Specs/SL_PACKAGE.md` section 5); until then a host
|
|
62
|
+
takes them from OneJS's `SLCommon.cginc`, `Noise2D.cginc` and `SDF2D.cginc`.
|
|
63
|
+
|
|
64
|
+
A uniform declared with a hex default (`uniform float4 tint = #ff8040;`), or
|
|
65
|
+
with `sl.uniform.colour`, is marked `colour: true`: its value is sRGB as
|
|
66
|
+
written, which is what a colour picker shows, and its reads convert. `inputsUsed`
|
|
67
|
+
says which inputs the result depends on, dead nodes aside, so a host knows
|
|
68
|
+
whether a program animates.
|
|
69
|
+
|
|
70
|
+
## Goldens
|
|
71
|
+
|
|
72
|
+
`goldens/goldens.json` is every corpus fixture drawn as a Linear OneJS game
|
|
73
|
+
stores it: the package's WGSL and GLSL ES in OneJS's web frame, into an
|
|
74
|
+
`rgba8unorm-srgb` target (the format the element's render texture has), read
|
|
75
|
+
back raw, with no Unity, no UI Toolkit and no browser colour management. A
|
|
76
|
+
second host's own backend is checked against it; OneJS's parity harness is what
|
|
77
|
+
proves the web emitters equal the VM in the first place.
|
|
78
|
+
|
|
79
|
+
`npm run goldens` draws it on WebGPU and WebGL2 in a Chrome with its own
|
|
80
|
+
profile (set `CHROME` to choose one). The two backends must agree within 1/255
|
|
81
|
+
over every pixel, and three anchors must match arithmetic, not each other:
|
|
82
|
+
`orient.sl` (orientation, and the linear to sRGB store), `hex.sl` (a hex colour
|
|
83
|
+
stores as written) and `texture.sl` (a texture's orientation and sRGB decode).
|
|
84
|
+
The file describes the sampling grid, the times and the texture every sampled
|
|
85
|
+
slot gets. No CI runner here has a GPU, so `src/goldens.test.ts` checks instead
|
|
86
|
+
that the file still covers the corpus at today's hashes; a change that moves a
|
|
87
|
+
hash fails there until the goldens are drawn again.
|
|
88
|
+
|
|
48
89
|
## Runs anywhere ES2020 runs
|
|
49
90
|
|
|
50
91
|
The source reaches for no host API: no `fs`, `process`, `Buffer`,
|
|
@@ -56,7 +97,7 @@ and QuickJS (Magerie). Two checks hold it to that:
|
|
|
56
97
|
- `npm run test:quickjs` bundles `quickjs/corpus.ts` as one ES2020 IIFE, the
|
|
57
98
|
way Magerie bundles a script, runs it in QuickJS-ng and in a bare Node
|
|
58
99
|
context, and fails unless the two results agree byte for byte. The corpus
|
|
59
|
-
parses, encodes, fits and emits every program in `
|
|
100
|
+
parses, encodes, fits and emits every program in `corpus/`, every
|
|
60
101
|
shape at its full parameter count, and the error paths. `npm test` runs it
|
|
61
102
|
after vitest.
|
|
62
103
|
|