@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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EngineError } from '../errors/engine-error.js';
|
|
2
|
+
/** The first frame's promise, which the start settles once. */
|
|
3
|
+
export declare class FirstFrame {
|
|
4
|
+
readonly promise: Promise<void>;
|
|
5
|
+
private resolve;
|
|
6
|
+
private reject;
|
|
7
|
+
constructor();
|
|
8
|
+
/** The GPU has finished the first frame. */
|
|
9
|
+
drawn(): void;
|
|
10
|
+
/**
|
|
11
|
+
* The engine draws no more frames. `drawn` says whether the GPU finished the first frame first,
|
|
12
|
+
* which resolves the promise. Otherwise it rejects with `failure`, the failure that ended the
|
|
13
|
+
* frames, or with E1420 for a stop that no failure caused.
|
|
14
|
+
*/
|
|
15
|
+
stopped(drawn: boolean, failure?: EngineError): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// `engine.firstFrame`: resolves once the GPU has finished the first frame after the setup, and
|
|
2
|
+
// rejects when the engine stops drawing first, so a page that waits only for the first frame
|
|
3
|
+
// hears why it never came. The engine starts its frames once the setup has run, and the preset
|
|
4
|
+
// check measures them during play, so a failure of the thread that draws at its first frame comes
|
|
5
|
+
// after `createEngine` has resolved.
|
|
6
|
+
import { EngineError } from '../errors/engine-error.js';
|
|
7
|
+
/** The first frame's promise, which the start settles once. */
|
|
8
|
+
export class FirstFrame {
|
|
9
|
+
promise;
|
|
10
|
+
resolve = () => { };
|
|
11
|
+
reject = () => { };
|
|
12
|
+
constructor() {
|
|
13
|
+
this.promise = new Promise((resolve, reject) => {
|
|
14
|
+
this.resolve = resolve;
|
|
15
|
+
this.reject = reject;
|
|
16
|
+
});
|
|
17
|
+
// A page that never waits for the first frame hears nothing of a rejection.
|
|
18
|
+
this.promise.catch(() => { });
|
|
19
|
+
}
|
|
20
|
+
/** The GPU has finished the first frame. */
|
|
21
|
+
drawn() {
|
|
22
|
+
this.resolve();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The engine draws no more frames. `drawn` says whether the GPU finished the first frame first,
|
|
26
|
+
* which resolves the promise. Otherwise it rejects with `failure`, the failure that ended the
|
|
27
|
+
* frames, or with E1420 for a stop that no failure caused.
|
|
28
|
+
*/
|
|
29
|
+
stopped(drawn, failure) {
|
|
30
|
+
if (drawn)
|
|
31
|
+
this.resolve();
|
|
32
|
+
else
|
|
33
|
+
this.reject(failure ?? new EngineError('E1420', 'the engine stopped before it drew its first frame.'));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PhaseName, type RingRecords } from '../shared/metrics.js';
|
|
1
|
+
import { type MetricsReader, type PhaseName, type RingRecords } from '../shared/metrics.js';
|
|
2
2
|
import { type Percentiles } from '../shared/stats.js';
|
|
3
3
|
/**
|
|
4
4
|
* One thread's CPU time per frame, in `FrameSummary.threads`.
|
|
@@ -261,6 +261,13 @@ export interface FrameMetrics extends FrameSummary {
|
|
|
261
261
|
firstDrawMs: number | null;
|
|
262
262
|
/** GPU pipelines that the first frame built, or null before the first frame. */
|
|
263
263
|
firstFramePipelines: number | null;
|
|
264
|
+
/**
|
|
265
|
+
* When the thread that draws reached each step of its start, in milliseconds from the start
|
|
266
|
+
* of page navigation. Right after the probe, the page tells that thread which GPU path and
|
|
267
|
+
* device to start, so it asks for its device and its shader files while the core downloads.
|
|
268
|
+
* A step that the thread has not reached, or does not take, is null.
|
|
269
|
+
*/
|
|
270
|
+
drawingStart: DrawingStart;
|
|
264
271
|
/**
|
|
265
272
|
* The quality preset in force when the first frame was drawn: the one the engine starts with.
|
|
266
273
|
* It can differ from the preset the page ends on, because the engine's own preset check may
|
|
@@ -296,6 +303,32 @@ export interface FrameMetrics extends FrameSummary {
|
|
|
296
303
|
*/
|
|
297
304
|
slow?: SlowFrame[];
|
|
298
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* When the thread that draws reached each step of its start, in `FrameMetrics.load.drawingStart`:
|
|
308
|
+
* milliseconds from the start of page navigation, or null for a step that it has not reached or
|
|
309
|
+
* does not take.
|
|
310
|
+
*
|
|
311
|
+
* @category api/debug
|
|
312
|
+
*/
|
|
313
|
+
export interface DrawingStart {
|
|
314
|
+
/**
|
|
315
|
+
* The page's message after the probe arrived. The thread then started the downloads of its
|
|
316
|
+
* renderers and shader files, and on WebGPU the request for its device.
|
|
317
|
+
*/
|
|
318
|
+
requestMs: number | null;
|
|
319
|
+
/** Its WebGPU adapter arrived. Null on WebGL2. */
|
|
320
|
+
adapterMs: number | null;
|
|
321
|
+
/** Its WebGPU device arrived. Null on WebGL2. */
|
|
322
|
+
deviceMs: number | null;
|
|
323
|
+
/** The shader file of its device arrived. */
|
|
324
|
+
shadersMs: number | null;
|
|
325
|
+
/** The core and the thread's setup arrived from the page. */
|
|
326
|
+
initMs: number | null;
|
|
327
|
+
/** Its first renderer was built, so its frame loop could start. */
|
|
328
|
+
rendererMs: number | null;
|
|
329
|
+
}
|
|
330
|
+
/** The start of the thread that draws, as `reader` holds it, on the page's timeline. */
|
|
331
|
+
export declare function drawingStartFigures(reader: MetricsReader): DrawingStart;
|
|
299
332
|
/**
|
|
300
333
|
* The frame rates of one second of a measurement, in `FrameMetrics.perSecond`.
|
|
301
334
|
*
|
package/lib/page/frame-stats.js
CHANGED
|
@@ -7,6 +7,21 @@ import { commonStep, stepMs } from '../shared/gpu-clock.js';
|
|
|
7
7
|
import { COUNTER_NAMES, Counter, GPU_TIMED_PASSES, GpuCounter, PHASE_NAMES, Role, UNTIMED, } from '../shared/metrics.js';
|
|
8
8
|
import { measureWithEveryThread } from '../shared/page-measurement.js';
|
|
9
9
|
import { countPerSecond, percentiles, ratePerSecond, spanMs, } from '../shared/stats.js';
|
|
10
|
+
/** The start of the thread that draws, as `reader` holds it, on the page's timeline. */
|
|
11
|
+
export function drawingStartFigures(reader) {
|
|
12
|
+
const at = (step) => {
|
|
13
|
+
const epoch = reader.drawingStep(step);
|
|
14
|
+
return epoch > 0 ? epoch - performance.timeOrigin : null;
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
requestMs: at('request'),
|
|
18
|
+
adapterMs: at('adapter'),
|
|
19
|
+
deviceMs: at('device'),
|
|
20
|
+
shadersMs: at('shaders'),
|
|
21
|
+
initMs: at('init'),
|
|
22
|
+
rendererMs: at('renderer'),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
10
25
|
const NO_RECORDS = {
|
|
11
26
|
frames: [],
|
|
12
27
|
busy: [],
|
package/lib/page/label-loop.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export declare class LabelLoop {
|
|
|
25
25
|
private readonly seen;
|
|
26
26
|
/** The camera that the containers show, and the canvas size, as the update read them. */
|
|
27
27
|
private readonly cameraSeen;
|
|
28
|
+
/** The presented frame's camera, which the update reads with the tables. */
|
|
29
|
+
private readonly cameraNext;
|
|
28
30
|
/** The transform of a container, and the container of each parent element that holds 3D labels. */
|
|
29
31
|
private containerTransform;
|
|
30
32
|
private readonly containers;
|
|
@@ -52,11 +54,13 @@ export declare class LabelLoop {
|
|
|
52
54
|
/** Moves each bound element to its label in the frame on screen, if anything changed. */
|
|
53
55
|
update(): void;
|
|
54
56
|
/**
|
|
55
|
-
* Reads each binding's place from the presented tables into `next
|
|
56
|
-
*
|
|
57
|
+
* Reads each binding's place from the presented tables into `next`, and the presented frame's
|
|
58
|
+
* camera with them, under the same sequence count, so the elements and the containers show one
|
|
59
|
+
* frame. Returns that count, or -1 when the thread that draws kept changing the tables, so the
|
|
60
|
+
* elements stay as they are until the next update.
|
|
57
61
|
*/
|
|
58
62
|
private read;
|
|
59
|
-
/** Moves the containers to the
|
|
63
|
+
/** Moves the containers to the camera that the update read, when it or the canvas changed. */
|
|
60
64
|
private updateCamera;
|
|
61
65
|
/** Writes the styles of the elements whose place or view changed, after every read. */
|
|
62
66
|
private write;
|
package/lib/page/label-loop.js
CHANGED
|
@@ -50,6 +50,8 @@ export class LabelLoop {
|
|
|
50
50
|
seen = Float64Array.of(-1, 0, 0);
|
|
51
51
|
/** The camera that the containers show, and the canvas size, as the update read them. */
|
|
52
52
|
cameraSeen = new Float64Array(CAMERA_STATE).fill(Number.NaN);
|
|
53
|
+
/** The presented frame's camera, which the update reads with the tables. */
|
|
54
|
+
cameraNext = new Float64Array(CAMERA_STATE - 2);
|
|
53
55
|
/** The transform of a container, and the container of each parent element that holds 3D labels. */
|
|
54
56
|
containerTransform = '';
|
|
55
57
|
containers = new Map();
|
|
@@ -146,19 +148,22 @@ export class LabelLoop {
|
|
|
146
148
|
const sequence = labelSequence(region);
|
|
147
149
|
if (!this.changed && sequence === seen[0] && width === seen[1] && height === seen[2])
|
|
148
150
|
return;
|
|
149
|
-
|
|
151
|
+
const read = this.read(region, count, width, height);
|
|
152
|
+
if (read < 0)
|
|
150
153
|
return;
|
|
151
|
-
seen[0] =
|
|
154
|
+
seen[0] = read;
|
|
152
155
|
seen[1] = width;
|
|
153
156
|
seen[2] = height;
|
|
154
157
|
this.changed = false;
|
|
155
158
|
if (this.three > 0)
|
|
156
|
-
this.updateCamera(
|
|
159
|
+
this.updateCamera(width, height);
|
|
157
160
|
this.write(count);
|
|
158
161
|
}
|
|
159
162
|
/**
|
|
160
|
-
* Reads each binding's place from the presented tables into `next
|
|
161
|
-
*
|
|
163
|
+
* Reads each binding's place from the presented tables into `next`, and the presented frame's
|
|
164
|
+
* camera with them, under the same sequence count, so the elements and the containers show one
|
|
165
|
+
* frame. Returns that count, or -1 when the thread that draws kept changing the tables, so the
|
|
166
|
+
* elements stay as they are until the next update.
|
|
162
167
|
*/
|
|
163
168
|
read(region, count, width, height) {
|
|
164
169
|
const { ints, floats } = region;
|
|
@@ -194,17 +199,19 @@ export class LabelLoop {
|
|
|
194
199
|
next[n + STATE_X] = ((floats[at + LABEL_X] + 1) / 2) * width;
|
|
195
200
|
next[n + STATE_Y] = ((1 - floats[at + LABEL_Y]) / 2) * height;
|
|
196
201
|
}
|
|
202
|
+
if (this.three > 0)
|
|
203
|
+
this.cameraNext.set(region.presentedCamera);
|
|
197
204
|
if (labelSequence(region) !== sequence)
|
|
198
205
|
continue;
|
|
199
206
|
this.frame = frame;
|
|
200
|
-
return
|
|
207
|
+
return sequence;
|
|
201
208
|
}
|
|
202
|
-
return
|
|
209
|
+
return -1;
|
|
203
210
|
}
|
|
204
|
-
/** Moves the containers to the
|
|
205
|
-
updateCamera(
|
|
211
|
+
/** Moves the containers to the camera that the update read, when it or the canvas changed. */
|
|
212
|
+
updateCamera(width, height) {
|
|
206
213
|
const seen = this.cameraSeen;
|
|
207
|
-
const camera =
|
|
214
|
+
const camera = this.cameraNext;
|
|
208
215
|
let changed = seen[CAMERA_STATE - 2] !== width || seen[CAMERA_STATE - 1] !== height;
|
|
209
216
|
for (let k = 0; k < CAMERA_STATE - 2; k++) {
|
|
210
217
|
if (seen[k] !== camera[k])
|
package/lib/page/labels.d.ts
CHANGED
|
@@ -16,9 +16,9 @@ export interface EngineLabels {
|
|
|
16
16
|
*
|
|
17
17
|
* A label that the sketch tracks with `transform: 'world'` or `'billboard'` is a plane of the
|
|
18
18
|
* scene: the engine moves the element into a container of its own inside the element's parent,
|
|
19
|
-
* and turns it with the scene's perspective
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* and turns it with the scene's perspective. Leave the element's `transform-origin` at its
|
|
20
|
+
* center, and size the element in CSS pixels, which are the scene's units at the distance where
|
|
21
|
+
* the view is one pixel per unit.
|
|
22
22
|
*/
|
|
23
23
|
bind(id: string, element: HTMLElement): () => void;
|
|
24
24
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { QualityPreset } from '../quality/presets.js';
|
|
2
|
+
import type { Tier } from '../shared/tier.js';
|
|
3
|
+
/**
|
|
4
|
+
* The facts that a pipeline list depends on, as one text: the engine's version, the GPU path, the
|
|
5
|
+
* device's fixed shader bits, the preset and the canvas's format. Two starts with the same text
|
|
6
|
+
* ask for the same pipelines for the same scene.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pipelineConditions(tier: Tier, shaderBits: number, preset: QualityPreset, canvasFormat: string | undefined): string;
|
|
9
|
+
/** True when `list` holds whole create commands only, as a thread that draws lists them. */
|
|
10
|
+
export declare function isPipelineList(list: readonly number[]): boolean;
|
|
11
|
+
/** The stored pipeline list of one sketch, for one start of it. */
|
|
12
|
+
export declare class PipelineStore {
|
|
13
|
+
private readonly conditions;
|
|
14
|
+
private readonly storage;
|
|
15
|
+
private readonly key;
|
|
16
|
+
/**
|
|
17
|
+
* `conditions` are the start's, as `pipelineConditions` gives them. `storage` stands in for the
|
|
18
|
+
* page's localStorage in tests.
|
|
19
|
+
*/
|
|
20
|
+
constructor(sketchUrl: string, conditions: string, storage?: Storage | undefined);
|
|
21
|
+
/** The stored list that applies to this start, or undefined. */
|
|
22
|
+
read(): Uint32Array | undefined;
|
|
23
|
+
/** Stores the list of the pipelines that this start's first frame built. */
|
|
24
|
+
save(list: Uint32Array): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The stored pipeline list: the pipelines that the first frame of each sketch's last start built,
|
|
2
|
+
// kept in the page's localStorage. The next start of the sketch in the same browser hands the list
|
|
3
|
+
// to the thread that draws, which starts those builds as soon as their shaders are there, while
|
|
4
|
+
// the core downloads and the setup runs (`gpu/early-builds.ts`). A start without a stored list
|
|
5
|
+
// builds each pipeline when the first frame asks for it. Chrome's own cache of compiled pipelines
|
|
6
|
+
// is small on Android, so a scene of a few dozen pipelines outgrows it and each visit compiles
|
|
7
|
+
// every pipeline again. A list applies only to a start on the same GPU path, with the same fixed
|
|
8
|
+
// shader bits, at the same preset, with the same engine version. It only names pipelines, so a
|
|
9
|
+
// list that the scene outgrew costs builds that no frame takes, never a wrong picture. Storage that
|
|
10
|
+
// cannot be read or written counts as empty.
|
|
11
|
+
import { OP_CREATE_COMPUTE_PIPELINE, OP_CREATE_RENDER_PIPELINE } from '../generated/gpu.js';
|
|
12
|
+
import { operandsAfterId, PIPELINE_LIST_LIMIT } from '../gpu/early-builds.js';
|
|
13
|
+
import { VERSION } from '../shared/version.js';
|
|
14
|
+
import { pageStorage } from './start-marker.js';
|
|
15
|
+
const KEY_PREFIX = 'null3d.pipelines:';
|
|
16
|
+
/**
|
|
17
|
+
* The facts that a pipeline list depends on, as one text: the engine's version, the GPU path, the
|
|
18
|
+
* device's fixed shader bits, the preset and the canvas's format. Two starts with the same text
|
|
19
|
+
* ask for the same pipelines for the same scene.
|
|
20
|
+
*/
|
|
21
|
+
export function pipelineConditions(tier, shaderBits, preset, canvasFormat) {
|
|
22
|
+
return JSON.stringify([VERSION, tier, shaderBits, preset, canvasFormat ?? null]);
|
|
23
|
+
}
|
|
24
|
+
/** True when `list` holds whole create commands only, as a thread that draws lists them. */
|
|
25
|
+
export function isPipelineList(list) {
|
|
26
|
+
let commands = 0;
|
|
27
|
+
for (let i = 0; i < list.length; commands++) {
|
|
28
|
+
const op = list[i];
|
|
29
|
+
if (op !== OP_CREATE_RENDER_PIPELINE && op !== OP_CREATE_COMPUTE_PIPELINE)
|
|
30
|
+
return false;
|
|
31
|
+
const end = i + 1 + operandsAfterId(op);
|
|
32
|
+
if (end > list.length || commands >= PIPELINE_LIST_LIMIT)
|
|
33
|
+
return false;
|
|
34
|
+
for (let k = i + 1; k < end; k++) {
|
|
35
|
+
const word = list[k];
|
|
36
|
+
if (!Number.isInteger(word) || word < 0 || word > 0xffffffff)
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
i = end;
|
|
40
|
+
}
|
|
41
|
+
return list.length > 0;
|
|
42
|
+
}
|
|
43
|
+
/** The stored pipeline list of one sketch, for one start of it. */
|
|
44
|
+
export class PipelineStore {
|
|
45
|
+
conditions;
|
|
46
|
+
storage;
|
|
47
|
+
key;
|
|
48
|
+
/**
|
|
49
|
+
* `conditions` are the start's, as `pipelineConditions` gives them. `storage` stands in for the
|
|
50
|
+
* page's localStorage in tests.
|
|
51
|
+
*/
|
|
52
|
+
constructor(sketchUrl, conditions, storage = pageStorage()) {
|
|
53
|
+
this.conditions = conditions;
|
|
54
|
+
this.storage = storage;
|
|
55
|
+
this.key = KEY_PREFIX + sketchUrl;
|
|
56
|
+
}
|
|
57
|
+
/** The stored list that applies to this start, or undefined. */
|
|
58
|
+
read() {
|
|
59
|
+
try {
|
|
60
|
+
const text = this.storage?.getItem(this.key);
|
|
61
|
+
if (!text)
|
|
62
|
+
return undefined;
|
|
63
|
+
const stored = JSON.parse(text);
|
|
64
|
+
if (stored?.conditions !== this.conditions || !Array.isArray(stored.list))
|
|
65
|
+
return undefined;
|
|
66
|
+
return isPipelineList(stored.list) ? Uint32Array.from(stored.list) : undefined;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Stores the list of the pipelines that this start's first frame built. */
|
|
73
|
+
save(list) {
|
|
74
|
+
if (!isPipelineList(Array.from(list)))
|
|
75
|
+
return;
|
|
76
|
+
const stored = { conditions: this.conditions, list: Array.from(list) };
|
|
77
|
+
try {
|
|
78
|
+
this.storage?.setItem(this.key, JSON.stringify(stored));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// The next start builds each pipeline when its first frame asks for it.
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -37,7 +37,10 @@ export declare class StartMarker {
|
|
|
37
37
|
* and removes it when the page leaves.
|
|
38
38
|
*/
|
|
39
39
|
begin(history: StartHistory, tier: Tier): void;
|
|
40
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Removes the note once the engine has drawn for `playMs` after `firstFrame`. A first frame that
|
|
42
|
+
* never comes leaves the note to the stop, which removes it.
|
|
43
|
+
*/
|
|
41
44
|
endAfter(firstFrame: Promise<void>, playMs?: number): void;
|
|
42
45
|
/** Removes the note, if this page load wrote it. Later calls do nothing. */
|
|
43
46
|
end(): void;
|
package/lib/page/start-marker.js
CHANGED
|
@@ -90,12 +90,15 @@ export class StartMarker {
|
|
|
90
90
|
}
|
|
91
91
|
globalThis.addEventListener?.('pagehide', this.onPageHide);
|
|
92
92
|
}
|
|
93
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Removes the note once the engine has drawn for `playMs` after `firstFrame`. A first frame that
|
|
95
|
+
* never comes leaves the note to the stop, which removes it.
|
|
96
|
+
*/
|
|
94
97
|
endAfter(firstFrame, playMs = STABLE_PLAY_MS) {
|
|
95
98
|
void firstFrame.then(() => {
|
|
96
99
|
if (!this.ended)
|
|
97
100
|
this.timer = setTimeout(() => this.end(), playMs);
|
|
98
|
-
});
|
|
101
|
+
}, () => { });
|
|
99
102
|
}
|
|
100
103
|
/** Removes the note, if this page load wrote it. Later calls do nothing. */
|
|
101
104
|
end() {
|
package/lib/page/switches.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StatsRequest } from '../debug/stats-options.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type PresetCheckTiming, type TargetFps } from '../quality/check.js';
|
|
3
3
|
import { type QualityPreset } from '../quality/presets.js';
|
|
4
4
|
export type GpuSwitch = 'auto' | 'webgpu' | 'compat' | 'webgl2';
|
|
5
5
|
/**
|
|
@@ -38,13 +38,20 @@ export type SketchThread = 'worker' | 'main';
|
|
|
38
38
|
* draws it. WebGL2 draws it where the browser has the `EXT_clip_control` extension, which gives
|
|
39
39
|
* WebGL2 the depth range from 0 to 1 that WebGPU has. The `reversed-gl` mode keeps the same
|
|
40
40
|
* order, but in WebGL2's own depth range from -1 to 1, which loses most of the precision. In
|
|
41
|
-
* `standard` depth, the near plane stores 0
|
|
41
|
+
* `standard` depth, the near plane stores 0 and the far plane 1.
|
|
42
42
|
*
|
|
43
43
|
* @category api/engine
|
|
44
44
|
*/
|
|
45
45
|
export type DepthMode = 'reversed' | 'reversed-gl' | 'standard';
|
|
46
46
|
/** A format of the HDR scene color that the ?scene-format= switch names. */
|
|
47
47
|
export type SceneFormat = 'rg11b10' | 'rgba16f';
|
|
48
|
+
/**
|
|
49
|
+
* The quality tier that ?tier= names: `lowest` starts the page in the tier below the four presets,
|
|
50
|
+
* with its start values; `off` keeps the governor out of the tier, so a test measures the presets
|
|
51
|
+
* alone. Without the switch the governor enters the tier only when frames still miss at the
|
|
52
|
+
* preset's floor (D-382).
|
|
53
|
+
*/
|
|
54
|
+
export type LowestTier = 'lowest' | 'off';
|
|
48
55
|
/** The bits per texel of the shadow cascades' depth. */
|
|
49
56
|
export type ShadowDepthBits = 16 | 32;
|
|
50
57
|
/**
|
|
@@ -108,6 +115,11 @@ export interface Switches {
|
|
|
108
115
|
* of taking the preset check's stored result from an earlier start.
|
|
109
116
|
*/
|
|
110
117
|
freshCheck: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* True when ?builds=fresh makes the first frame start every pipeline build itself, as on a first
|
|
120
|
+
* visit, instead of building the stored list of an earlier start's first frame ahead of it.
|
|
121
|
+
*/
|
|
122
|
+
freshBuilds: boolean;
|
|
111
123
|
/**
|
|
112
124
|
* True when ?two-step=report makes a development page log the two-step pass's answers once the
|
|
113
125
|
* first frame is on screen: whether the frame wanted the pass, declared it, had its second step
|
|
@@ -231,6 +243,12 @@ export interface Switches {
|
|
|
231
243
|
* the page's `targetFps` option, or undefined without the switch or with another value.
|
|
232
244
|
*/
|
|
233
245
|
targetFps: TargetFps | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* When the preset check measures, from ?preset-check=: `during-play` or `before-play`, which
|
|
248
|
+
* wins over the page's `presetCheck` option, or undefined without the switch or with another
|
|
249
|
+
* value.
|
|
250
|
+
*/
|
|
251
|
+
presetCheck: PresetCheckTiming | undefined;
|
|
234
252
|
/**
|
|
235
253
|
* The most job workers that ?jobs= lets the engine start, or undefined for the count from the
|
|
236
254
|
* device's cores. The engine starts them as the work grows, and no more than the device has
|
|
@@ -253,6 +271,13 @@ export interface Switches {
|
|
|
253
271
|
* crash marker, or undefined without the switch or with a name that is no preset.
|
|
254
272
|
*/
|
|
255
273
|
preset: QualityPreset | undefined;
|
|
274
|
+
/**
|
|
275
|
+
* `'lowest'` when ?tier=lowest starts the page in the lowest quality tier: the render scale at
|
|
276
|
+
* a third, the sun's shadows and bloom off, and WebGL2's depth prepass off. The tier exists for
|
|
277
|
+
* tests, devices and a known weak class, while the governor is the default path to it. Undefined
|
|
278
|
+
* for any other name, or without the switch.
|
|
279
|
+
*/
|
|
280
|
+
lowestTier: LowestTier | undefined;
|
|
256
281
|
/**
|
|
257
282
|
* The text of ?hold=, an empty text for a bare ?hold, or undefined without the switch. The
|
|
258
283
|
* engine checks it when it starts, so a bad time fails at once instead of starting a live engine.
|
|
@@ -274,6 +299,11 @@ export interface Switches {
|
|
|
274
299
|
still: boolean;
|
|
275
300
|
/** True when ?bench asks the engine to publish itself on the page for a benchmark tool. */
|
|
276
301
|
bench: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* True when ?inspect opens the development build's in-page inspector, which lists the scene,
|
|
304
|
+
* selects an object and edits its transform, material and visibility.
|
|
305
|
+
*/
|
|
306
|
+
inspect: boolean;
|
|
277
307
|
/**
|
|
278
308
|
* The debug view that ?view= asks for, by the name that `debug.view` takes: one of the engine's
|
|
279
309
|
* own views, or a view that an add-on's feature registers. Undefined without the switch.
|
package/lib/page/switches.js
CHANGED
|
@@ -17,12 +17,16 @@
|
|
|
17
17
|
// in a pass each, none joined, for pages that measure what joining saves. ?replay-delay= makes the
|
|
18
18
|
// thread that draws wait before it replays each frame's list, for a test of memory that the sketch
|
|
19
19
|
// thread frees while the list may still point at it. ?hold starts hold mode for image tests, ?preset= fixes the quality preset,
|
|
20
|
-
// ?target-fps= sets the frame rate that the
|
|
20
|
+
// ?tier=lowest starts in the lowest quality tier, ?target-fps= sets the frame rate that the
|
|
21
|
+
// engine defends, ?preset-check= says whether the preset check measures during play or before it,
|
|
22
|
+
// ?bench publishes the running engine
|
|
21
23
|
// for benchmark tools, ?gl-timing times each WebGL call for benchmark pages, ?stats shows the
|
|
22
24
|
// stats overlay, and ?view picks a debug view, one of the engine's own or one that an add-on's
|
|
23
25
|
// feature registers.
|
|
26
|
+
import { PRESET_CHECK_TIMINGS } from '../quality/check.js';
|
|
24
27
|
import { QUALITY_PRESETS, QUALITY_SETTINGS } from '../quality/presets.js';
|
|
25
28
|
const SCENE_FORMATS = ['rg11b10', 'rgba16f'];
|
|
29
|
+
const LOWEST_TIERS = ['lowest', 'off'];
|
|
26
30
|
const COMPRESSION_FAMILIES = ['astc', 'bc', 'etc2'];
|
|
27
31
|
/** The longest wait that ?replay-delay= gives, in ms: longer would stall the frames for good. */
|
|
28
32
|
const MAX_REPLAY_DELAY_MS = 1000;
|
|
@@ -97,6 +101,7 @@ export function parseSwitches(search) {
|
|
|
97
101
|
parallelCompile: params.get('compile') !== 'wait',
|
|
98
102
|
freshShaders: params.get('shaders') === 'fresh',
|
|
99
103
|
freshCheck: params.get('check') === 'fresh',
|
|
104
|
+
freshBuilds: params.get('builds') === 'fresh',
|
|
100
105
|
wakeByMessage: params.get('wake') === 'message',
|
|
101
106
|
twoStep: params.get('two-step') === 'report',
|
|
102
107
|
displayChecks: params.get('display-check') !== 'off',
|
|
@@ -119,15 +124,18 @@ export function parseSwitches(search) {
|
|
|
119
124
|
derivedCache: params.get('derived-cache') !== 'off',
|
|
120
125
|
fps: positive(params.get('fps')),
|
|
121
126
|
targetFps: params.get('target-fps') === 'display' ? 'display' : whole(params.get('target-fps')),
|
|
127
|
+
presetCheck: oneOf(params.get('preset-check'), PRESET_CHECK_TIMINGS),
|
|
122
128
|
jobs: whole(params.get('jobs'), MAX_JOB_WORKERS),
|
|
123
129
|
queue: params.get('queue') === 'off' ? Number.POSITIVE_INFINITY : whole(params.get('queue')),
|
|
124
130
|
memoryMiB: within(whole(params.get('memory')), MEMORY_MIB.min, MEMORY_MIB.max),
|
|
125
131
|
preset: oneOf(params.get('preset'), QUALITY_PRESETS),
|
|
132
|
+
lowestTier: oneOf(params.get('tier'), LOWEST_TIERS),
|
|
126
133
|
hold: params.get('hold') ?? undefined,
|
|
127
134
|
replay: params.get('replay') ?? undefined,
|
|
128
135
|
record: params.has('record'),
|
|
129
136
|
still: params.get('still-camera') !== 'off',
|
|
130
137
|
bench: params.has('bench'),
|
|
138
|
+
inspect: params.has('inspect'),
|
|
131
139
|
view: params.get('view') || undefined,
|
|
132
140
|
stats: statsSwitch(params.get('stats')),
|
|
133
141
|
permutations: params.get('permutations') === 'record' ? 'record' : undefined,
|
package/lib/quality/check.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ import type { QualityPreset } from './presets.js';
|
|
|
7
7
|
export declare const CHECK_MAX_FPS = 60;
|
|
8
8
|
/** A preset holds its target when the measured rate reaches this share of it. */
|
|
9
9
|
export declare const CHECK_HOLD_SHARE = 0.9;
|
|
10
|
+
/**
|
|
11
|
+
* A preset is far below its target when the measured rate stays under this share of it. The
|
|
12
|
+
* check then lowers it straight to Low, and the presets between could not close such a gap.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CHECK_FAR_SHARE = 0.25;
|
|
10
15
|
/**
|
|
11
16
|
* How long the check draws before it measures, in ms: after the first frame, and after each lower
|
|
12
17
|
* preset's first frame. The first frames after a warm-up can run slower than play, and a new
|
|
@@ -63,10 +68,23 @@ export interface PresetCheck {
|
|
|
63
68
|
rounds: PresetCheckRound[];
|
|
64
69
|
/**
|
|
65
70
|
* True when the engine took this result from an earlier start of the sketch in this browser on
|
|
66
|
-
* this device, and did not measure again. The engine stores each check's result for a week.
|
|
71
|
+
* this device, and did not measure again. The engine stores each check's result for a week. A
|
|
72
|
+
* check that went on from the rounds of an earlier start, whose check never ended, is false, and
|
|
73
|
+
* lists those rounds first.
|
|
67
74
|
*/
|
|
68
75
|
reused: boolean;
|
|
69
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* When the preset check measures, as `createEngine`'s `presetCheck` option and the
|
|
79
|
+
* `?preset-check=` switch name it. With `during-play`, the default, the scene plays from its first
|
|
80
|
+
* frame, and the check measures the first frames of play. With `before-play`, the check measures
|
|
81
|
+
* before the sketch's update runs, and the start waits for it.
|
|
82
|
+
*
|
|
83
|
+
* @category api/engine
|
|
84
|
+
*/
|
|
85
|
+
export type PresetCheckTiming = 'during-play' | 'before-play';
|
|
86
|
+
/** The values of `PresetCheckTiming`, for the option's and the switch's checks. */
|
|
87
|
+
export declare const PRESET_CHECK_TIMINGS: readonly PresetCheckTiming[];
|
|
70
88
|
/**
|
|
71
89
|
* The frame rate that the engine defends, as `createEngine`'s `targetFps` option and the
|
|
72
90
|
* `?target-fps=` switch name it: `display` for the display's full refresh rate, or a whole number
|
|
@@ -88,11 +106,14 @@ export declare function checkTargetFps(refreshHz: number, highest?: number): num
|
|
|
88
106
|
/**
|
|
89
107
|
* The target after a round: the higher of the target so far and the one from the refresh rate that
|
|
90
108
|
* the meter reads now. A GPU that falls behind can slow the meter, which then reads low, so the
|
|
91
|
-
* target never falls during a check
|
|
92
|
-
* the check
|
|
109
|
+
* target never falls during a check, and it starts at the rate that the meter read before the
|
|
110
|
+
* check's first frame. Each round that the check lowered then missed the target that the check
|
|
111
|
+
* reports.
|
|
93
112
|
*/
|
|
94
113
|
export declare function raiseTarget(targetFps: number, refreshHz: number, highest?: number): number;
|
|
95
114
|
/** A rate from a count of frames and the time they covered, in ms; 0 when they covered none. */
|
|
96
115
|
export declare function frameRate(frames: number, ms: number): number;
|
|
97
116
|
/** True when the lower of a round's two rates reaches the share of the target that holds it. */
|
|
98
117
|
export declare function holdsTarget(round: PresetCheckRound, targetFps: number): boolean;
|
|
118
|
+
/** True when the lower of a round's two rates stays under the share of the target that is far below it. */
|
|
119
|
+
export declare function farBelowTarget(round: PresetCheckRound, targetFps: number): boolean;
|
package/lib/quality/check.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// The preset check's rules, apart from the code that runs it (sketch/preset-check.ts). When the
|
|
2
2
|
// engine chooses the preset itself, the device hints only suggest it, so after the first frame the
|
|
3
|
-
// engine
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// engine measures the frame rate for a moment: of play, or of the scene that the setup built
|
|
4
|
+
// before play starts, as the page's choice of timing says. It reads the lower of the presented and
|
|
5
|
+
// completed rates, so frames that queue on the GPU cannot pass for a healthy rate. A preset holds
|
|
6
|
+
// when that rate reaches most of the target. Otherwise the engine lowers the preset by one and
|
|
7
|
+
// measures again, down to Low. A preset far below the target goes straight to Low. These
|
|
8
|
+
// functions are pure, so tests call them with any rates, and the docs generator reads the
|
|
9
|
+
// constants.
|
|
8
10
|
/**
|
|
9
11
|
* The highest frame rate that the check asks a preset to hold, unless the page asks for more. A
|
|
10
12
|
* display that refreshes faster still gets this target, as a preset that holds it plays smoothly
|
|
@@ -13,6 +15,11 @@
|
|
|
13
15
|
export const CHECK_MAX_FPS = 60;
|
|
14
16
|
/** A preset holds its target when the measured rate reaches this share of it. */
|
|
15
17
|
export const CHECK_HOLD_SHARE = 0.9;
|
|
18
|
+
/**
|
|
19
|
+
* A preset is far below its target when the measured rate stays under this share of it. The
|
|
20
|
+
* check then lowers it straight to Low, and the presets between could not close such a gap.
|
|
21
|
+
*/
|
|
22
|
+
export const CHECK_FAR_SHARE = 0.25;
|
|
16
23
|
/**
|
|
17
24
|
* How long the check draws before it measures, in ms: after the first frame, and after each lower
|
|
18
25
|
* preset's first frame. The first frames after a warm-up can run slower than play, and a new
|
|
@@ -36,6 +43,8 @@ export const CHECK_SETTLE_INTERVAL_MS = 100;
|
|
|
36
43
|
export const CHECK_SETTLE_FRAMES = 2;
|
|
37
44
|
/** The longest time in ms that the check waits after a lowering for the new preset to settle. */
|
|
38
45
|
export const CHECK_SETTLE_WAIT_MS = 4000;
|
|
46
|
+
/** The values of `PresetCheckTiming`, for the option's and the switch's checks. */
|
|
47
|
+
export const PRESET_CHECK_TIMINGS = ['during-play', 'before-play'];
|
|
39
48
|
/**
|
|
40
49
|
* The highest target that a `targetFps` setting and a frame rate cap such as `?fps=` allow:
|
|
41
50
|
* `CHECK_MAX_FPS` without a setting, and infinity for `display` without a cap.
|
|
@@ -54,8 +63,9 @@ export function checkTargetFps(refreshHz, highest = CHECK_MAX_FPS) {
|
|
|
54
63
|
/**
|
|
55
64
|
* The target after a round: the higher of the target so far and the one from the refresh rate that
|
|
56
65
|
* the meter reads now. A GPU that falls behind can slow the meter, which then reads low, so the
|
|
57
|
-
* target never falls during a check
|
|
58
|
-
* the check
|
|
66
|
+
* target never falls during a check, and it starts at the rate that the meter read before the
|
|
67
|
+
* check's first frame. Each round that the check lowered then missed the target that the check
|
|
68
|
+
* reports.
|
|
59
69
|
*/
|
|
60
70
|
export function raiseTarget(targetFps, refreshHz, highest = CHECK_MAX_FPS) {
|
|
61
71
|
return Math.max(targetFps, checkTargetFps(refreshHz, highest));
|
|
@@ -68,3 +78,7 @@ export function frameRate(frames, ms) {
|
|
|
68
78
|
export function holdsTarget(round, targetFps) {
|
|
69
79
|
return Math.min(round.presentedFps, round.completedFps) >= targetFps * CHECK_HOLD_SHARE;
|
|
70
80
|
}
|
|
81
|
+
/** True when the lower of a round's two rates stays under the share of the target that is far below it. */
|
|
82
|
+
export function farBelowTarget(round, targetFps) {
|
|
83
|
+
return Math.min(round.presentedFps, round.completedFps) < targetFps * CHECK_FAR_SHARE;
|
|
84
|
+
}
|
package/lib/quality/chooser.d.ts
CHANGED
|
@@ -85,6 +85,12 @@ export declare function memoryPreset(request: PresetRequest): QualityPreset;
|
|
|
85
85
|
* lowered after crashed starts.
|
|
86
86
|
*/
|
|
87
87
|
export declare function choosePreset(request: PresetRequest, tier: Tier): QualityPreset;
|
|
88
|
+
/**
|
|
89
|
+
* True when a start has crashed the tab twice, so it begins in the lowest quality tier: Low's half
|
|
90
|
+
* of the render scale still missed on that device. A page that names a preset starts outside the
|
|
91
|
+
* tier, as it starts outside the preset choice.
|
|
92
|
+
*/
|
|
93
|
+
export declare function crashLowest(crashedStarts: number): boolean;
|
|
88
94
|
/**
|
|
89
95
|
* The GPU path to start on after crashed starts, when the page leaves the path to the engine:
|
|
90
96
|
* WebGL2 after two, when the last one ran on WebGPU. Undefined leaves the choice to the engine.
|
package/lib/quality/chooser.js
CHANGED
|
@@ -91,6 +91,14 @@ export function memoryPreset(request) {
|
|
|
91
91
|
export function choosePreset(request, tier) {
|
|
92
92
|
return afterCrashes(withinTier(wantedPreset(request), tier), request.crashedStarts);
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* True when a start has crashed the tab twice, so it begins in the lowest quality tier: Low's half
|
|
96
|
+
* of the render scale still missed on that device. A page that names a preset starts outside the
|
|
97
|
+
* tier, as it starts outside the preset choice.
|
|
98
|
+
*/
|
|
99
|
+
export function crashLowest(crashedStarts) {
|
|
100
|
+
return crashedStarts >= 2;
|
|
101
|
+
}
|
|
94
102
|
/**
|
|
95
103
|
* The GPU path to start on after crashed starts, when the page leaves the path to the engine:
|
|
96
104
|
* WebGL2 after two, when the last one ran on WebGPU. Undefined leaves the choice to the engine.
|