@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.
- package/README.md +109 -0
- package/THIRD-PARTY-NOTICES.txt +0 -1
- package/dist/wasm/single/null3d.js +19 -6
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +19 -6
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +23 -67
- package/docs/api/assets.md +42 -26
- package/docs/api/cameras.md +8 -6
- package/docs/api/controls.md +46 -44
- package/docs/api/debug.md +13 -8
- package/docs/api/engine.md +17 -11
- package/docs/api/feature-draws.md +3 -3
- package/docs/api/feature-effects.md +3 -3
- package/docs/api/feature-instances.md +2 -2
- package/docs/api/features.md +14 -15
- package/docs/api/geometry.md +56 -75
- package/docs/api/grass.md +1 -1
- package/docs/api/impostors.md +120 -9
- package/docs/api/input.md +4 -11
- package/docs/api/lights.md +14 -38
- package/docs/api/lines.md +8 -25
- package/docs/api/materials.md +69 -70
- package/docs/api/math.md +6 -7
- package/docs/api/objects.md +13 -13
- package/docs/api/particles.md +2 -14
- package/docs/api/points.md +3 -25
- package/docs/api/post.md +22 -23
- package/docs/api/quality.md +11 -6
- package/docs/api/raycast.md +13 -32
- package/docs/api/reference/animation.md +9 -9
- package/docs/api/reference/assets.md +18 -18
- package/docs/api/reference/cameras.md +5 -2
- package/docs/api/reference/controls.md +75 -23
- package/docs/api/reference/debug.md +23 -8
- package/docs/api/reference/engine.md +22 -10
- package/docs/api/reference/geometry.md +161 -82
- package/docs/api/reference/grass.md +1 -1
- package/docs/api/reference/impostors.md +92 -1
- package/docs/api/reference/input.md +3 -3
- package/docs/api/reference/lights.md +9 -9
- package/docs/api/reference/lines.md +7 -7
- package/docs/api/reference/materials.md +48 -48
- package/docs/api/reference/math.md +22 -22
- package/docs/api/reference/objects.md +9 -9
- package/docs/api/reference/points.md +4 -4
- package/docs/api/reference/post.md +18 -18
- package/docs/api/reference/quality.md +7 -3
- package/docs/api/reference/raycast.md +6 -6
- package/docs/api/reference/render.md +2 -2
- package/docs/api/reference/scene.md +29 -26
- package/docs/api/reference/sketch.md +4 -0
- package/docs/api/reference/sound.md +203 -0
- package/docs/api/reference/sprites.md +5 -5
- package/docs/api/reference/terrain.md +2 -1
- package/docs/api/reference/textures.md +4 -4
- package/docs/api/reference/ui.md +3 -3
- package/docs/api/reference/vertex-draws.md +3 -3
- package/docs/api/reference/water.md +77 -6
- package/docs/api/reference/wind.md +2 -2
- package/docs/api/render.md +12 -10
- package/docs/api/scene.md +40 -29
- package/docs/api/sketch.md +64 -3
- package/docs/api/sound.md +169 -0
- package/docs/api/splats.md +7 -0
- package/docs/api/sprites.md +4 -20
- package/docs/api/tasks.md +2 -2
- package/docs/api/terrain.md +2 -14
- package/docs/api/textures.md +9 -9
- package/docs/api/ui.md +3 -15
- package/docs/api/water.md +198 -15
- package/docs/api/wind.md +5 -5
- package/docs/cli/null3d.md +93 -18
- package/docs/concepts/architecture.md +10 -10
- package/docs/concepts/assets.md +2 -19
- package/docs/concepts/backends.md +7 -5
- package/docs/concepts/color-management.md +15 -26
- package/docs/concepts/culling.md +1 -1
- package/docs/concepts/instances.md +5 -5
- package/docs/concepts/large-worlds.md +1 -1
- package/docs/concepts/lighting.md +50 -55
- package/docs/concepts/lod.md +2 -15
- package/docs/concepts/materials.md +16 -16
- package/docs/concepts/post-processing.md +7 -29
- package/docs/concepts/quality-preset-tables.md +53 -50
- package/docs/concepts/quality-presets.md +56 -27
- package/docs/concepts/render-graph.md +19 -14
- package/docs/concepts/render-layers.md +3 -17
- package/docs/concepts/shadows.md +10 -28
- package/docs/concepts/static-dynamic.md +2 -2
- package/docs/cookbook/index.md +1 -1
- package/docs/data/threejs-mapping.json +136 -102
- package/docs/errors/E1214.md +3 -3
- package/docs/errors/E1307.md +23 -0
- package/docs/errors/E1420.md +3 -3
- package/docs/errors/index.md +3 -2
- package/docs/getting-started/cdn.md +17 -1
- package/docs/getting-started/first-scene.md +1 -1
- package/docs/getting-started/hosting.md +50 -9
- package/docs/getting-started/install.md +8 -7
- package/docs/getting-started/network-use.md +10 -2
- package/docs/getting-started/project-structure.md +15 -6
- package/docs/getting-started/third-party-notices.md +8 -6
- package/docs/guides/accessibility.md +1 -1
- package/docs/guides/add-ons.md +3 -2
- package/docs/guides/agents.md +16 -5
- package/docs/guides/assets-pipeline.md +13 -12
- package/docs/guides/audio.md +109 -124
- package/docs/guides/car-paint.md +1 -1
- package/docs/guides/content-pages.md +10 -6
- package/docs/guides/custom-passes.md +9 -8
- package/docs/guides/custom-shaders.md +6 -3
- package/docs/guides/debugging.md +78 -4
- package/docs/guides/deploying.md +105 -5
- package/docs/guides/deterministic-simulation.md +1 -1
- package/docs/guides/first-use-shaders.md +4 -4
- package/docs/guides/loading-screens.md +78 -33
- package/docs/guides/multiple-views.md +41 -2
- package/docs/guides/performance.md +6 -3
- package/docs/guides/phones.md +12 -1
- package/docs/guides/physics.md +1 -1
- package/docs/guides/screens.md +7 -5
- package/docs/guides/start-time.md +328 -0
- package/docs/guides/testing.md +23 -5
- package/docs/guides/ui-overlays.md +3 -3
- package/docs/index.md +12 -8
- package/docs/pages.md +26 -23
- package/docs/porting/react-three-fiber.md +228 -5
- package/docs/porting/threejs-loop-and-threads.md +220 -6
- package/docs/porting/threejs-mapping.md +86 -84
- package/docs/porting/threejs-materials.md +212 -5
- package/docs/porting/threejs-overview.md +218 -5
- package/docs/porting/threejs-postprocessing.md +2 -2
- package/docs/porting/threejs-shaders.md +298 -5
- package/docs/porting/threejs-unsupported.md +82 -6
- package/docs/porting/verification.md +181 -5
- package/docs/shaders/builtins.md +1 -1
- package/docs/shaders/library.md +63 -39
- package/docs/shaders/surface-functions.md +11 -10
- package/docs/shaders/wgsl-rules.md +1 -1
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +9 -7
- package/lib/debug/draw.d.ts +9 -0
- package/lib/debug/draw.js +49 -2
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/stats-panel.d.ts +1 -1
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.js +8 -2
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +3 -2
- package/lib/generated/core.d.ts +1 -1
- package/lib/generated/core.js +1 -1
- package/lib/gpu/early-builds.d.ts +68 -0
- package/lib/gpu/early-builds.js +158 -0
- package/lib/gpu/pipeline-name.d.ts +6 -0
- package/lib/gpu/pipeline-name.js +23 -0
- package/lib/gpu/webgl2/backend.d.ts +63 -2
- package/lib/gpu/webgl2/backend.js +226 -8
- package/lib/gpu/webgl2/programs.d.ts +18 -0
- package/lib/gpu/webgl2/programs.js +4 -1
- package/lib/gpu/webgpu/backend.d.ts +89 -2
- package/lib/gpu/webgpu/backend.js +255 -8
- package/lib/gpu/webgpu/pipelines.d.ts +13 -0
- package/lib/gpu/webgpu/pipelines.js +15 -1
- package/lib/index.d.ts +6 -4
- package/lib/index.js +3 -2
- package/lib/math/color.d.ts +5 -5
- package/lib/math/color.js +5 -5
- package/lib/math/mat4.d.ts +6 -12
- package/lib/math/mat4.js +6 -12
- package/lib/math/namespaces/quat.d.ts +3 -3
- package/lib/math/namespaces/quat.js +3 -3
- package/lib/math/quat.d.ts +8 -12
- package/lib/math/quat.js +8 -12
- package/lib/math/random.d.ts +2 -3
- package/lib/math/random.js +2 -3
- package/lib/math/types.d.ts +4 -4
- package/lib/math/vec3.d.ts +3 -6
- package/lib/math/vec3.js +3 -6
- package/lib/page/capabilities.d.ts +7 -7
- package/lib/page/capabilities.js +39 -25
- package/lib/page/check-store.d.ts +14 -2
- package/lib/page/check-store.js +34 -11
- package/lib/page/engine.d.ts +103 -26
- package/lib/page/engine.js +420 -97
- package/lib/page/first-frame.d.ts +16 -0
- package/lib/page/first-frame.js +35 -0
- package/lib/page/frame-stats.d.ts +34 -1
- package/lib/page/frame-stats.js +15 -0
- package/lib/page/label-loop.d.ts +7 -3
- package/lib/page/label-loop.js +17 -10
- package/lib/page/labels.d.ts +3 -3
- package/lib/page/pipeline-store.d.ts +25 -0
- package/lib/page/pipeline-store.js +84 -0
- package/lib/page/start-marker.d.ts +4 -1
- package/lib/page/start-marker.js +5 -2
- package/lib/page/switches.d.ts +32 -2
- package/lib/page/switches.js +9 -1
- package/lib/quality/check.d.ts +24 -3
- package/lib/quality/check.js +21 -7
- package/lib/quality/chooser.d.ts +6 -0
- package/lib/quality/chooser.js +8 -0
- package/lib/quality/governor.d.ts +98 -6
- package/lib/quality/governor.js +250 -20
- package/lib/quality/preset-docs.d.ts +16 -1
- package/lib/quality/preset-docs.js +3 -0
- package/lib/quality/presets.d.ts +84 -7
- package/lib/quality/presets.js +94 -2
- package/lib/render/draw.d.ts +3 -2
- package/lib/render/draw.js +15 -5
- package/lib/render/load-draw.d.ts +7 -5
- package/lib/render/load-draw.js +7 -5
- package/lib/render/loss.d.ts +28 -10
- package/lib/render/loss.js +50 -22
- package/lib/render/recovery.d.ts +20 -0
- package/lib/render/recovery.js +44 -4
- package/lib/render/renderer.d.ts +85 -9
- package/lib/render/renderer.js +181 -42
- package/lib/render/scene-renderer.d.ts +19 -1
- package/lib/render/scene-renderer.js +25 -1
- package/lib/render/webgl2-renderers.js +8 -5
- package/lib/render/webgpu-renderers.js +5 -4
- package/lib/scene/animation.d.ts +28 -32
- package/lib/scene/animation.js +12 -15
- package/lib/scene/assets.d.ts +61 -86
- package/lib/scene/assets.js +103 -236
- package/lib/scene/background.d.ts +14 -18
- package/lib/scene/background.js +5 -2
- package/lib/scene/color.d.ts +3 -3
- package/lib/scene/downloads.d.ts +2 -0
- package/lib/scene/downloads.js +371 -0
- package/lib/scene/environment.d.ts +7 -7
- package/lib/scene/environment.js +1 -1
- package/lib/scene/fake-call-values.js +1 -1
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +19 -0
- package/lib/scene/frame-cameras.js +58 -0
- package/lib/scene/gltf.d.ts +32 -2
- package/lib/scene/gltf.js +78 -49
- package/lib/scene/grading.d.ts +2 -2
- package/lib/scene/grading.js +3 -3
- package/lib/scene/ktx2.d.ts +9 -1
- package/lib/scene/ktx2.js +3 -2
- package/lib/scene/level-rule.d.ts +120 -0
- package/lib/scene/level-rule.js +130 -0
- package/lib/scene/lines.d.ts +13 -17
- package/lib/scene/lines.js +3 -3
- package/lib/scene/lut.d.ts +1 -2
- package/lib/scene/lut.js +1 -2
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +38 -43
- package/lib/scene/post.js +4 -1
- package/lib/scene/prefab.d.ts +7 -8
- package/lib/scene/prefab.js +7 -8
- package/lib/scene/property-animation.d.ts +1 -1
- package/lib/scene/property-animation.js +1 -1
- package/lib/scene/queries.d.ts +7 -13
- package/lib/scene/resources.d.ts +225 -254
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +149 -118
- package/lib/scene/scene.js +196 -98
- package/lib/scene/serial-loads.d.ts +29 -0
- package/lib/scene/serial-loads.js +68 -0
- package/lib/scene/shader-preloads.d.ts +34 -0
- package/lib/scene/shader-preloads.js +38 -0
- package/lib/scene/sprites.d.ts +14 -17
- package/lib/scene/sprites.js +5 -6
- package/lib/scene/textures.d.ts +11 -12
- package/lib/scene/textures.js +9 -10
- package/lib/scene/time-of-day.d.ts +3 -4
- package/lib/scene/time-of-day.js +2 -3
- package/lib/scene/vertex-draws.d.ts +5 -4
- package/lib/scene/vertex-draws.js +7 -5
- package/lib/shader-artifact.json +1 -0
- package/lib/shared/core.d.ts +5 -0
- package/lib/shared/core.js +1 -0
- package/lib/shared/import-once.d.ts +6 -0
- package/lib/shared/import-once.js +19 -0
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/task-pending.d.ts +12 -0
- package/lib/shared/task-pending.js +61 -1
- package/lib/shared/tasks.js +79 -32
- package/lib/shared/version.d.ts +17 -1
- package/lib/shared/version.js +19 -1
- package/lib/shared/wasm.d.ts +12 -4
- package/lib/shared/wasm.js +50 -27
- package/lib/shared/worker-start.d.ts +7 -0
- package/lib/shared/worker-start.js +27 -0
- package/lib/sketch/define-sketch.d.ts +35 -0
- package/lib/sketch/input.d.ts +2 -2
- package/lib/sketch/preset-check.d.ts +20 -6
- package/lib/sketch/preset-check.js +42 -17
- package/lib/sketch/quality.d.ts +69 -11
- package/lib/sketch/quality.js +54 -13
- package/lib/sketch/runner.d.ts +76 -9
- package/lib/sketch/runner.js +385 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +61 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +25 -4
- package/lib/workers/sketch-worker.js +104 -15
- package/package.json +2 -2
package/lib/generated/core.js
CHANGED
|
@@ -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 =
|
|
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
|
-
/**
|
|
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
|
/**
|