@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/sketch/runner.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
// the engine chose the preset itself, the setup ends with the preset check (preset-check.ts), which
|
|
18
18
|
// loads after the first frame. The first frame after a change of preset, and the first frame whose
|
|
19
19
|
// handlers hear of it, wait for their pipelines on the thread that draws.
|
|
20
|
+
import { DebugChannel } from '../debug/channel.js';
|
|
20
21
|
import { DebugDraw } from '../debug/draw.js';
|
|
21
22
|
import { SketchDebug } from '../debug/sketch-debug.js';
|
|
22
23
|
import { DEV } from '../errors/checks.js';
|
|
@@ -28,7 +29,7 @@ import { FORMAT_CANVAS, PERMUTATION_DRAW_INDEX, PERMUTATION_TONE_MAP } from '../
|
|
|
28
29
|
import { cellTableWarning } from '../page/limits.js';
|
|
29
30
|
import { FULL_SCALE, thousandths } from '../quality/budget.js';
|
|
30
31
|
import { Governor, GovernorLoop } from '../quality/governor.js';
|
|
31
|
-
import { SKETCH_SETTINGS } from '../quality/presets.js';
|
|
32
|
+
import { lowestTierCuts, presetSettings, presetValue, SKETCH_SETTINGS, tierRestoreSettings, } from '../quality/presets.js';
|
|
32
33
|
import { FrameCameras } from '../scene/frame-cameras.js';
|
|
33
34
|
import { GltfExtensions } from '../scene/gltf-extensions.js';
|
|
34
35
|
import { GradeTable } from '../scene/grade-table.js';
|
|
@@ -46,8 +47,8 @@ import { stopHelperWorkers } from '../shared/helper-workers.js';
|
|
|
46
47
|
import { imagesArrived, } from '../shared/images.js';
|
|
47
48
|
import { MEMORY_AREA_COUNT } from '../shared/memory-area.js';
|
|
48
49
|
import { MemoryViews } from '../shared/memory-views.js';
|
|
49
|
-
import { Counter, FrameRecorder, MemoryFigure, PHASE_NAMES, Phase, RingFrames, Role, } from '../shared/metrics.js';
|
|
50
|
-
import { plansPending, tasksPending } from '../shared/task-pending.js';
|
|
50
|
+
import { Counter, FrameRecorder, MemoryFigure, PHASE_NAMES, Phase, RingFrames, Role, refreshRate, } from '../shared/metrics.js';
|
|
51
|
+
import { endPlanHold, holdPlans, plansPending, releasePlans, tasksPending, } from '../shared/task-pending.js';
|
|
51
52
|
import { VIDEO_FRAME } from '../shared/videos.js';
|
|
52
53
|
import { slotChange, slotChangeOrRecheck } from '../shared/wake.js';
|
|
53
54
|
import { FixedClock, FrameClock, holdSteps } from './clock.js';
|
|
@@ -92,6 +93,75 @@ const COMMAND_CAPACITY = 1 << 16;
|
|
|
92
93
|
/** The id of the pointer that a timed script drives, and the bit of its main button. */
|
|
93
94
|
const MAIN_POINTER = 1;
|
|
94
95
|
const MAIN_BUTTON = 1;
|
|
96
|
+
/**
|
|
97
|
+
* How many of a sketch's listed files download at once, while no load asks for one. On HTTP/1.1 a
|
|
98
|
+
* browser opens few connections to one server, and a large file holds one until it has arrived, so
|
|
99
|
+
* the engine's own start files, such as the shader files that the setup's first frame asks for,
|
|
100
|
+
* still find free ones. One file at a time would leave the link idle for a round trip between files.
|
|
101
|
+
*/
|
|
102
|
+
const LISTED_AT_ONCE = 2;
|
|
103
|
+
/**
|
|
104
|
+
* How many of a sketch's listed files download at once while loads wait for them: those loads go
|
|
105
|
+
* ahead of the rest of the list. A setup that asks for many listed files together then still
|
|
106
|
+
* leaves connections for the engine's own files, which its loads need too, such as the model
|
|
107
|
+
* loader's code and the warm-up's shader files.
|
|
108
|
+
*/
|
|
109
|
+
const LISTED_MOST = 4;
|
|
110
|
+
/**
|
|
111
|
+
* Fetches a listed file that no load has asked for yet, at low priority, so the engine's own files
|
|
112
|
+
* go first where the browser orders requests, as it does on HTTP/2.
|
|
113
|
+
*/
|
|
114
|
+
const fetchListed = (address) => fetch(address, { priority: 'low' });
|
|
115
|
+
/**
|
|
116
|
+
* The addresses of a sketch's download list, resolved against the page's address, without repeats.
|
|
117
|
+
* Throws E1214 for a list that is not an array, and for an entry that is not a file's address.
|
|
118
|
+
*/
|
|
119
|
+
function listedAddresses(list, base) {
|
|
120
|
+
if (!Array.isArray(list))
|
|
121
|
+
throw new EngineError('E1214', `defineSketch() got ${String(list)} for downloads, which takes an array of addresses.`);
|
|
122
|
+
const addresses = new Map();
|
|
123
|
+
for (const entry of list) {
|
|
124
|
+
let address;
|
|
125
|
+
if (entry instanceof URL || (typeof entry === 'string' && entry.trim() !== '')) {
|
|
126
|
+
try {
|
|
127
|
+
address = new URL(entry, base);
|
|
128
|
+
}
|
|
129
|
+
catch { }
|
|
130
|
+
}
|
|
131
|
+
if (!address)
|
|
132
|
+
throw new EngineError('E1214', `defineSketch() got ${typeof entry === 'string' ? JSON.stringify(entry) : String(entry)} in downloads, which is not the address of a file.`);
|
|
133
|
+
addresses.set(address.href, address);
|
|
134
|
+
}
|
|
135
|
+
return [...addresses.values()];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @internal Begins the downloads of a live sketch's list, unless `files` holds them already: the
|
|
139
|
+
* first two fetches at once, and the assets loader's code beside them, whose downloads read the
|
|
140
|
+
* bodies as they arrive and start the rest. A list that is not valid begins nothing, and the setup
|
|
141
|
+
* reports it.
|
|
142
|
+
*/
|
|
143
|
+
export function startListedFiles(files, sketch, base) {
|
|
144
|
+
const list = sketch.options.downloads;
|
|
145
|
+
if (files.downloads || list === undefined)
|
|
146
|
+
return;
|
|
147
|
+
let addresses;
|
|
148
|
+
try {
|
|
149
|
+
addresses = listedAddresses(list, base);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (addresses.length === 0)
|
|
155
|
+
return;
|
|
156
|
+
const started = addresses
|
|
157
|
+
.slice(0, LISTED_AT_ONCE)
|
|
158
|
+
.map((address) => awaitLater(fetchListed(address)));
|
|
159
|
+
files.downloads = awaitLater(import('../scene/assets.js').then(({ Downloads }) => {
|
|
160
|
+
const downloads = new Downloads(base);
|
|
161
|
+
downloads.list(addresses, started, LISTED_AT_ONCE, LISTED_MOST, fetchListed);
|
|
162
|
+
return downloads;
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
95
165
|
/** How often a wait for a control slot checks it, where the control block is not shared memory. */
|
|
96
166
|
const SLOT_POLL_MS = 4;
|
|
97
167
|
/** Each meter of automatic exposure, by its code in the core. */
|
|
@@ -103,6 +173,17 @@ const EXPOSURE_METERS = { downsample: 0, histogram: 1 };
|
|
|
103
173
|
const MEMORY_EVERY = 8;
|
|
104
174
|
/** Frames over which the sketch thread averages its parallel work before it asks for job workers. */
|
|
105
175
|
const JOB_WINDOW = 30;
|
|
176
|
+
/**
|
|
177
|
+
* The longest a window waits for its frames, in seconds of the sketch's own time, and the fewest
|
|
178
|
+
* frames it judges: a software GPU draws so few frames a second that a window of frames alone
|
|
179
|
+
* would never end inside a page's run, so the deadline ends the window once it holds the fewest
|
|
180
|
+
* frames. The runner reads no clock for this and allocates nothing per frame: its own step time
|
|
181
|
+
* carries the deadline, and a step is capped at a quarter second, so the deadline takes as few as
|
|
182
|
+
* eight frames. The mean over the frames it has then decides as it does for a full window.
|
|
183
|
+
*/
|
|
184
|
+
const JOB_WINDOW_SECONDS = 2;
|
|
185
|
+
/** The fewest frames a window needs before the deadline may end it. */
|
|
186
|
+
const JOB_WINDOW_MIN_FRAMES = 2;
|
|
106
187
|
/**
|
|
107
188
|
* The mean time per frame that the sketch thread spends in loops it hands out, in microseconds,
|
|
108
189
|
* from which it asks for more job workers: twice as many, and at least 2.
|
|
@@ -119,14 +200,35 @@ const JOB_PAUSE_SECONDS = 4.5;
|
|
|
119
200
|
* The assets API, whose loader loads with the first call that reads a file: a sketch that loads no
|
|
120
201
|
* file downloads none of it. Every call waits for the loader first. The two calls that answer with
|
|
121
202
|
* a function of their own answer at once: the extension handlers live beside the runner, so a
|
|
122
|
-
* registration keeps its errors, and the progress handlers join the loader once it arrives.
|
|
203
|
+
* registration keeps its errors, and the progress handlers join the loader once it arrives. The
|
|
204
|
+
* loader takes the downloads of the sketch's list when `listed` gives them, and a development build
|
|
205
|
+
* watches the sketch's loads while `watching` says so.
|
|
206
|
+
*
|
|
207
|
+
* With `inOrder`, as while the engine holds its frames, the calls run one at a time in the order
|
|
208
|
+
* the sketch made them: each starts once the call before it has answered. A load makes its
|
|
209
|
+
* textures, meshes and materials when its files arrive, and files arrive in an order that changes
|
|
210
|
+
* from run to run, so loads that ran together would make the scene's content in another order on
|
|
211
|
+
* each run, and the held frame would draw its objects in another order and with other ids.
|
|
123
212
|
*/
|
|
124
|
-
function lazyAssets(textures, base, makers) {
|
|
213
|
+
function lazyAssets(textures, base, makers, listed, watching, inOrder) {
|
|
125
214
|
const extensions = new GltfExtensions();
|
|
126
|
-
// The loader's file starts downloading at the first call that reads a file,
|
|
127
|
-
// a page that loads nothing must download none of it.
|
|
215
|
+
// The loader's file starts downloading at the first call that reads a file, or with the
|
|
216
|
+
// sketch's list, never at the start: a page that loads nothing must download none of it.
|
|
128
217
|
let ready;
|
|
129
|
-
|
|
218
|
+
/** The answer of the call made last, which the next call waits for when the calls run in order. */
|
|
219
|
+
let answered = Promise.resolve();
|
|
220
|
+
const load = () => (ready ??= awaitLater(import('../scene/assets.js').then(({ Assets, Downloads }) => {
|
|
221
|
+
const make = (downloads) => {
|
|
222
|
+
if (DEV)
|
|
223
|
+
downloads.watch(watching);
|
|
224
|
+
return new Assets(textures, base, makers, extensions, downloads);
|
|
225
|
+
};
|
|
226
|
+
// Without a list the loader is ready within the import's own promise steps, so its
|
|
227
|
+
// calls keep their place among the setup's other promises, as hold mode, a replay
|
|
228
|
+
// and a recording need.
|
|
229
|
+
const early = listed();
|
|
230
|
+
return early ? early.then(make) : make(new Downloads(base));
|
|
231
|
+
})));
|
|
130
232
|
return new Proxy({}, {
|
|
131
233
|
get(_target, name) {
|
|
132
234
|
// The proxy must not look like a promise to the code that awaits a call's result.
|
|
@@ -145,7 +247,14 @@ function lazyAssets(textures, base, makers) {
|
|
|
145
247
|
return () => off?.();
|
|
146
248
|
};
|
|
147
249
|
}
|
|
148
|
-
return (...args) =>
|
|
250
|
+
return (...args) => {
|
|
251
|
+
const call = () => load().then((assets) => assets[name](...args));
|
|
252
|
+
if (!inOrder)
|
|
253
|
+
return call();
|
|
254
|
+
const answer = answered.then(call, call);
|
|
255
|
+
answered = answer;
|
|
256
|
+
return answer;
|
|
257
|
+
};
|
|
149
258
|
},
|
|
150
259
|
});
|
|
151
260
|
}
|
|
@@ -234,6 +343,15 @@ export class SketchRunner {
|
|
|
234
343
|
callbacks = {};
|
|
235
344
|
/** True once the setup function has returned. */
|
|
236
345
|
setUp = false;
|
|
346
|
+
/** The downloads of the sketch's list, once a live setup began or took them. */
|
|
347
|
+
listed;
|
|
348
|
+
/** Resolves the sketch's `engine.firstFrame`, until it has. */
|
|
349
|
+
firstFrameReached;
|
|
350
|
+
/**
|
|
351
|
+
* True while a development build watches the sketch's loads for one that waits for another:
|
|
352
|
+
* during the setup function of a live start.
|
|
353
|
+
*/
|
|
354
|
+
watchesLoads = false;
|
|
237
355
|
/** The frames that warm-ups during the setup published, one after another, as the last one's number. */
|
|
238
356
|
setupFrames = Promise.resolve(0);
|
|
239
357
|
clock = new FrameClock();
|
|
@@ -276,6 +394,8 @@ export class SketchRunner {
|
|
|
276
394
|
*/
|
|
277
395
|
jobWindowUs = 0;
|
|
278
396
|
jobWindowFrames = 0;
|
|
397
|
+
/** The sketch time at which the window's first frame arrived, in seconds. */
|
|
398
|
+
jobWindowStart = 0;
|
|
279
399
|
/** The sketch time at which the sketch thread times its parallel loops again, while they pause. */
|
|
280
400
|
jobPauseUntil = -1;
|
|
281
401
|
/** Whether the core times the parallel loops that the sketch thread hands out. */
|
|
@@ -312,6 +432,10 @@ export class SketchRunner {
|
|
|
312
432
|
frameTimes;
|
|
313
433
|
/** The governor's count of changes when the core last took the settings that its steps move. */
|
|
314
434
|
stepChanges = 0;
|
|
435
|
+
/** The governor's count of tier changes when the sketch last took the tier's settings. */
|
|
436
|
+
tierChanges = 0;
|
|
437
|
+
/** The settings that the tier replaced, to give back when it leaves, or undefined outside it. */
|
|
438
|
+
tierRestore;
|
|
315
439
|
/** The budgets' count of changes when the governor last took the steps that they allow. */
|
|
316
440
|
budgetChanges = 0;
|
|
317
441
|
/** The sketch's post-processing settings, which say whether bloom is on. */
|
|
@@ -360,6 +484,11 @@ export class SketchRunner {
|
|
|
360
484
|
heldScale = FULL_SCALE;
|
|
361
485
|
/** The sketch's debug drawing, in development builds only, which is also its `ctx.debug`. */
|
|
362
486
|
debugDraw;
|
|
487
|
+
/**
|
|
488
|
+
* The development build's inspection channel, which the in-page inspector and the MCP server
|
|
489
|
+
* call. A release build holds none of it.
|
|
490
|
+
*/
|
|
491
|
+
channel;
|
|
363
492
|
/** The sketch's labels, which each frame projects. */
|
|
364
493
|
ui;
|
|
365
494
|
/** True once the sketch thread has warned that the grid cells ran out. */
|
|
@@ -381,6 +510,17 @@ export class SketchRunner {
|
|
|
381
510
|
* time, or a replay, which steps through a recording.
|
|
382
511
|
*/
|
|
383
512
|
holdsFrames;
|
|
513
|
+
/**
|
|
514
|
+
* True while the preset check measures the frames of play. The governor waits until it ends, so
|
|
515
|
+
* the check measures each preset at the full render scale.
|
|
516
|
+
*/
|
|
517
|
+
checking = false;
|
|
518
|
+
/**
|
|
519
|
+
* The refresh rate that the thread that draws measured when the sketch's setup returned, before
|
|
520
|
+
* the frames of play loaded the GPU, or 0 before it measured one. The preset check's target and
|
|
521
|
+
* the governor's start from it.
|
|
522
|
+
*/
|
|
523
|
+
setupRefreshHz = 0;
|
|
384
524
|
context;
|
|
385
525
|
/**
|
|
386
526
|
* Starts the engine on the core's thread. `holdSeconds` starts hold mode at that sketch time: it
|
|
@@ -447,6 +587,9 @@ export class SketchRunner {
|
|
|
447
587
|
// A device that draws on the CPU keeps the whole render scale once a step below it failed:
|
|
448
588
|
// its two-step upscale costs about what the smaller scene saves (D-237).
|
|
449
589
|
this.governor.setSoftware(device.softwareRenderer);
|
|
590
|
+
// The page's `?tier=off` switch keeps the tier out, which a test that measures the presets
|
|
591
|
+
// asks for.
|
|
592
|
+
this.governor.setLowestTier(sketch.quality.lowestAllowed !== false);
|
|
450
593
|
this.governorLoop =
|
|
451
594
|
holdSeconds === undefined
|
|
452
595
|
? new GovernorLoop(this.governor, metrics, {
|
|
@@ -458,12 +601,21 @@ export class SketchRunner {
|
|
|
458
601
|
// Alpha to coverage fades a mask's edges only on targets with MSAA.
|
|
459
602
|
this.preloads = new ShaderPreloads(sketch.sendPreload);
|
|
460
603
|
this.preloads.setUsable('coverage', device.antialias === ANTIALIAS_MSAA);
|
|
604
|
+
this.preloads.setPassFacts({
|
|
605
|
+
tier: sketch.capabilities.tier,
|
|
606
|
+
device,
|
|
607
|
+
settings: () => this.quality.settings,
|
|
608
|
+
});
|
|
461
609
|
const { governor } = this;
|
|
462
610
|
const bloomSize = () => this.bloomSetting / 2 ** governor.bloomHalvings;
|
|
463
611
|
this.quality = new SketchQuality(sketch.quality, (update, changed) => {
|
|
464
612
|
this.applyFrameSettings(update.settings);
|
|
465
613
|
textures.applyQuality(update.settings, changed);
|
|
466
614
|
sketch.applyQuality(update);
|
|
615
|
+
// A preset or the sketch gives the settings their own values again, and the tier
|
|
616
|
+
// keeps its cuts.
|
|
617
|
+
if (this.governor.lowest)
|
|
618
|
+
this.applyTierSettings();
|
|
467
619
|
}, () => this.settle(true), () => this.renderScale() / FULL_SCALE, {
|
|
468
620
|
get steps() {
|
|
469
621
|
return governor.steps;
|
|
@@ -489,8 +641,20 @@ export class SketchRunner {
|
|
|
489
641
|
get farAnimationInterval() {
|
|
490
642
|
return governor.animationInterval;
|
|
491
643
|
},
|
|
644
|
+
get lowest() {
|
|
645
|
+
return governor.lowest;
|
|
646
|
+
},
|
|
492
647
|
}, textures.memory);
|
|
493
648
|
this.textures = textures;
|
|
649
|
+
if (sketch.quality.lowest === true) {
|
|
650
|
+
// The page started in the tier, so the settings carry its values already. Remember the
|
|
651
|
+
// preset's, which the governor gives back when the frames have room for its window.
|
|
652
|
+
const { preset } = sketch.quality;
|
|
653
|
+
const path = sketch.capabilities.tier;
|
|
654
|
+
this.governor.startLowest(thousandths(presetValue('minRenderScale', preset, path)), thousandths(presetValue('maxRenderScale', preset, path)));
|
|
655
|
+
this.tierRestore = tierRestoreSettings(presetSettings(preset, {}, path));
|
|
656
|
+
this.tierChanges = this.governor.tierChanges;
|
|
657
|
+
}
|
|
494
658
|
this.applyFrameSettings(this.quality.settings);
|
|
495
659
|
this.readViewport();
|
|
496
660
|
const host = {
|
|
@@ -527,6 +691,24 @@ export class SketchRunner {
|
|
|
527
691
|
if (debugView !== undefined)
|
|
528
692
|
this.debugDraw?.requestView(debugView);
|
|
529
693
|
const debug = this.debugDraw ?? new SketchDebug(host);
|
|
694
|
+
if (DEV) {
|
|
695
|
+
// The channel reads the scene, the render passes and the quality settings that the
|
|
696
|
+
// inspector changes, and outlines the object that it selects.
|
|
697
|
+
const channel = new DebugChannel({
|
|
698
|
+
scene,
|
|
699
|
+
render: this.render,
|
|
700
|
+
quality: this.quality,
|
|
701
|
+
debug,
|
|
702
|
+
debugDraw: this.debugDraw,
|
|
703
|
+
info: () => ({
|
|
704
|
+
tier: sketch.capabilities.tier,
|
|
705
|
+
preset: this.quality.preset,
|
|
706
|
+
renderScale: this.renderScale() / FULL_SCALE,
|
|
707
|
+
}),
|
|
708
|
+
});
|
|
709
|
+
this.channel = channel;
|
|
710
|
+
this.inspect = (call, args) => channel.inspect(call, args);
|
|
711
|
+
}
|
|
530
712
|
const holdsFrames = this.holdsFrames;
|
|
531
713
|
this.context = {
|
|
532
714
|
time: this.time,
|
|
@@ -534,12 +716,15 @@ export class SketchRunner {
|
|
|
534
716
|
viewport: this.viewport,
|
|
535
717
|
capabilities: sketch.capabilities,
|
|
536
718
|
held: this.holdsFrames,
|
|
719
|
+
firstFrame: new Promise((resolve) => {
|
|
720
|
+
this.firstFrameReached = resolve;
|
|
721
|
+
}),
|
|
537
722
|
},
|
|
538
723
|
scene,
|
|
539
724
|
materials,
|
|
540
725
|
geometry,
|
|
541
726
|
textures,
|
|
542
|
-
assets: lazyAssets(textures, sketch.pageUrl, { core: this.core, geometry, materials, scene }),
|
|
727
|
+
assets: lazyAssets(textures, sketch.pageUrl, { core: this.core, geometry, materials, scene }, () => this.listed, () => this.watchesLoads, this.holdsFrames),
|
|
543
728
|
input: this.input,
|
|
544
729
|
post: this.post,
|
|
545
730
|
render: this.render,
|
|
@@ -582,23 +767,54 @@ export class SketchRunner {
|
|
|
582
767
|
: (replay?.seed ?? (record ? RECORDING_SEED : undefined));
|
|
583
768
|
if (seed !== undefined)
|
|
584
769
|
this.restoreRandom = seedMathRandom(seed);
|
|
770
|
+
// The level plans that the setup starts hand over their levels when the hold begins, in the
|
|
771
|
+
// order they started, so the scene's meshes sit in engine memory in one order on every run.
|
|
772
|
+
// Last too, so a constructor that fails leaves the plans handing over as they answer.
|
|
773
|
+
if (holdSeconds !== undefined)
|
|
774
|
+
holdPlans();
|
|
585
775
|
}
|
|
586
776
|
/**
|
|
587
777
|
* Runs the sketch's setup function, which returns the sketch's callbacks. When the page asks for
|
|
588
|
-
*
|
|
589
|
-
*
|
|
778
|
+
* the preset check before play, the check follows, and the setup resolves after it. When it asks
|
|
779
|
+
* for the check during play, the check starts as the setup resolves, and measures the frames
|
|
780
|
+
* that the frame loop draws from then on. In hold mode, it then steps the sketch to the held time
|
|
781
|
+
* (see `hold`). Options out of range fail with E1214 before the setup function runs. A live
|
|
782
|
+
* start's listed files are downloading by then; hold mode, a replay and a recording leave each
|
|
783
|
+
* file to its load, so their order stays as without the list.
|
|
590
784
|
*/
|
|
591
785
|
async setup(sketch) {
|
|
786
|
+
const { options } = sketch;
|
|
592
787
|
try {
|
|
593
|
-
this.fixed = new FixedClock(
|
|
788
|
+
this.fixed = new FixedClock(options.fixedRate, options.maxFixedSteps);
|
|
789
|
+
// A sketch whose own thread limits its frames keeps the governor out of the lowest tier:
|
|
790
|
+
// its smaller render cannot speed the sketch work, so the cut only loses the picture.
|
|
791
|
+
if (options.lowestTier === false)
|
|
792
|
+
this.governor.setLowestTier(false);
|
|
793
|
+
const live = !this.holdsFrames && !this.records;
|
|
794
|
+
if (options.downloads !== undefined) {
|
|
795
|
+
const { pageUrl, listed = {} } = this.sketch;
|
|
796
|
+
listedAddresses(options.downloads, pageUrl);
|
|
797
|
+
if (live) {
|
|
798
|
+
startListedFiles(listed, sketch, pageUrl);
|
|
799
|
+
this.listed = listed.downloads;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
594
802
|
// The setup grows the scene, and a page that stalls here reports the time it spent doing it.
|
|
595
803
|
this.record.markSetupStart();
|
|
596
804
|
const growing = performance.now();
|
|
805
|
+
// The development warning watches the setup function's own loads. A setup that fails ends
|
|
806
|
+
// the start, so the watch needs no end of its own then.
|
|
807
|
+
if (DEV)
|
|
808
|
+
this.watchesLoads = live && options.serialLoadWarning !== false;
|
|
597
809
|
this.callbacks = (await sketch.setup(this.context)) ?? {};
|
|
810
|
+
if (DEV)
|
|
811
|
+
this.watchesLoads = false;
|
|
598
812
|
this.record.markSetupDone(performance.now() - growing);
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
813
|
+
this.setupRefreshHz = refreshRate(this.metrics);
|
|
814
|
+
this.governorLoop?.startTarget(this.setupRefreshHz);
|
|
815
|
+
const check = this.holdsFrames ? undefined : this.sketch.quality.check;
|
|
816
|
+
if (check === 'before-play')
|
|
817
|
+
await this.checkPreset(() => this.drawSetupFrame());
|
|
602
818
|
// Warm-ups that the setup started without waiting for them publish their frames first, so
|
|
603
819
|
// the frame loop never records while a setup frame does.
|
|
604
820
|
await this.setupFrames;
|
|
@@ -610,10 +826,16 @@ export class SketchRunner {
|
|
|
610
826
|
this.input.recorder = this.recorder;
|
|
611
827
|
}
|
|
612
828
|
this.setUp = true;
|
|
829
|
+
if (check === 'during-play')
|
|
830
|
+
void this.checkDuringPlay();
|
|
613
831
|
if (this.holdSeconds !== undefined)
|
|
614
832
|
await this.hold(this.holdSeconds);
|
|
615
833
|
else if (this.replayProgram !== undefined)
|
|
616
834
|
await this.replay(this.replayProgram);
|
|
835
|
+
// Hold mode and a replay record no frame after their last, so the sketch's `firstFrame`
|
|
836
|
+
// work can no longer change the frames that they show.
|
|
837
|
+
if (this.holdsFrames)
|
|
838
|
+
this.reachFirstFrame();
|
|
617
839
|
}
|
|
618
840
|
catch (error) {
|
|
619
841
|
// A setup that fails, at any step, leaves no runner to dispose, so the runner stops hearing
|
|
@@ -623,45 +845,92 @@ export class SketchRunner {
|
|
|
623
845
|
throw error;
|
|
624
846
|
}
|
|
625
847
|
}
|
|
848
|
+
/**
|
|
849
|
+
* The preset check during play: the frame loop draws the scene and runs the sketch, and the
|
|
850
|
+
* check measures its frames. The governor waits until the check ends. A preset that the sketch
|
|
851
|
+
* asks for itself ends the check, which then reports no result: the sketch chose its preset.
|
|
852
|
+
*/
|
|
853
|
+
async checkDuringPlay() {
|
|
854
|
+
const { slots } = this.sketch.control;
|
|
855
|
+
const { quality } = this;
|
|
856
|
+
const requests = quality.presetRequests;
|
|
857
|
+
this.checking = true;
|
|
858
|
+
try {
|
|
859
|
+
await this.checkPreset(async () => {
|
|
860
|
+
if (Atomics.load(slots, Slot.Running) === 0)
|
|
861
|
+
return false;
|
|
862
|
+
await reached(slots, Slot.FramesTaken, nextFrame(Atomics.load(slots, Slot.FramesTaken)));
|
|
863
|
+
return Atomics.load(slots, Slot.Running) !== 0 && quality.presetRequests === requests;
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
finally {
|
|
867
|
+
this.checking = false;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
626
870
|
/**
|
|
627
871
|
* The preset check, after the setup: the first frame draws with every pipeline built, then the
|
|
628
|
-
* check measures the scene
|
|
629
|
-
*
|
|
630
|
-
*
|
|
872
|
+
* check measures the scene, and lowers the preset where the device cannot hold its frame rate.
|
|
873
|
+
* `drawFrame` resolves once the thread that draws has taken one more frame: a frame that it
|
|
874
|
+
* publishes of the scene as the setup built it, before play, or the frame loop's next frame,
|
|
875
|
+
* during play. It resolves with false when the check must stop. The check's code loads after the
|
|
876
|
+
* first frame, while the scene keeps drawing. A check that cannot load leaves the preset as it
|
|
877
|
+
* is. It goes on from the rounds that an earlier start measured before its check ended, when the
|
|
878
|
+
* page gives them. While the engine runs, the page hears of each lowering with the rounds so
|
|
879
|
+
* far, and that the check ended, with its result when it measured one.
|
|
631
880
|
*/
|
|
632
|
-
async checkPreset() {
|
|
633
|
-
|
|
881
|
+
async checkPreset(drawFrame) {
|
|
882
|
+
let check;
|
|
883
|
+
try {
|
|
884
|
+
check = await this.measurePreset(drawFrame);
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
console.warn(`null3D could not check the quality preset: ${messageOf(error)}`);
|
|
888
|
+
}
|
|
889
|
+
if (this.core.stopped || Atomics.load(this.sketch.control.slots, Slot.Running) === 0)
|
|
634
890
|
return;
|
|
891
|
+
try {
|
|
892
|
+
this.quality.report(check);
|
|
893
|
+
}
|
|
894
|
+
catch (error) {
|
|
895
|
+
console.warn(`null3D could not report the quality preset check: ${messageOf(error)}`);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Runs the preset check with `drawFrame`, as `checkPreset` says, once the thread that draws has
|
|
900
|
+
* built the pipelines that the scene needs; undefined when it stopped.
|
|
901
|
+
*/
|
|
902
|
+
async measurePreset(drawFrame) {
|
|
903
|
+
await this.warmUp();
|
|
904
|
+
if (!(await drawFrame()))
|
|
905
|
+
return undefined;
|
|
635
906
|
const loading = import('./preset-check.js');
|
|
636
907
|
let loaded = false;
|
|
637
908
|
const settled = () => {
|
|
638
909
|
loaded = true;
|
|
639
910
|
};
|
|
640
911
|
loading.then(settled, settled);
|
|
641
|
-
const graceStart = performance.now();
|
|
642
912
|
while (!loaded)
|
|
643
|
-
if (!(await
|
|
644
|
-
return;
|
|
645
|
-
const { glue } = this.sketch;
|
|
913
|
+
if (!(await drawFrame()))
|
|
914
|
+
return undefined;
|
|
915
|
+
const { glue, maxTargetFps } = this.sketch;
|
|
646
916
|
const { quality } = this;
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
917
|
+
const { checkPreset, checkStart } = await loading;
|
|
918
|
+
return checkPreset({
|
|
919
|
+
metrics: this.metrics,
|
|
920
|
+
get preset() {
|
|
921
|
+
return quality.preset;
|
|
922
|
+
},
|
|
923
|
+
lower: (check, to) => quality.lower(check, to),
|
|
924
|
+
drawFrame,
|
|
925
|
+
uploading: () => glue.textureStat(TEXTURE_STAT_WAITING, 0) > 0,
|
|
926
|
+
maxTargetFps,
|
|
927
|
+
resumes: () => Atomics.load(this.sketch.control.slots, Slot.Resumes),
|
|
928
|
+
}, checkStart(quality.preset, this.setupRefreshHz, maxTargetFps, this.sketch.quality.resume));
|
|
929
|
+
}
|
|
930
|
+
/** Resolves the sketch's `engine.firstFrame`, once. */
|
|
931
|
+
reachFirstFrame() {
|
|
932
|
+
this.firstFrameReached?.();
|
|
933
|
+
this.firstFrameReached = undefined;
|
|
665
934
|
}
|
|
666
935
|
/** True once the setup function has returned, so the frame loop may step the sketch. */
|
|
667
936
|
get started() {
|
|
@@ -725,9 +994,14 @@ export class SketchRunner {
|
|
|
725
994
|
/**
|
|
726
995
|
* Ends the sketch when the engine stops: runs its onDestroy, then makes every later call to the
|
|
727
996
|
* engine fail with E1420, so code that outlives the engine never reaches the next engine's core.
|
|
728
|
-
* It also gives the thread its own Math.random back, where hold mode seeded it
|
|
997
|
+
* It also gives the thread its own Math.random back, where hold mode seeded it, and ends hold
|
|
998
|
+
* mode's hold on the level plans, for a setup that failed before its hold.
|
|
729
999
|
*/
|
|
730
1000
|
dispose() {
|
|
1001
|
+
// Before the check below: a runner whose core stopped first still lets go of the channel,
|
|
1002
|
+
// which holds the scene and its memory.
|
|
1003
|
+
this.inspect = undefined;
|
|
1004
|
+
this.channel = undefined;
|
|
731
1005
|
// Before the check below: a runner whose core stopped first still stops hearing add-ons.
|
|
732
1006
|
if (DEV)
|
|
733
1007
|
this.stopAddonNotes?.();
|
|
@@ -745,6 +1019,7 @@ export class SketchRunner {
|
|
|
745
1019
|
stopHelperWorkers();
|
|
746
1020
|
this.restoreRandom?.();
|
|
747
1021
|
this.restoreRandom = undefined;
|
|
1022
|
+
endPlanHold();
|
|
748
1023
|
}
|
|
749
1024
|
/**
|
|
750
1025
|
* Delivers a message the page sent with engine.postToSketch. It arrives between frames. A
|
|
@@ -799,6 +1074,7 @@ export class SketchRunner {
|
|
|
799
1074
|
this.updateFailed = true;
|
|
800
1075
|
if (!this.reported.has(message)) {
|
|
801
1076
|
this.reported.add(message);
|
|
1077
|
+
this.channel?.recordError(message);
|
|
802
1078
|
console.error(error);
|
|
803
1079
|
this.sketch.reportSketchError?.(message);
|
|
804
1080
|
}
|
|
@@ -830,8 +1106,9 @@ export class SketchRunner {
|
|
|
830
1106
|
/**
|
|
831
1107
|
* Adds a frame's parallel work to the window, and at the window's end asks the page for twice
|
|
832
1108
|
* the `asked` job workers, and at least 2, when the frames handed out enough work to share.
|
|
833
|
-
*
|
|
834
|
-
*
|
|
1109
|
+
* The window ends at its frame count, or at its deadline once it holds enough frames, so a
|
|
1110
|
+
* slow GPU asks as a fast one does. After a window with less, the loops go untimed for a
|
|
1111
|
+
* while; once every job worker has been asked for, for good.
|
|
835
1112
|
*/
|
|
836
1113
|
growJobs(glue, asked) {
|
|
837
1114
|
if (asked >= this.jobRecords.length) {
|
|
@@ -845,8 +1122,14 @@ export class SketchRunner {
|
|
|
845
1122
|
this.timeHandedLoops(glue, true);
|
|
846
1123
|
return;
|
|
847
1124
|
}
|
|
1125
|
+
if (this.jobWindowFrames === 0)
|
|
1126
|
+
this.jobWindowStart = this.clock.now;
|
|
848
1127
|
this.jobWindowUs += glue.takeHandedUs();
|
|
849
|
-
|
|
1128
|
+
this.jobWindowFrames++;
|
|
1129
|
+
const byFrames = this.jobWindowFrames >= JOB_WINDOW;
|
|
1130
|
+
const byDeadline = this.jobWindowFrames >= JOB_WINDOW_MIN_FRAMES &&
|
|
1131
|
+
this.clock.now - this.jobWindowStart >= JOB_WINDOW_SECONDS;
|
|
1132
|
+
if (!byFrames && !byDeadline)
|
|
850
1133
|
return;
|
|
851
1134
|
const enough = this.jobWindowUs >= JOB_GROW_US * this.jobWindowFrames;
|
|
852
1135
|
this.jobWindowUs = 0;
|
|
@@ -901,7 +1184,8 @@ export class SketchRunner {
|
|
|
901
1184
|
this.heldScale = high;
|
|
902
1185
|
const { governor } = this;
|
|
903
1186
|
governor.setOn(settings.governor);
|
|
904
|
-
governor.
|
|
1187
|
+
governor.setLevelSteps(settings.governorLevels);
|
|
1188
|
+
governor.setRange(low, high, this.quality.owns('minRenderScale'));
|
|
905
1189
|
this.followMovers = settings.followMovingCasters;
|
|
906
1190
|
this.cascadeBlend = settings.shadowCascadeBlend;
|
|
907
1191
|
this.lodThreshold = settings.lodThreshold;
|
|
@@ -923,6 +1207,7 @@ export class SketchRunner {
|
|
|
923
1207
|
this.stepChanges = governor.stepChanges;
|
|
924
1208
|
const { glue } = this.sketch;
|
|
925
1209
|
if (glue.setRenderScaling((settings.governor ? low : high) < FULL_SCALE) !== 0 ||
|
|
1210
|
+
glue.setDepthPrepass(settings.depthPrepass) !== 0 ||
|
|
926
1211
|
this.setShadowQuality() !== 0 ||
|
|
927
1212
|
glue.setBloomChain(this.bloomSetting, governor.bloomHalvings) !== 0 ||
|
|
928
1213
|
glue.setAoScale(governor.aoScale) !== 0 ||
|
|
@@ -996,11 +1281,13 @@ export class SketchRunner {
|
|
|
996
1281
|
}
|
|
997
1282
|
/**
|
|
998
1283
|
* Gives the core the shadow settings and bloom's base after a step of the governor, and tells
|
|
999
|
-
* the sketch's change handlers of it.
|
|
1284
|
+
* the sketch's change handlers of it. The lowest quality tier's settings come before those
|
|
1285
|
+
* steps, so a step that the tier's cuts allow reads the values that it leaves.
|
|
1000
1286
|
*/
|
|
1001
1287
|
applyGovernedSteps() {
|
|
1002
1288
|
const { governor } = this;
|
|
1003
1289
|
const { glue } = this.sketch;
|
|
1290
|
+
this.applyTierSettings();
|
|
1004
1291
|
this.stepChanges = governor.stepChanges;
|
|
1005
1292
|
if (this.setLevelQuality() !== 0 ||
|
|
1006
1293
|
this.setShadowQuality() !== 0 ||
|
|
@@ -1012,6 +1299,39 @@ export class SketchRunner {
|
|
|
1012
1299
|
this.report(coreFailure(glue, 'the quality governor'));
|
|
1013
1300
|
this.quality.governed();
|
|
1014
1301
|
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Applies the lowest quality tier's cuts when the governor enters it, and gives the settings
|
|
1304
|
+
* back when it leaves. The sketch's own choice of a preset does not keep them: a preset gives
|
|
1305
|
+
* the settings its own values again.
|
|
1306
|
+
*/
|
|
1307
|
+
applyTierSettings() {
|
|
1308
|
+
const { governor, quality } = this;
|
|
1309
|
+
this.tierChanges = governor.tierChanges;
|
|
1310
|
+
const { settings } = quality;
|
|
1311
|
+
// A render-scale floor that the sketch set itself wins over the tier's, in the tier and as it
|
|
1312
|
+
// leaves.
|
|
1313
|
+
const ownFloor = quality.owns('minRenderScale');
|
|
1314
|
+
if (governor.lowest) {
|
|
1315
|
+
this.tierRestore ??= tierRestoreSettings(settings);
|
|
1316
|
+
const cuts = lowestTierCuts(this.sketch.capabilities.tier, settings.minRenderScale);
|
|
1317
|
+
if (ownFloor)
|
|
1318
|
+
delete cuts.minRenderScale;
|
|
1319
|
+
const current = settings;
|
|
1320
|
+
if (Object.entries(cuts).some(([name, value]) => current[name] !== value))
|
|
1321
|
+
void quality.setGoverned(cuts);
|
|
1322
|
+
if (ownFloor)
|
|
1323
|
+
governor.setRange(thousandths(settings.minRenderScale), thousandths(settings.maxRenderScale), true);
|
|
1324
|
+
}
|
|
1325
|
+
else if (this.tierRestore) {
|
|
1326
|
+
const restore = { ...this.tierRestore };
|
|
1327
|
+
this.tierRestore = undefined;
|
|
1328
|
+
if (ownFloor) {
|
|
1329
|
+
delete restore.minRenderScale;
|
|
1330
|
+
restore.maxRenderScale = Math.max(restore.maxRenderScale ?? settings.maxRenderScale, settings.minRenderScale);
|
|
1331
|
+
}
|
|
1332
|
+
void quality.setGoverned(restore);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1015
1335
|
/**
|
|
1016
1336
|
* Gives the governor the steps that the sketch's budgets allow, and moves the budgets to the
|
|
1017
1337
|
* governor's steps of their scale, which calls their `onScale` handlers.
|
|
@@ -1131,6 +1451,10 @@ export class SketchRunner {
|
|
|
1131
1451
|
* `timestamp` is the frame's time in milliseconds.
|
|
1132
1452
|
*/
|
|
1133
1453
|
step(timestamp) {
|
|
1454
|
+
// A live sketch's `firstFrame` resolves at the first step after the GPU finished the first
|
|
1455
|
+
// frame, which the thread that draws records; the check ends once it has.
|
|
1456
|
+
if (this.firstFrameReached !== undefined && !this.holdsFrames && this.record.firstFrameDone)
|
|
1457
|
+
this.reachFirstFrame();
|
|
1134
1458
|
const resumes = Atomics.load(this.sketch.control.slots, Slot.Resumes);
|
|
1135
1459
|
this.resumed = this.resumes >= 0 && resumes !== this.resumes;
|
|
1136
1460
|
this.resumes = resumes;
|
|
@@ -1170,6 +1494,12 @@ export class SketchRunner {
|
|
|
1170
1494
|
this.render.held = true;
|
|
1171
1495
|
this.recorded.held = true;
|
|
1172
1496
|
try {
|
|
1497
|
+
// The tasks and level plans that the setup started answer whenever the job workers finish
|
|
1498
|
+
// them. The steps start once they all have, and the plans hand over their levels in the
|
|
1499
|
+
// order they started, so the steps and the held frame find the same scene on every run.
|
|
1500
|
+
releasePlans();
|
|
1501
|
+
if (tasksPending() > 0)
|
|
1502
|
+
await this.settleTasks();
|
|
1173
1503
|
for (let step = 0; step <= steps; step++) {
|
|
1174
1504
|
this.clock.holdStep(step, steps, seconds);
|
|
1175
1505
|
const now = this.clock.now;
|
|
@@ -1237,6 +1567,7 @@ export class SketchRunner {
|
|
|
1237
1567
|
throw new EngineError('E1408', `hold mode stopped at ${Number(this.clock.now.toFixed(3))} seconds, in frame ${this.context.time.frame}: ${messageOf(error)}${phase}`);
|
|
1238
1568
|
}
|
|
1239
1569
|
finally {
|
|
1570
|
+
endPlanHold();
|
|
1240
1571
|
this.holding = false;
|
|
1241
1572
|
this.time.held = false;
|
|
1242
1573
|
this.time.drawn = true;
|
|
@@ -1561,11 +1892,12 @@ export class SketchRunner {
|
|
|
1561
1892
|
this.readViewport();
|
|
1562
1893
|
// The governor judges the frames so far before the sketch's update, which then sees the
|
|
1563
1894
|
// render scale of this frame, and whose change handlers hear of a shadow step.
|
|
1564
|
-
if (play && this.governorLoop) {
|
|
1895
|
+
if (play && this.governorLoop && !this.checking) {
|
|
1565
1896
|
this.governorLoop.now[0] = start;
|
|
1566
1897
|
this.governorLoop.frame(this.resumed);
|
|
1567
1898
|
this.resumed = false;
|
|
1568
|
-
if (this.governor.stepChanges !== this.stepChanges
|
|
1899
|
+
if (this.governor.stepChanges !== this.stepChanges ||
|
|
1900
|
+
this.governor.tierChanges !== this.tierChanges)
|
|
1569
1901
|
this.applyGovernedSteps();
|
|
1570
1902
|
}
|
|
1571
1903
|
// Handlers that hear of a restart may create objects with new pipelines, so their frame
|
|
@@ -1652,7 +1984,8 @@ export class SketchRunner {
|
|
|
1652
1984
|
}
|
|
1653
1985
|
if (this.followEffects())
|
|
1654
1986
|
restart = true;
|
|
1655
|
-
if (this.governor.stepChanges !== this.stepChanges
|
|
1987
|
+
if (this.governor.stepChanges !== this.stepChanges ||
|
|
1988
|
+
this.governor.tierChanges !== this.tierChanges)
|
|
1656
1989
|
this.applyGovernedSteps();
|
|
1657
1990
|
// Development builds first report static batch rows written without markDirty, because the
|
|
1658
1991
|
// batch update clears the marks.
|