onejs-sl 0.1.12 → 0.1.13

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.13
4
+
5
+ Unity's Metal compile of OneJS's effects no longer warns of an uninitialized variable. Nothing draws differently.
6
+
7
+ - `onejsFbmKind` returns once, so FxSources compiles on Metal with no warning
8
+ - A WGSL noise kind no longer evaluates both fBm kinds to pick one
9
+
3
10
  ## 0.1.12
4
11
 
5
12
  The noise hashes are integer arithmetic, so every GPU draws the same bits. Value noise and voronoi look different, seed 0 included; program hashes do not change.
package/README.md CHANGED
@@ -115,8 +115,8 @@ know the project's colour space when it prints.
115
115
  difference, the `.cginc` copies included in the container, and OneJS's
116
116
  `SLSharedLibraryTests` checks them from the other side. What proves the
117
117
  translations draw the same picture: the goldens compile the whole library on
118
- WebGPU and WebGL2 and draw every fixture; OneJS's parity harness holds the web
119
- output to the VM; `SLSharedLibraryTests` draws every corpus program in Unity
118
+ WebGPU and WebGL2 and draw every fixture; OneJS's parity harness draws every
119
+ fixture through a real WebGL player and holds it to the goldens; `SLSharedLibraryTests` draws every corpus program in Unity
120
120
  through `SLCommon.cginc` and through the translated shared subset and requires
121
121
  them to agree; and the Metal check above compiles the shared subset.
122
122
 
@@ -125,9 +125,11 @@ them to agree; and the Metal check above compiles the shared subset.
125
125
  `goldens/goldens.json` is every corpus fixture drawn as a Linear OneJS game
126
126
  stores it: the package's WGSL and GLSL ES in OneJS's web frame, into an
127
127
  `rgba8unorm-srgb` target (the format the element's render texture has), read
128
- back raw, with no Unity, no UI Toolkit and no browser colour management. A
129
- second host's own backend is checked against it; OneJS's parity harness is what
130
- proves the web emitters equal the VM in the first place.
128
+ back raw, with no Unity, no UI Toolkit and no browser colour management. The
129
+ goldens stand on their own: the two backends must agree, and the anchors and
130
+ the hash probes must match arithmetic. A host's own backend is checked against
131
+ them, as OneJS's parity harness (`Tools/sl-web-parity` in the container) checks
132
+ what a WebGL player draws.
131
133
 
132
134
  `npm run goldens` draws it on WebGPU and WebGL2 in a Chrome with its own
133
135
  profile (set `CHROME` to choose one). The two backends must agree within 1/255
@@ -202,17 +204,17 @@ container this package is checked out at `JSModules/onejs-sl`, and
202
204
 
203
205
  ## The one idea
204
206
 
205
- **One authoring surface, one IR, two backends.** Unity cannot compile a shader
206
- at runtime in a player build, on any graphics API, so in the browser a program
207
- has to become data that a fixed shader evaluates. Ejecting to a Unity project
208
- does not change what the author wrote, it changes what is possible, because an
209
- editor compiles shaders at build time.
207
+ **One authoring surface, one IR, several backends.** Unity cannot compile a
208
+ shader at runtime in a player build, on any graphics API, so the first backend
209
+ made a program data that a fixed shader evaluates: a VM. An editor does compile
210
+ shaders, at build time, so the second prints HLSL for it.
210
211
 
211
- So the same source is interpreted by a VM on play.onejs.com and compiled from
212
- generated HLSL after an eject, with no edit in between. Both backends exist:
212
+ So the same source draws compiled from generated HLSL in the editor and in a
213
+ native player, with no edit in between, and the VM stays behind a switch: OneJS
214
+ leaves it out unless a project defines `ONEJS_SL_VM`. Both backends exist:
213
215
  `encode.ts` feeds OneJS's `Runtime/SL/SLProgramBridge.cs` and `FxProgram.shader`,
214
216
  and `hlsl.ts` feeds its `Editor/SLShaderGenerator.cs`. Nobody writes a manifest for the
215
- second: an editor that interprets a program asks the encoded program for its
217
+ second: an editor that draws a program asks the encoded program for its
216
218
  `hlsl` (a lazy getter, never read in Play), records it into
217
219
  `Assets/OneJS/Recorded.sl.json`, generates the shader and
218
220
  moves the live material onto it. `manifest()` is still there for an app that
@@ -223,10 +225,11 @@ shader, but the page it runs in can. `web.ts` prints every program as WGSL and
223
225
  as GLSL ES 3.00 (carrying the library functions it calls, translated from
224
226
  `lib/*.hlsl`), and OneJS's
225
227
  `Plugins/WebGL/OneJSSLWeb.jslib` compiles whichever one Unity's device speaks
226
- and draws it into the element's target in place of the VM. A `.sl` import
227
- carries both strings, printed at build time; an `encode()` result has them as
228
- lazy getters, like `hlsl`. The VM draws until the compiled program is ready,
229
- and for good if it fails to compile. The host contract (the frame block, the
228
+ and draws it into the element's target. A `.sl` import carries both strings,
229
+ printed at build time; an `encode()` result has them as lazy getters, like
230
+ `hlsl`. A WebGL player has no VM: the element draws nothing until the compiled
231
+ program is ready, and nothing after a compile error, which the page reports.
232
+ The host contract (the frame block, the
230
233
  16 uniform slots, one binding pair per sampled texture) is written out at the
231
234
  top of `web.ts`.
232
235
 
@@ -234,7 +237,7 @@ The emitters match the HLSL emitter's semantics rather than each language's
234
237
  own: `%` truncates like `fmod`, `pow` takes `abs` of its base, `asin` and
235
238
  `acos` clamp, `log` and `sqrt` guard their argument, a select is the VM's
236
239
  branchless `lerp`. `web.test.ts` checks the structure (every shape, every
237
- opcode, the library order); whether the output matches the VM within 1/255 is
240
+ opcode, the library order); whether the output matches the goldens is
238
241
  measured in a browser, through the real element, by `Tools/sl-web-parity` in
239
242
  the container.
240
243
 
@@ -294,8 +297,10 @@ baseline, which is the one resource neither backend can widen.
294
297
 
295
298
  `Program.hash` is what will link a program to its compiled shader. If it differs
296
299
  between the machine that generated the shader and the machine that runs it, the
297
- runtime falls back to the VM and **nobody is told**: correct output, quietly
298
- slow, no error. That is the worst failure this design can have.
300
+ player finds no shader for the program: it draws nothing and logs one error
301
+ naming the hash. Before OneJS 3.6.0 it fell back to the VM and **nobody was
302
+ told**: correct output, quietly slow, no error, the worst failure this design
303
+ could have, and the reason the hash is built the way it is.
299
304
 
300
305
  So it is a Merkle hash over the graph reachable from the result, not a walk of
301
306
  the node array. An earlier version hashed storage order, which meant hoisting a
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "generatedBy": "onejs-sl goldens/run.mjs",
3
- "package": "0.1.12",
3
+ "package": "0.1.13",
4
4
  "ir": 2,
5
5
  "target": "rgba8unorm-srgb: straight alpha, 8 bit, sRGB encoded, the stored bytes of a Linear OneJS game's element",
6
6
  "size": [
package/lib/noise2d.hlsl CHANGED
@@ -213,10 +213,16 @@ float onejsRidged(float2 p, float seed, int octaves, float lacunarity, float gai
213
213
 
214
214
  /// Dispatches on the noise kind: 0 value fBm, 1 simplex fBm, 2 turbulence,
215
215
  /// 3 ridged. The numbers are the contract with onejs-unity/src/fx/image.ts.
216
+ ///
217
+ /// One return, at the end. Written with early returns, every path still
218
+ /// returns, but Unity's Metal compile warns of a potentially uninitialized
219
+ /// variable named after this function in every project that imports OneJS.
216
220
  float onejsFbmKind(int kind, float2 p, float seed, int octaves, float lacunarity, float gain)
217
221
  {
218
- if (kind == 2) return onejsTurbulence(p, seed, octaves, lacunarity, gain);
219
- if (kind == 3) return onejsRidged(p, seed, octaves, lacunarity, gain);
220
- return kind == 1 ? onejsFbmSimplex(p, seed, octaves, lacunarity, gain)
221
- : onejsFbm(p, seed, octaves, lacunarity, gain);
222
+ float n;
223
+ if (kind == 2) n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
224
+ else if (kind == 3) n = onejsRidged(p, seed, octaves, lacunarity, gain);
225
+ else if (kind == 1) n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
226
+ else n = onejsFbm(p, seed, octaves, lacunarity, gain);
227
+ return n;
222
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onejs-sl",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "The OneJS shader language: a small typed language for per pixel programs, compiled to a portable IR and emitted as HLSL, WGSL, GLSL ES or a VM buffer",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/lib/glsl.ts CHANGED
@@ -710,13 +710,17 @@ float onejsRidged(vec2 p, float seed, int octaves, float lacunarity, float gain)
710
710
  `,
711
711
  `
712
712
  float onejsFbmKind(int kind, vec2 p, float seed, int octaves, float lacunarity, float gain) {
713
+ float n;
713
714
  if (kind == 2) {
714
- return onejsTurbulence(p, seed, octaves, lacunarity, gain);
715
- }
716
- if (kind == 3) {
717
- return onejsRidged(p, seed, octaves, lacunarity, gain);
715
+ n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
716
+ } else if (kind == 3) {
717
+ n = onejsRidged(p, seed, octaves, lacunarity, gain);
718
+ } else if (kind == 1) {
719
+ n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
720
+ } else {
721
+ n = onejsFbm(p, seed, octaves, lacunarity, gain);
718
722
  }
719
- return kind == 1 ? onejsFbmSimplex(p, seed, octaves, lacunarity, gain) : onejsFbm(p, seed, octaves, lacunarity, gain);
723
+ return n;
720
724
  }
721
725
  `,
722
726
  `
package/src/lib/hlsl.ts CHANGED
@@ -710,13 +710,17 @@ float onejsRidged(float2 p, float seed, int octaves, float lacunarity, float gai
710
710
  `,
711
711
  `
712
712
  float onejsFbmKind(int kind, float2 p, float seed, int octaves, float lacunarity, float gain) {
713
+ float n;
713
714
  if (kind == 2) {
714
- return onejsTurbulence(p, seed, octaves, lacunarity, gain);
715
- }
716
- if (kind == 3) {
717
- return onejsRidged(p, seed, octaves, lacunarity, gain);
715
+ n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
716
+ } else if (kind == 3) {
717
+ n = onejsRidged(p, seed, octaves, lacunarity, gain);
718
+ } else if (kind == 1) {
719
+ n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
720
+ } else {
721
+ n = onejsFbm(p, seed, octaves, lacunarity, gain);
718
722
  }
719
- return kind == 1 ? onejsFbmSimplex(p, seed, octaves, lacunarity, gain) : onejsFbm(p, seed, octaves, lacunarity, gain);
723
+ return n;
720
724
  }
721
725
  `,
722
726
  `
package/src/lib/wgsl.ts CHANGED
@@ -761,13 +761,17 @@ fn onejsRidged(pIn: vec2f, seed: f32, octaves: i32, lacunarity: f32, gain: f32)
761
761
  `,
762
762
  `
763
763
  fn onejsFbmKind(kind: i32, p: vec2f, seed: f32, octaves: i32, lacunarity: f32, gain: f32) -> f32 {
764
+ var n: f32;
764
765
  if (kind == 2) {
765
- return onejsTurbulence(p, seed, octaves, lacunarity, gain);
766
- }
767
- if (kind == 3) {
768
- return onejsRidged(p, seed, octaves, lacunarity, gain);
766
+ n = onejsTurbulence(p, seed, octaves, lacunarity, gain);
767
+ } else if (kind == 3) {
768
+ n = onejsRidged(p, seed, octaves, lacunarity, gain);
769
+ } else if (kind == 1) {
770
+ n = onejsFbmSimplex(p, seed, octaves, lacunarity, gain);
771
+ } else {
772
+ n = onejsFbm_f2_f_i_f_f(p, seed, octaves, lacunarity, gain);
769
773
  }
770
- return select(onejsFbm_f2_f_i_f_f(p, seed, octaves, lacunarity, gain), onejsFbmSimplex(p, seed, octaves, lacunarity, gain), kind == 1);
774
+ return n;
771
775
  }
772
776
  `,
773
777
  `