@null3d/engine 0.0.0 → 0.1.0

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.
Files changed (311) hide show
  1. package/README.md +109 -0
  2. package/THIRD-PARTY-NOTICES.txt +0 -1
  3. package/dist/wasm/single/null3d.js +19 -6
  4. package/dist/wasm/single/null3d_bg.wasm +0 -0
  5. package/dist/wasm/threaded/null3d.js +19 -6
  6. package/dist/wasm/threaded/null3d_bg.wasm +0 -0
  7. package/docs/api/animation.md +23 -67
  8. package/docs/api/assets.md +42 -26
  9. package/docs/api/cameras.md +8 -6
  10. package/docs/api/controls.md +46 -44
  11. package/docs/api/debug.md +13 -8
  12. package/docs/api/engine.md +17 -11
  13. package/docs/api/feature-draws.md +3 -3
  14. package/docs/api/feature-effects.md +3 -3
  15. package/docs/api/feature-instances.md +2 -2
  16. package/docs/api/features.md +14 -15
  17. package/docs/api/geometry.md +56 -75
  18. package/docs/api/grass.md +1 -1
  19. package/docs/api/impostors.md +120 -9
  20. package/docs/api/input.md +4 -11
  21. package/docs/api/lights.md +14 -38
  22. package/docs/api/lines.md +8 -25
  23. package/docs/api/materials.md +69 -70
  24. package/docs/api/math.md +6 -7
  25. package/docs/api/objects.md +13 -13
  26. package/docs/api/particles.md +2 -14
  27. package/docs/api/points.md +3 -25
  28. package/docs/api/post.md +22 -23
  29. package/docs/api/quality.md +11 -6
  30. package/docs/api/raycast.md +13 -32
  31. package/docs/api/reference/animation.md +9 -9
  32. package/docs/api/reference/assets.md +18 -18
  33. package/docs/api/reference/cameras.md +5 -2
  34. package/docs/api/reference/controls.md +75 -23
  35. package/docs/api/reference/debug.md +23 -8
  36. package/docs/api/reference/engine.md +22 -10
  37. package/docs/api/reference/geometry.md +161 -82
  38. package/docs/api/reference/grass.md +1 -1
  39. package/docs/api/reference/impostors.md +92 -1
  40. package/docs/api/reference/input.md +3 -3
  41. package/docs/api/reference/lights.md +9 -9
  42. package/docs/api/reference/lines.md +7 -7
  43. package/docs/api/reference/materials.md +48 -48
  44. package/docs/api/reference/math.md +22 -22
  45. package/docs/api/reference/objects.md +9 -9
  46. package/docs/api/reference/points.md +4 -4
  47. package/docs/api/reference/post.md +18 -18
  48. package/docs/api/reference/quality.md +7 -3
  49. package/docs/api/reference/raycast.md +6 -6
  50. package/docs/api/reference/render.md +2 -2
  51. package/docs/api/reference/scene.md +29 -26
  52. package/docs/api/reference/sketch.md +4 -0
  53. package/docs/api/reference/sound.md +203 -0
  54. package/docs/api/reference/sprites.md +5 -5
  55. package/docs/api/reference/terrain.md +2 -1
  56. package/docs/api/reference/textures.md +4 -4
  57. package/docs/api/reference/ui.md +3 -3
  58. package/docs/api/reference/vertex-draws.md +3 -3
  59. package/docs/api/reference/water.md +77 -6
  60. package/docs/api/reference/wind.md +2 -2
  61. package/docs/api/render.md +12 -10
  62. package/docs/api/scene.md +40 -29
  63. package/docs/api/sketch.md +64 -3
  64. package/docs/api/sound.md +169 -0
  65. package/docs/api/splats.md +7 -0
  66. package/docs/api/sprites.md +4 -20
  67. package/docs/api/tasks.md +2 -2
  68. package/docs/api/terrain.md +2 -14
  69. package/docs/api/textures.md +9 -9
  70. package/docs/api/ui.md +3 -15
  71. package/docs/api/water.md +198 -15
  72. package/docs/api/wind.md +5 -5
  73. package/docs/cli/null3d.md +93 -18
  74. package/docs/concepts/architecture.md +10 -10
  75. package/docs/concepts/assets.md +2 -19
  76. package/docs/concepts/backends.md +7 -5
  77. package/docs/concepts/color-management.md +15 -26
  78. package/docs/concepts/culling.md +1 -1
  79. package/docs/concepts/instances.md +5 -5
  80. package/docs/concepts/large-worlds.md +1 -1
  81. package/docs/concepts/lighting.md +50 -55
  82. package/docs/concepts/lod.md +2 -15
  83. package/docs/concepts/materials.md +16 -16
  84. package/docs/concepts/post-processing.md +7 -29
  85. package/docs/concepts/quality-preset-tables.md +53 -50
  86. package/docs/concepts/quality-presets.md +56 -27
  87. package/docs/concepts/render-graph.md +19 -14
  88. package/docs/concepts/render-layers.md +3 -17
  89. package/docs/concepts/shadows.md +10 -28
  90. package/docs/concepts/static-dynamic.md +2 -2
  91. package/docs/cookbook/index.md +1 -1
  92. package/docs/data/threejs-mapping.json +136 -102
  93. package/docs/errors/E1214.md +3 -3
  94. package/docs/errors/E1307.md +23 -0
  95. package/docs/errors/E1420.md +3 -3
  96. package/docs/errors/index.md +3 -2
  97. package/docs/getting-started/cdn.md +17 -1
  98. package/docs/getting-started/first-scene.md +1 -1
  99. package/docs/getting-started/hosting.md +50 -9
  100. package/docs/getting-started/install.md +8 -7
  101. package/docs/getting-started/network-use.md +10 -2
  102. package/docs/getting-started/project-structure.md +15 -6
  103. package/docs/getting-started/third-party-notices.md +8 -6
  104. package/docs/guides/accessibility.md +1 -1
  105. package/docs/guides/add-ons.md +3 -2
  106. package/docs/guides/agents.md +16 -5
  107. package/docs/guides/assets-pipeline.md +13 -12
  108. package/docs/guides/audio.md +109 -124
  109. package/docs/guides/car-paint.md +1 -1
  110. package/docs/guides/content-pages.md +10 -6
  111. package/docs/guides/custom-passes.md +9 -8
  112. package/docs/guides/custom-shaders.md +6 -3
  113. package/docs/guides/debugging.md +78 -4
  114. package/docs/guides/deploying.md +105 -5
  115. package/docs/guides/deterministic-simulation.md +1 -1
  116. package/docs/guides/first-use-shaders.md +4 -4
  117. package/docs/guides/loading-screens.md +78 -33
  118. package/docs/guides/multiple-views.md +41 -2
  119. package/docs/guides/performance.md +6 -3
  120. package/docs/guides/phones.md +12 -1
  121. package/docs/guides/physics.md +1 -1
  122. package/docs/guides/screens.md +7 -5
  123. package/docs/guides/start-time.md +328 -0
  124. package/docs/guides/testing.md +23 -5
  125. package/docs/guides/ui-overlays.md +3 -3
  126. package/docs/index.md +12 -8
  127. package/docs/pages.md +26 -23
  128. package/docs/porting/react-three-fiber.md +228 -5
  129. package/docs/porting/threejs-loop-and-threads.md +220 -6
  130. package/docs/porting/threejs-mapping.md +86 -84
  131. package/docs/porting/threejs-materials.md +212 -5
  132. package/docs/porting/threejs-overview.md +218 -5
  133. package/docs/porting/threejs-postprocessing.md +2 -2
  134. package/docs/porting/threejs-shaders.md +298 -5
  135. package/docs/porting/threejs-unsupported.md +82 -6
  136. package/docs/porting/verification.md +181 -5
  137. package/docs/shaders/builtins.md +1 -1
  138. package/docs/shaders/library.md +63 -39
  139. package/docs/shaders/surface-functions.md +11 -10
  140. package/docs/shaders/wgsl-rules.md +1 -1
  141. package/lib/debug/channel.d.ts +103 -0
  142. package/lib/debug/channel.js +269 -0
  143. package/lib/debug/debug.d.ts +9 -7
  144. package/lib/debug/draw.d.ts +9 -0
  145. package/lib/debug/draw.js +49 -2
  146. package/lib/debug/inspector.d.ts +60 -0
  147. package/lib/debug/inspector.js +475 -0
  148. package/lib/debug/stats-panel.d.ts +1 -1
  149. package/lib/debug/stats.d.ts +2 -3
  150. package/lib/errors/codes.js +8 -2
  151. package/lib/errors/engine-error.js +25 -10
  152. package/lib/errors/fixes.d.ts +1 -0
  153. package/lib/errors/fixes.js +3 -2
  154. package/lib/generated/core.d.ts +1 -1
  155. package/lib/generated/core.js +1 -1
  156. package/lib/gpu/early-builds.d.ts +68 -0
  157. package/lib/gpu/early-builds.js +158 -0
  158. package/lib/gpu/pipeline-name.d.ts +6 -0
  159. package/lib/gpu/pipeline-name.js +23 -0
  160. package/lib/gpu/webgl2/backend.d.ts +63 -2
  161. package/lib/gpu/webgl2/backend.js +226 -8
  162. package/lib/gpu/webgl2/programs.d.ts +18 -0
  163. package/lib/gpu/webgl2/programs.js +4 -1
  164. package/lib/gpu/webgpu/backend.d.ts +89 -2
  165. package/lib/gpu/webgpu/backend.js +255 -8
  166. package/lib/gpu/webgpu/pipelines.d.ts +13 -0
  167. package/lib/gpu/webgpu/pipelines.js +15 -1
  168. package/lib/index.d.ts +6 -4
  169. package/lib/index.js +3 -2
  170. package/lib/math/color.d.ts +5 -5
  171. package/lib/math/color.js +5 -5
  172. package/lib/math/mat4.d.ts +6 -12
  173. package/lib/math/mat4.js +6 -12
  174. package/lib/math/namespaces/quat.d.ts +3 -3
  175. package/lib/math/namespaces/quat.js +3 -3
  176. package/lib/math/quat.d.ts +8 -12
  177. package/lib/math/quat.js +8 -12
  178. package/lib/math/random.d.ts +2 -3
  179. package/lib/math/random.js +2 -3
  180. package/lib/math/types.d.ts +4 -4
  181. package/lib/math/vec3.d.ts +3 -6
  182. package/lib/math/vec3.js +3 -6
  183. package/lib/page/capabilities.d.ts +7 -7
  184. package/lib/page/capabilities.js +39 -25
  185. package/lib/page/check-store.d.ts +14 -2
  186. package/lib/page/check-store.js +34 -11
  187. package/lib/page/engine.d.ts +103 -26
  188. package/lib/page/engine.js +420 -97
  189. package/lib/page/first-frame.d.ts +16 -0
  190. package/lib/page/first-frame.js +35 -0
  191. package/lib/page/frame-stats.d.ts +34 -1
  192. package/lib/page/frame-stats.js +15 -0
  193. package/lib/page/label-loop.d.ts +7 -3
  194. package/lib/page/label-loop.js +17 -10
  195. package/lib/page/labels.d.ts +3 -3
  196. package/lib/page/pipeline-store.d.ts +25 -0
  197. package/lib/page/pipeline-store.js +84 -0
  198. package/lib/page/start-marker.d.ts +4 -1
  199. package/lib/page/start-marker.js +5 -2
  200. package/lib/page/switches.d.ts +32 -2
  201. package/lib/page/switches.js +9 -1
  202. package/lib/quality/check.d.ts +24 -3
  203. package/lib/quality/check.js +21 -7
  204. package/lib/quality/chooser.d.ts +6 -0
  205. package/lib/quality/chooser.js +8 -0
  206. package/lib/quality/governor.d.ts +98 -6
  207. package/lib/quality/governor.js +250 -20
  208. package/lib/quality/preset-docs.d.ts +16 -1
  209. package/lib/quality/preset-docs.js +3 -0
  210. package/lib/quality/presets.d.ts +84 -7
  211. package/lib/quality/presets.js +94 -2
  212. package/lib/render/draw.d.ts +3 -2
  213. package/lib/render/draw.js +15 -5
  214. package/lib/render/load-draw.d.ts +7 -5
  215. package/lib/render/load-draw.js +7 -5
  216. package/lib/render/loss.d.ts +28 -10
  217. package/lib/render/loss.js +50 -22
  218. package/lib/render/recovery.d.ts +20 -0
  219. package/lib/render/recovery.js +44 -4
  220. package/lib/render/renderer.d.ts +85 -9
  221. package/lib/render/renderer.js +181 -42
  222. package/lib/render/scene-renderer.d.ts +19 -1
  223. package/lib/render/scene-renderer.js +25 -1
  224. package/lib/render/webgl2-renderers.js +8 -5
  225. package/lib/render/webgpu-renderers.js +5 -4
  226. package/lib/scene/animation.d.ts +28 -32
  227. package/lib/scene/animation.js +12 -15
  228. package/lib/scene/assets.d.ts +61 -86
  229. package/lib/scene/assets.js +103 -236
  230. package/lib/scene/background.d.ts +14 -18
  231. package/lib/scene/background.js +5 -2
  232. package/lib/scene/color.d.ts +3 -3
  233. package/lib/scene/downloads.d.ts +2 -0
  234. package/lib/scene/downloads.js +371 -0
  235. package/lib/scene/environment.d.ts +7 -7
  236. package/lib/scene/environment.js +1 -1
  237. package/lib/scene/fake-call-values.js +1 -1
  238. package/lib/scene/fog.d.ts +11 -4
  239. package/lib/scene/fog.js +8 -2
  240. package/lib/scene/frame-cameras.d.ts +19 -0
  241. package/lib/scene/frame-cameras.js +58 -0
  242. package/lib/scene/gltf.d.ts +32 -2
  243. package/lib/scene/gltf.js +78 -49
  244. package/lib/scene/grading.d.ts +2 -2
  245. package/lib/scene/grading.js +3 -3
  246. package/lib/scene/ktx2.d.ts +9 -1
  247. package/lib/scene/ktx2.js +3 -2
  248. package/lib/scene/level-rule.d.ts +120 -0
  249. package/lib/scene/level-rule.js +130 -0
  250. package/lib/scene/lines.d.ts +13 -17
  251. package/lib/scene/lines.js +3 -3
  252. package/lib/scene/lut.d.ts +1 -2
  253. package/lib/scene/lut.js +1 -2
  254. package/lib/scene/picks.d.ts +2 -2
  255. package/lib/scene/pointer-events.d.ts +4 -7
  256. package/lib/scene/post.d.ts +38 -43
  257. package/lib/scene/post.js +4 -1
  258. package/lib/scene/prefab.d.ts +7 -8
  259. package/lib/scene/prefab.js +7 -8
  260. package/lib/scene/property-animation.d.ts +1 -1
  261. package/lib/scene/property-animation.js +1 -1
  262. package/lib/scene/queries.d.ts +7 -13
  263. package/lib/scene/resources.d.ts +225 -254
  264. package/lib/scene/resources.js +179 -81
  265. package/lib/scene/scene.d.ts +149 -118
  266. package/lib/scene/scene.js +196 -98
  267. package/lib/scene/serial-loads.d.ts +29 -0
  268. package/lib/scene/serial-loads.js +68 -0
  269. package/lib/scene/shader-preloads.d.ts +34 -0
  270. package/lib/scene/shader-preloads.js +38 -0
  271. package/lib/scene/sprites.d.ts +14 -17
  272. package/lib/scene/sprites.js +5 -6
  273. package/lib/scene/textures.d.ts +11 -12
  274. package/lib/scene/textures.js +9 -10
  275. package/lib/scene/time-of-day.d.ts +3 -4
  276. package/lib/scene/time-of-day.js +2 -3
  277. package/lib/scene/vertex-draws.d.ts +5 -4
  278. package/lib/scene/vertex-draws.js +7 -5
  279. package/lib/shader-artifact.json +1 -0
  280. package/lib/shared/core.d.ts +5 -0
  281. package/lib/shared/core.js +1 -0
  282. package/lib/shared/import-once.d.ts +6 -0
  283. package/lib/shared/import-once.js +19 -0
  284. package/lib/shared/metrics.d.ts +38 -0
  285. package/lib/shared/metrics.js +62 -1
  286. package/lib/shared/run-task.js +7 -1
  287. package/lib/shared/task-pending.d.ts +12 -0
  288. package/lib/shared/task-pending.js +61 -1
  289. package/lib/shared/tasks.js +79 -32
  290. package/lib/shared/version.d.ts +17 -1
  291. package/lib/shared/version.js +19 -1
  292. package/lib/shared/wasm.d.ts +12 -4
  293. package/lib/shared/wasm.js +50 -27
  294. package/lib/shared/worker-start.d.ts +7 -0
  295. package/lib/shared/worker-start.js +27 -0
  296. package/lib/sketch/define-sketch.d.ts +35 -0
  297. package/lib/sketch/input.d.ts +2 -2
  298. package/lib/sketch/preset-check.d.ts +20 -6
  299. package/lib/sketch/preset-check.js +42 -17
  300. package/lib/sketch/quality.d.ts +69 -11
  301. package/lib/sketch/quality.js +54 -13
  302. package/lib/sketch/runner.d.ts +76 -9
  303. package/lib/sketch/runner.js +385 -52
  304. package/lib/sketch/ui.d.ts +5 -8
  305. package/lib/workers/probe-worker.d.ts +5 -0
  306. package/lib/workers/probe-worker.js +13 -4
  307. package/lib/workers/protocol.d.ts +61 -13
  308. package/lib/workers/protocol.js +4 -0
  309. package/lib/workers/render-worker.js +25 -4
  310. package/lib/workers/sketch-worker.js +104 -15
  311. package/package.json +2 -2
@@ -376,7 +376,7 @@ export const POST_VALUE_SSR_THICKNESS = 61;
376
376
  export const POST_VALUE_SSR_MAX_ROUGHNESS = 62;
377
377
  export const POST_VALUE_SHARPEN = 63;
378
378
  export const POST_VALUE_COUNT = 64;
379
- export const CALL_VALUE_COUNT = 10;
379
+ export const CALL_VALUE_COUNT = 11;
380
380
  export const ENVIRONMENT_VALUE_INTENSITY = 0;
381
381
  export const ENVIRONMENT_VALUE_ROTATION = 1;
382
382
  export const ENVIRONMENT_VALUE_SH = 4;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The operands that follow a create command's id: a render pipeline's template, permutation,
3
+ * color and depth formats, sample count, state flags, vertex format, and depth bias and slope; a
4
+ * compute pipeline's template and permutation.
5
+ */
6
+ export declare function operandsAfterId(op: number): number;
7
+ /** The most pipelines that a list holds. A scene's first frame builds well under a hundred. */
8
+ export declare const PIPELINE_LIST_LIMIT = 512;
9
+ /**
10
+ * The create commands of the pipelines that a thread builds before its first frame, as a pipeline
11
+ * list: each command's op, then its operands after its id. Commands of equal operands, such as an
12
+ * add-on's compute passes of one shader, are listed once.
13
+ */
14
+ export declare class PipelineListing {
15
+ private words;
16
+ private readonly keys;
17
+ /** True until `take` ends the listing. */
18
+ get active(): boolean;
19
+ /** Lists the command `op` whose operands start with its id at `a`. */
20
+ add(op: number, words: Uint32Array, a: number): void;
21
+ /** Ends the listing and returns its list, or undefined after the first call or for no pipeline. */
22
+ take(): Uint32Array | undefined;
23
+ }
24
+ /** A build that started before its command came. */
25
+ export interface EarlyBuild<P> {
26
+ /** The pipeline, once it is built. */
27
+ pipeline: P | undefined;
28
+ /** True once the build failed: the command then builds its pipeline itself, and meets the error. */
29
+ failed: boolean;
30
+ readonly done: Promise<P>;
31
+ }
32
+ /**
33
+ * Starts a listed pipeline's build from the command's operands, with a zero id first: the build,
34
+ * or undefined while its shader has not arrived, or null when it does not build ahead.
35
+ */
36
+ export type EarlyStarter<P> = (op: number, operands: Uint32Array) => Promise<P> | undefined | null;
37
+ /** Each list key that a command's operands make: its op and its operands after its id. */
38
+ export declare function keyOf(op: number, words: Uint32Array, a: number): string;
39
+ /**
40
+ * The builds of a pipeline list. Each starts as soon as `start` can build it, and the commands that
41
+ * create the same pipelines take them. `stop` drops the builds that no command took, once the first
42
+ * frame has drawn.
43
+ */
44
+ export declare class EarlyBuilds<P> {
45
+ private readonly start;
46
+ /** The listed commands whose builds wait for their shaders, as operands with a zero id first. */
47
+ private waiting;
48
+ private readonly started;
49
+ /** The keys of commands that came before their listed build started, which then never starts. */
50
+ private readonly claimed;
51
+ private timer;
52
+ constructor(list: Uint32Array, start: EarlyStarter<P>);
53
+ /** How many listed builds started so far. */
54
+ get startedCount(): number;
55
+ /**
56
+ * Starts each waiting build whose shader has arrived, and looks again a little later while any
57
+ * still waits. A command that cannot build here leaves the list, and its own build reports why.
58
+ */
59
+ private look;
60
+ /**
61
+ * The build that matches the command `op` whose operands start with its id at `a`, which leaves
62
+ * the list, or undefined when none started or the one that started failed. A listed build that
63
+ * has not started by then never does, as the command builds the pipeline itself.
64
+ */
65
+ take(op: number, words: Uint32Array, a: number): EarlyBuild<P> | undefined;
66
+ /** Stops the waiting builds and forgets the started ones that no command took. */
67
+ stop(): void;
68
+ }
@@ -0,0 +1,158 @@
1
+ // Pipelines that a start builds before the commands that create them arrive. The page keeps the list
2
+ // of the pipelines that the first frame of its sketch's last start built (`page/pipeline-store.ts`).
3
+ // The next start hands that list to the thread that draws, which starts each build as soon as the
4
+ // build's shader is there, while the core downloads and the setup runs. Without it, the first
5
+ // build starts only when the setup's first frame reaches the thread that draws. The first frame's
6
+ // commands then take the builds that match them. Equal operands make an equal pipeline, so a list
7
+ // from another start of the sketch only builds pipelines that no command takes.
8
+ import { OP_CREATE_COMPUTE_PIPELINE, OP_CREATE_RENDER_PIPELINE } from '../generated/gpu.js';
9
+ /**
10
+ * The operands that follow a create command's id: a render pipeline's template, permutation,
11
+ * color and depth formats, sample count, state flags, vertex format, and depth bias and slope; a
12
+ * compute pipeline's template and permutation.
13
+ */
14
+ export function operandsAfterId(op) {
15
+ return op === OP_CREATE_RENDER_PIPELINE ? 9 : 2;
16
+ }
17
+ /** The most pipelines that a list holds. A scene's first frame builds well under a hundred. */
18
+ export const PIPELINE_LIST_LIMIT = 512;
19
+ /**
20
+ * The create commands of the pipelines that a thread builds before its first frame, as a pipeline
21
+ * list: each command's op, then its operands after its id. Commands of equal operands, such as an
22
+ * add-on's compute passes of one shader, are listed once.
23
+ */
24
+ export class PipelineListing {
25
+ words = [];
26
+ keys = new Set();
27
+ /** True until `take` ends the listing. */
28
+ get active() {
29
+ return this.words !== undefined;
30
+ }
31
+ /** Lists the command `op` whose operands start with its id at `a`. */
32
+ add(op, words, a) {
33
+ const listed = this.words;
34
+ if (!listed || this.keys.size >= PIPELINE_LIST_LIMIT)
35
+ return;
36
+ const key = keyOf(op, words, a);
37
+ if (this.keys.has(key))
38
+ return;
39
+ this.keys.add(key);
40
+ listed.push(op);
41
+ const operands = operandsAfterId(op);
42
+ for (let k = 1; k <= operands; k++)
43
+ listed.push(words[a + k]);
44
+ }
45
+ /** Ends the listing and returns its list, or undefined after the first call or for no pipeline. */
46
+ take() {
47
+ const listed = this.words;
48
+ this.words = undefined;
49
+ this.keys.clear();
50
+ return listed && listed.length > 0 ? Uint32Array.from(listed) : undefined;
51
+ }
52
+ }
53
+ /** How often the builds that wait for their shaders look again, in ms. */
54
+ const WAIT_MS = 25;
55
+ /** Each list key that a command's operands make: its op and its operands after its id. */
56
+ export function keyOf(op, words, a) {
57
+ let key = String(op);
58
+ const operands = operandsAfterId(op);
59
+ for (let k = 1; k <= operands; k++)
60
+ key += ` ${words[a + k]}`;
61
+ return key;
62
+ }
63
+ /**
64
+ * The builds of a pipeline list. Each starts as soon as `start` can build it, and the commands that
65
+ * create the same pipelines take them. `stop` drops the builds that no command took, once the first
66
+ * frame has drawn.
67
+ */
68
+ export class EarlyBuilds {
69
+ start;
70
+ /** The listed commands whose builds wait for their shaders, as operands with a zero id first. */
71
+ waiting = [];
72
+ started = new Map();
73
+ /** The keys of commands that came before their listed build started, which then never starts. */
74
+ claimed = new Set();
75
+ timer;
76
+ constructor(list, start) {
77
+ this.start = start;
78
+ const keys = new Set();
79
+ for (let i = 0; i < list.length;) {
80
+ const op = list[i];
81
+ if (op !== OP_CREATE_RENDER_PIPELINE && op !== OP_CREATE_COMPUTE_PIPELINE)
82
+ break;
83
+ const operands = operandsAfterId(op);
84
+ if (i + 1 + operands > list.length)
85
+ break;
86
+ const command = new Uint32Array(operands + 1);
87
+ command.set(list.subarray(i + 1, i + 1 + operands), 1);
88
+ const key = keyOf(op, command, 0);
89
+ // A list from a start that listed equal commands apart builds each pipeline once.
90
+ if (!keys.has(key))
91
+ this.waiting.push({ op, operands: command, key });
92
+ keys.add(key);
93
+ i += 1 + operands;
94
+ }
95
+ this.look();
96
+ }
97
+ /** How many listed builds started so far. */
98
+ get startedCount() {
99
+ return this.started.size;
100
+ }
101
+ /**
102
+ * Starts each waiting build whose shader has arrived, and looks again a little later while any
103
+ * still waits. A command that cannot build here leaves the list, and its own build reports why.
104
+ */
105
+ look() {
106
+ this.timer = undefined;
107
+ const still = [];
108
+ for (const waiting of this.waiting) {
109
+ const { op, operands, key } = waiting;
110
+ let build = null;
111
+ if (!this.claimed.has(key))
112
+ try {
113
+ build = this.start(op, operands);
114
+ }
115
+ catch {
116
+ build = null;
117
+ }
118
+ if (build === undefined)
119
+ still.push(waiting);
120
+ if (!build)
121
+ continue;
122
+ const made = { pipeline: undefined, failed: false, done: build };
123
+ build.then((pipeline) => {
124
+ made.pipeline = pipeline;
125
+ }, () => {
126
+ made.failed = true;
127
+ });
128
+ this.started.set(key, made);
129
+ }
130
+ this.waiting = still;
131
+ if (still.length > 0)
132
+ this.timer = setTimeout(() => this.look(), WAIT_MS);
133
+ }
134
+ /**
135
+ * The build that matches the command `op` whose operands start with its id at `a`, which leaves
136
+ * the list, or undefined when none started or the one that started failed. A listed build that
137
+ * has not started by then never does, as the command builds the pipeline itself.
138
+ */
139
+ take(op, words, a) {
140
+ const key = keyOf(op, words, a);
141
+ const made = this.started.get(key);
142
+ if (!made) {
143
+ this.claimed.add(key);
144
+ return undefined;
145
+ }
146
+ this.started.delete(key);
147
+ return made.failed ? undefined : made;
148
+ }
149
+ /** Stops the waiting builds and forgets the started ones that no command took. */
150
+ stop() {
151
+ if (this.timer !== undefined)
152
+ clearTimeout(this.timer);
153
+ this.timer = undefined;
154
+ this.waiting = [];
155
+ this.started.clear();
156
+ this.claimed.clear();
157
+ }
158
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The name of the pipeline of `template` and `permutation`, from `label`, the template's own name.
3
+ * A template of the sketch's WGSL takes its label, or else counts as a custom material. One of the
4
+ * engine's own says so, before its label or its number.
5
+ */
6
+ export declare function pipelineName(template: number, permutation: number, label?: string): string;
@@ -0,0 +1,23 @@
1
+ // The name of a render pipeline for a message, the same on both GPU paths: its template's name, and
2
+ // the pass that its build draws in where that is not the shading.
3
+ import { SHADING_CUSTOM_FIRST } from '../generated/core.js';
4
+ import { PERMUTATION_CASTER, PERMUTATION_MOTION, PERMUTATION_PICK, PERMUTATION_PREPASS, TEMPLATE_MOTION, } from '../generated/gpu.js';
5
+ /**
6
+ * The name of the pipeline of `template` and `permutation`, from `label`, the template's own name.
7
+ * A template of the sketch's WGSL takes its label, or else counts as a custom material. One of the
8
+ * engine's own says so, before its label or its number.
9
+ */
10
+ export function pipelineName(template, permutation, label) {
11
+ const name = template >= SHADING_CUSTOM_FIRST
12
+ ? (label ?? `custom material ${template}`)
13
+ : `engine template ${label ?? template}`;
14
+ if (permutation & PERMUTATION_CASTER)
15
+ return `${name}, its shadow caster build`;
16
+ if (template !== TEMPLATE_MOTION && permutation & PERMUTATION_MOTION)
17
+ return `${name}, its motion build`;
18
+ if (permutation & PERMUTATION_PICK)
19
+ return `${name}, its pick build`;
20
+ if (permutation & PERMUTATION_PREPASS)
21
+ return `${name}, its depth prepass build`;
22
+ return name;
23
+ }
@@ -21,6 +21,13 @@ export interface CanvasTarget {
21
21
  * Metal's own convention, which needs no rewrite.
22
22
  */
23
23
  export declare function useFirstProvokingVertex(gl: WebGL2RenderingContext): void;
24
+ /**
25
+ * A framebuffer that a live context refused. The backend skips the frame and asks again on the
26
+ * next one, because a driver can answer a lost context's check with a refusal before the loss flag
27
+ * is set; the same refusal on the next frame is a format the device does not draw into.
28
+ */
29
+ export declare class WebGL2TargetRefused extends Error {
30
+ }
24
31
  export declare class WebGL2Backend {
25
32
  private readonly gl;
26
33
  private readonly canvas;
@@ -72,6 +79,13 @@ export declare class WebGL2Backend {
72
79
  readonly joins: JoinedBuilds;
73
80
  /** True once a list has replayed, after which no frame waits for a joined shader's compile. */
74
81
  private replayed;
82
+ /**
83
+ * How many frames in a row a live context has refused a target, and the target's message, so
84
+ * the next frame may refuse one again before the engine ends: a lost context can answer the
85
+ * check this way before its flag is set, and a cadence can put two targets in the way.
86
+ */
87
+ private refusedFrames;
88
+ private refusedTarget;
75
89
  /** The opcode and word of the command that the replay is carrying out. */
76
90
  private replayOp;
77
91
  private replayWord;
@@ -81,6 +95,10 @@ export declare class WebGL2Backend {
81
95
  * draws draw nothing.
82
96
  */
83
97
  private readonly parked;
98
+ /** The create commands of the pipelines that the lists before the first frame create. */
99
+ private readonly listing;
100
+ /** The compiles of the programs that the last start's first frame built, until this first frame. */
101
+ private early;
84
102
  /**
85
103
  * In development builds, the programs that a hot update of a custom material's shader compiles,
86
104
  * each under the key of the program it replaces once it has compiled. `relinked` is set once the
@@ -92,7 +110,16 @@ export declare class WebGL2Backend {
92
110
  * bits. Without it, every pipeline's build must be in the shaders that the backend got.
93
111
  */
94
112
  moreShaders: DeviceShaderSet | undefined;
95
- /** True while the current pipeline's program is compiling: draws draw nothing until it is set again. */
113
+ /**
114
+ * Hears each program of the scene's objects that the driver refused to link twice, by its
115
+ * pipeline's name and the link's logs. Its draws draw nothing from then on, and the frames go
116
+ * on without them.
117
+ */
118
+ refused: ((pipeline: string, reason: string) => void) | undefined;
119
+ /**
120
+ * True while the current pipeline's program is compiling, or after the driver refused it: draws
121
+ * draw nothing until it is set again.
122
+ */
96
123
  private skipDraws;
97
124
  private readonly anisotropic;
98
125
  private readonly maxAnisotropy;
@@ -245,6 +272,13 @@ export declare class WebGL2Backend {
245
272
  * first draw waits for its compile.
246
273
  */
247
274
  prepare(words: Uint32Array, start: number, end: number): number;
275
+ /**
276
+ * Starts to compile, in the background, the program of each pipeline that the list in
277
+ * `words[start, end)` creates after other commands. The frame before the first one then waits
278
+ * for them, as for the programs of the pipelines at the list's front, instead of its first draw
279
+ * with each waiting for its compile.
280
+ */
281
+ private compileAhead;
248
282
  /**
249
283
  * Where the draw section of the list in `words[start, end)` begins, after the pipelines it
250
284
  * creates. It walks the same ops as `prepare` and starts no build.
@@ -282,6 +316,20 @@ export declare class WebGL2Backend {
282
316
  * with a few of them, so `scene.warmUp()` builds those, as for any material.
283
317
  */
284
318
  precompile(features: readonly string[], module: FirstUseShaders): void;
319
+ /**
320
+ * Starts to compile the programs of `list`, a pipeline list of the pipelines that the first frame
321
+ * of the sketch's last start built (`gpu/early-builds.ts`). Each compile starts once its shader
322
+ * is there, and a pipeline of the same template and permutation takes the program. No frame
323
+ * waits for a program that no pipeline takes. A joined shader's program compiles when its
324
+ * pipeline comes, as its failure sends the effects back to a pass each.
325
+ */
326
+ buildEarly(list: Uint32Array): void;
327
+ /**
328
+ * Ends the list of the pipelines that the frames before the first one created, and returns it,
329
+ * once: the first frame has drawn. The compiles of the last start's list that have not started
330
+ * stop.
331
+ */
332
+ takeListing(): Uint32Array | undefined;
285
333
  /** Creates each parked pipeline whose custom material's shader has arrived. */
286
334
  private unpark;
287
335
  /**
@@ -300,9 +348,13 @@ export declare class WebGL2Backend {
300
348
  private countDraw;
301
349
  /**
302
350
  * Replays the draw list in `words[start, end)`. `floats` views the same memory as `words`, for
303
- * float operands; `memory` is the engine memory that uploads read from.
351
+ * float operands; `memory` is the engine memory that uploads read from. A target that a live
352
+ * context refuses ends the replay without an error, and the next frame asks again before the
353
+ * refusal is reported: a lost context can answer the check that way before its flag is set.
304
354
  */
305
355
  replay(words: Uint32Array, floats: Float32Array, start: number, end: number, memory: ArrayBufferLike): void;
356
+ /** Replays a draw list's commands, as `replay` describes them. */
357
+ private replayOps;
306
358
  /**
307
359
  * The program that draws mip levels, or the one that copies a layer, which starts compiling the
308
360
  * first time.
@@ -320,6 +372,15 @@ export declare class WebGL2Backend {
320
372
  * waits for its link when the driver has not finished it.
321
373
  */
322
374
  private spareProgram;
375
+ /**
376
+ * Puts a program of the scene's objects in use, as `useProgram` does, and returns true. A link
377
+ * that the driver refused links once more, from new shaders: a driver can run short of memory
378
+ * while it links. A second refusal marks the program, so its draws draw nothing from then on,
379
+ * reports it, and returns false. Any other failure, such as a material with more textures than
380
+ * the stages hold, still stops the replay, and so does a link on a lost context, which the
381
+ * renderer recovers from as a loss.
382
+ */
383
+ private useObjectsProgram;
323
384
  /** Puts a program in use, first checking its link and binding its slots at its first use. */
324
385
  private useProgram;
325
386
  /**