@null3d/engine 0.0.0 → 0.1.1
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 +25 -10
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +25 -10
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/animation.md +114 -86
- package/docs/api/assets.md +135 -49
- package/docs/api/cameras.md +45 -12
- package/docs/api/controls.md +88 -62
- package/docs/api/debug.md +116 -41
- package/docs/api/engine.md +117 -35
- package/docs/api/feature-draws.md +23 -17
- package/docs/api/feature-effects.md +11 -11
- package/docs/api/feature-instances.md +70 -19
- package/docs/api/features.md +77 -47
- package/docs/api/geometry.md +132 -82
- package/docs/api/grass.md +55 -13
- package/docs/api/impostors.md +175 -22
- package/docs/api/input.md +24 -18
- package/docs/api/lights.md +78 -51
- package/docs/api/lines.md +41 -33
- package/docs/api/materials.md +248 -121
- package/docs/api/math.md +12 -13
- package/docs/api/objects.md +47 -22
- package/docs/api/page.md +58 -7
- package/docs/api/particles.md +33 -20
- package/docs/api/points.md +19 -31
- package/docs/api/post.md +75 -42
- package/docs/api/quality.md +42 -17
- package/docs/api/raycast.md +65 -51
- package/docs/api/reference/animation.md +10 -11
- package/docs/api/reference/assets.md +25 -22
- package/docs/api/reference/cameras.md +8 -4
- package/docs/api/reference/controls.md +134 -25
- package/docs/api/reference/debug.md +81 -14
- package/docs/api/reference/engine.md +58 -17
- package/docs/api/reference/feature-draws.md +3 -4
- package/docs/api/reference/feature-effects.md +2 -3
- package/docs/api/reference/feature-instances.md +5 -4
- package/docs/api/reference/features.md +7 -4
- package/docs/api/reference/geometry.md +287 -97
- package/docs/api/reference/grass.md +63 -3
- package/docs/api/reference/impostors.md +208 -13
- package/docs/api/reference/input.md +4 -5
- package/docs/api/reference/lights.md +13 -12
- package/docs/api/reference/lines.md +10 -11
- package/docs/api/reference/materials.md +54 -53
- package/docs/api/reference/math.md +35 -24
- package/docs/api/reference/objects.md +11 -12
- package/docs/api/reference/particles.md +31 -6
- package/docs/api/reference/points.md +6 -7
- package/docs/api/reference/post.md +21 -20
- package/docs/api/reference/quality.md +8 -5
- package/docs/api/reference/raycast.md +7 -8
- package/docs/api/reference/render.md +5 -4
- package/docs/api/reference/scene.md +52 -30
- package/docs/api/reference/sketch.md +15 -11
- package/docs/api/reference/sound.md +234 -0
- package/docs/api/reference/splats.md +42 -3
- package/docs/api/reference/sprites.md +7 -8
- package/docs/api/reference/tasks.md +16 -3
- package/docs/api/reference/terrain.md +27 -5
- package/docs/api/reference/textures.md +5 -6
- package/docs/api/reference/three-compat.md +18 -7
- package/docs/api/reference/time.md +1 -2
- package/docs/api/reference/ui.md +12 -9
- package/docs/api/reference/vertex-draws.md +5 -6
- package/docs/api/reference/water.md +153 -9
- package/docs/api/reference/wind.md +17 -4
- package/docs/api/render.md +73 -29
- package/docs/api/scene.md +164 -60
- package/docs/api/sketch.md +102 -15
- package/docs/api/sound.md +205 -0
- package/docs/api/splats.md +46 -12
- package/docs/api/sprites.md +10 -24
- package/docs/api/tasks.md +33 -24
- package/docs/api/terrain.md +42 -22
- package/docs/api/textures.md +68 -19
- package/docs/api/three-compat.md +15 -7
- package/docs/api/time.md +3 -5
- package/docs/api/ui.md +19 -23
- package/docs/api/vertex-draws.md +13 -12
- package/docs/api/water.md +262 -35
- package/docs/api/wind.md +63 -17
- package/docs/cli/null3d.md +177 -27
- package/docs/concepts/architecture.md +73 -27
- package/docs/concepts/assets.md +57 -33
- package/docs/concepts/backends.md +69 -27
- package/docs/concepts/color-management.md +54 -36
- package/docs/concepts/culling.md +68 -47
- package/docs/concepts/handles.md +14 -5
- package/docs/concepts/instances.md +74 -25
- package/docs/concepts/large-worlds.md +18 -8
- package/docs/concepts/lighting.md +155 -87
- package/docs/concepts/lod.md +126 -44
- package/docs/concepts/materials.md +58 -27
- package/docs/concepts/particle-buffer.md +48 -35
- package/docs/concepts/post-processing.md +84 -43
- package/docs/concepts/quality-preset-tables.md +56 -52
- package/docs/concepts/quality-presets.md +164 -52
- package/docs/concepts/render-graph.md +69 -29
- package/docs/concepts/render-layers.md +11 -21
- package/docs/concepts/shadows.md +105 -52
- package/docs/concepts/static-dynamic.md +22 -7
- package/docs/cookbook/index.md +164 -120
- package/docs/data/threejs-mapping.json +362 -367
- package/docs/errors/E1101.md +23 -5
- package/docs/errors/E1102.md +11 -3
- package/docs/errors/E1103.md +11 -3
- package/docs/errors/E1104.md +11 -3
- package/docs/errors/E1105.md +13 -5
- package/docs/errors/E1106.md +11 -3
- package/docs/errors/E1107.md +15 -5
- package/docs/errors/E1108.md +11 -3
- package/docs/errors/E1109.md +32 -6
- package/docs/errors/E1110.md +23 -5
- package/docs/errors/E1111.md +11 -3
- package/docs/errors/E1112.md +11 -3
- package/docs/errors/E1203.md +12 -4
- package/docs/errors/E1204.md +11 -3
- package/docs/errors/E1205.md +11 -3
- package/docs/errors/E1206.md +28 -6
- package/docs/errors/E1207.md +11 -3
- package/docs/errors/E1208.md +12 -3
- package/docs/errors/E1209.md +11 -3
- package/docs/errors/E1213.md +27 -5
- package/docs/errors/E1214.md +14 -6
- package/docs/errors/E1215.md +31 -6
- package/docs/errors/E1216.md +31 -6
- package/docs/errors/E1217.md +29 -6
- package/docs/errors/E1218.md +22 -6
- package/docs/errors/E1219.md +11 -3
- package/docs/errors/E1220.md +24 -5
- package/docs/errors/E1221.md +24 -5
- package/docs/errors/E1222.md +11 -3
- package/docs/errors/E1223.md +39 -6
- package/docs/errors/E1224.md +11 -3
- package/docs/errors/E1225.md +11 -3
- package/docs/errors/E1301.md +11 -3
- package/docs/errors/E1302.md +11 -3
- package/docs/errors/E1303.md +11 -3
- package/docs/errors/E1304.md +11 -3
- package/docs/errors/E1305.md +13 -3
- package/docs/errors/E1306.md +11 -3
- package/docs/errors/E1307.md +40 -0
- package/docs/errors/E1401.md +11 -3
- package/docs/errors/E1402.md +13 -5
- package/docs/errors/E1403.md +11 -3
- package/docs/errors/E1404.md +13 -3
- package/docs/errors/E1405.md +15 -4
- package/docs/errors/E1406.md +31 -5
- package/docs/errors/E1407.md +11 -3
- package/docs/errors/E1408.md +11 -3
- package/docs/errors/E1409.md +11 -3
- package/docs/errors/E1410.md +13 -5
- package/docs/errors/E1411.md +11 -3
- package/docs/errors/E1412.md +29 -6
- package/docs/errors/E1413.md +11 -3
- package/docs/errors/E1414.md +11 -3
- package/docs/errors/E1415.md +11 -3
- package/docs/errors/E1416.md +27 -6
- package/docs/errors/E1417.md +11 -3
- package/docs/errors/E1418.md +12 -3
- package/docs/errors/E1419.md +13 -5
- package/docs/errors/E1420.md +14 -6
- package/docs/errors/E1421.md +11 -3
- package/docs/errors/E1422.md +12 -3
- package/docs/errors/E1423.md +12 -3
- package/docs/errors/E1424.md +24 -5
- package/docs/errors/E1425.md +11 -3
- package/docs/errors/E1426.md +11 -3
- package/docs/errors/E1430.md +11 -3
- package/docs/errors/E1431.md +11 -3
- package/docs/errors/E1432.md +11 -3
- package/docs/errors/E1433.md +11 -3
- package/docs/errors/E1434.md +15 -6
- package/docs/errors/E1435.md +11 -3
- package/docs/errors/E1436.md +11 -3
- package/docs/errors/E1437.md +14 -6
- package/docs/errors/E1501.md +41 -6
- package/docs/errors/E1502.md +13 -3
- package/docs/errors/E1503.md +11 -3
- package/docs/errors/E1504.md +11 -3
- package/docs/errors/E1505.md +23 -5
- package/docs/errors/E1506.md +11 -3
- package/docs/errors/index.md +54 -30
- package/docs/getting-started/cdn.md +32 -10
- package/docs/getting-started/first-scene.md +21 -13
- package/docs/getting-started/hosting.md +152 -63
- package/docs/getting-started/install.md +44 -28
- package/docs/getting-started/network-use.md +33 -15
- package/docs/getting-started/project-structure.md +33 -12
- package/docs/getting-started/third-party-notices.md +12 -14
- package/docs/guides/accessibility.md +5 -5
- package/docs/guides/add-ons.md +86 -15
- package/docs/guides/agents.md +16 -9
- package/docs/guides/assets-pipeline.md +259 -82
- package/docs/guides/audio.md +115 -128
- package/docs/guides/baked-light-data.md +44 -23
- package/docs/guides/car-paint.md +38 -32
- package/docs/guides/content-pages.md +63 -35
- package/docs/guides/custom-passes.md +65 -22
- package/docs/guides/custom-shaders.md +59 -39
- package/docs/guides/debugging.md +74 -10
- package/docs/guides/deploying.md +85 -6
- package/docs/guides/deterministic-simulation.md +24 -17
- package/docs/guides/first-use-shaders.md +83 -45
- package/docs/guides/lens-kit.md +29 -26
- package/docs/guides/loading-screens.md +132 -47
- package/docs/guides/multiple-views.md +63 -13
- package/docs/guides/performance.md +192 -38
- package/docs/guides/phones.md +78 -15
- package/docs/guides/physics.md +7 -11
- package/docs/guides/screens.md +47 -33
- package/docs/guides/start-time.md +363 -0
- package/docs/guides/testing.md +152 -95
- package/docs/guides/ui-overlays.md +19 -14
- package/docs/guides/video-textures.md +14 -13
- package/docs/images/api/animation/character.webp +0 -0
- package/docs/images/api/animation/look-at-ring.webp +0 -0
- package/docs/images/api/animation/morph-tulips.webp +0 -0
- package/docs/images/api/animation/skeleton-lines.webp +0 -0
- package/docs/images/api/controls/gizmo-handles.webp +0 -0
- package/docs/images/api/controls/walk-and-fly.webp +0 -0
- package/docs/images/api/debug/debug-shapes.webp +0 -0
- package/docs/images/api/debug/levels-view.webp +0 -0
- package/docs/images/api/engine/transparent-canvas.webp +0 -0
- package/docs/images/api/feature-draws/feature-draw-clouds.webp +0 -0
- package/docs/images/api/feature-instances/compute-instances.webp +0 -0
- package/docs/images/api/feature-instances/instances-shadow.webp +0 -0
- package/docs/images/api/geometry/extra-shapes.webp +0 -0
- package/docs/images/api/geometry/generators.webp +0 -0
- package/docs/images/api/geometry/mesh-arrays.webp +0 -0
- package/docs/images/api/geometry/vertex-updates.webp +0 -0
- package/docs/images/api/grass/grass-grove.webp +0 -0
- package/docs/images/api/grass/grass-presets.webp +0 -0
- package/docs/images/api/grass/grass-shadow.webp +0 -0
- package/docs/images/api/impostors/impostor-handover.webp +0 -0
- package/docs/images/api/impostors/impostor-shadow.webp +0 -0
- package/docs/images/api/impostors/impostors-forest.webp +0 -0
- package/docs/images/api/lights/spot-cookies.webp +0 -0
- package/docs/images/api/lines/lines-lit.webp +0 -0
- package/docs/images/api/lines/lines-widths.webp +0 -0
- package/docs/images/api/materials/coat-and-sheen.webp +0 -0
- package/docs/images/api/materials/decals.webp +0 -0
- package/docs/images/api/materials/iridescence-and-anisotropy.webp +0 -0
- package/docs/images/api/materials/relief.webp +0 -0
- package/docs/images/api/materials/shader-inputs.webp +0 -0
- package/docs/images/api/materials/standard-grid.webp +0 -0
- package/docs/images/api/materials/subsurface.webp +0 -0
- package/docs/images/api/materials/translucency.webp +0 -0
- package/docs/images/api/objects/objects-turntable.webp +0 -0
- package/docs/images/api/particles/campfire.webp +0 -0
- package/docs/images/api/points/galaxy.webp +0 -0
- package/docs/images/api/reference/textures/texture-wrap.webp +0 -0
- package/docs/images/api/render/fullscreen-glow.webp +0 -0
- package/docs/images/api/render/reflection-mirror.webp +0 -0
- package/docs/images/api/render/security-camera.webp +0 -0
- package/docs/images/api/scene/aurora-sky-layer.webp +0 -0
- package/docs/images/api/sound/sound-demo.webp +0 -0
- package/docs/images/api/splats/splats-demo.webp +0 -0
- package/docs/images/api/sprites/sprites-lines.webp +0 -0
- package/docs/images/api/terrain/terrain-demo.webp +0 -0
- package/docs/images/api/textures/canvas-screen.webp +0 -0
- package/docs/images/api/textures/mipmaps.webp +0 -0
- package/docs/images/api/vertex-draws/rain.webp +0 -0
- package/docs/images/api/water/ocean.webp +0 -0
- package/docs/images/api/water/water-demo.webp +0 -0
- package/docs/images/api/water/water-rain.webp +0 -0
- package/docs/images/api/water/waterfall.webp +0 -0
- package/docs/images/concepts/assets/gltf-model.webp +0 -0
- package/docs/images/concepts/color-management/tone-mapped.webp +0 -0
- package/docs/images/concepts/culling/far-from-origin.webp +0 -0
- package/docs/images/concepts/instances/instances.webp +0 -0
- package/docs/images/concepts/instances/per-row-colors.webp +0 -0
- package/docs/images/concepts/large-worlds/large-world.webp +0 -0
- package/docs/images/concepts/lighting/area-lights.webp +0 -0
- package/docs/images/concepts/lighting/atmosphere.webp +0 -0
- package/docs/images/concepts/lighting/environment.webp +0 -0
- package/docs/images/concepts/lighting/light-shafts.webp +0 -0
- package/docs/images/concepts/lighting/reflection-probes.webp +0 -0
- package/docs/images/concepts/lod/forest.webp +0 -0
- package/docs/images/concepts/materials/weighted-transparency.webp +0 -0
- package/docs/images/concepts/post-processing/auto-exposure.webp +0 -0
- package/docs/images/concepts/post-processing/bounce-light.webp +0 -0
- package/docs/images/concepts/post-processing/depth-of-field.webp +0 -0
- package/docs/images/concepts/post-processing/post-effects-alley.webp +0 -0
- package/docs/images/concepts/post-processing/sharpen.webp +0 -0
- package/docs/images/concepts/post-processing/ssr-wet-street.webp +0 -0
- package/docs/images/concepts/render-layers/layers-cottages.webp +0 -0
- package/docs/images/concepts/shadows/hero-shadow.webp +0 -0
- package/docs/images/cookbook/index/picking.webp +0 -0
- package/docs/images/cookbook/index/time-of-day.webp +0 -0
- package/docs/images/errors/E1431/area-lights-no-tables.webp +0 -0
- package/docs/images/guides/custom-passes/reflection-water.webp +0 -0
- package/docs/images/guides/deterministic-simulation/replay-demo.webp +0 -0
- package/docs/images/guides/multiple-views/split-screen.webp +0 -0
- package/docs/images/guides/performance/overdraw-view.webp +0 -0
- package/docs/images/guides/testing/hold-mode-frame.webp +0 -0
- package/docs/images/index/showcase-island.webp +0 -0
- package/docs/images/porting/threejs-shaders/dissolve.webp +0 -0
- package/docs/images/shaders/builtins/builtins.webp +0 -0
- package/docs/images/shaders/surface-functions/custom-surface.webp +0 -0
- package/docs/images/shaders/surface-functions/vertex-offset.webp +0 -0
- package/docs/images/shots.json +2231 -0
- package/docs/index.md +18 -23
- package/docs/moves.json +1 -0
- package/docs/nav.json +300 -0
- package/docs/pages.md +230 -209
- package/docs/porting/react-three-fiber.md +225 -6
- package/docs/porting/threejs-loop-and-threads.md +217 -7
- package/docs/porting/threejs-mapping.md +1249 -233
- package/docs/porting/threejs-materials.md +218 -6
- package/docs/porting/threejs-overview.md +240 -7
- package/docs/porting/threejs-postprocessing.md +4 -8
- package/docs/porting/threejs-shaders.md +301 -6
- package/docs/porting/threejs-unsupported.md +83 -7
- package/docs/porting/verification.md +178 -6
- package/docs/shaders/builtins.md +15 -4
- package/docs/shaders/library.md +72 -45
- package/docs/shaders/surface-functions.md +59 -23
- package/docs/shaders/wgsl-rules.md +12 -5
- package/lib/debug/channel.d.ts +103 -0
- package/lib/debug/channel.js +269 -0
- package/lib/debug/debug.d.ts +11 -9
- package/lib/debug/draw.d.ts +11 -2
- package/lib/debug/draw.js +57 -6
- package/lib/debug/inspector.d.ts +60 -0
- package/lib/debug/inspector.js +475 -0
- package/lib/debug/overlay-look.d.ts +6 -0
- package/lib/debug/overlay-look.js +29 -7
- package/lib/debug/overlay.js +15 -11
- package/lib/debug/stats-options.d.ts +13 -0
- package/lib/debug/stats-panel.d.ts +22 -7
- package/lib/debug/stats-panel.js +80 -13
- package/lib/debug/stats.d.ts +2 -3
- package/lib/errors/codes.d.ts +17 -3
- package/lib/errors/codes.js +117 -105
- package/lib/errors/engine-error.js +25 -10
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +20 -19
- 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/variants.d.ts +8 -2
- package/lib/gpu/variants.js +39 -7
- 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 +5 -2
- 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 +28 -14
- package/lib/index.d.ts +7 -5
- 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 +8 -8
- 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 +117 -31
- package/lib/page/engine.js +438 -99
- 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 +26 -14
- 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/stats-switch.js +2 -0
- package/lib/page/switches.d.ts +38 -6
- package/lib/page/switches.js +29 -5
- 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/baked-light.d.ts +2 -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 +3 -3
- package/lib/scene/fog.d.ts +11 -4
- package/lib/scene/fog.js +8 -2
- package/lib/scene/frame-cameras.d.ts +35 -4
- package/lib/scene/frame-cameras.js +86 -10
- package/lib/scene/gltf.d.ts +33 -3
- 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 +121 -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/particles.d.ts +7 -3
- package/lib/scene/particles.js +3 -1
- package/lib/scene/picks.d.ts +2 -2
- package/lib/scene/pointer-events.d.ts +4 -7
- package/lib/scene/post.d.ts +39 -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 +238 -261
- package/lib/scene/resources.js +179 -81
- package/lib/scene/scene.d.ts +167 -120
- package/lib/scene/scene.js +243 -103
- 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 +11 -7
- package/lib/scene/time-of-day.js +11 -8
- 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/labels.d.ts +5 -2
- package/lib/shared/labels.js +5 -2
- package/lib/shared/metrics.d.ts +38 -0
- package/lib/shared/metrics.js +62 -1
- package/lib/shared/permutation-words.d.ts +2 -0
- package/lib/shared/permutation-words.js +8 -0
- package/lib/shared/recording.d.ts +13 -5
- package/lib/shared/recording.js +31 -10
- package/lib/shared/run-task.js +7 -1
- package/lib/shared/sketch-data.d.ts +9 -0
- package/lib/shared/sketch-data.js +57 -0
- 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 +51 -7
- package/lib/sketch/define-sketch.js +2 -1
- 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 +80 -9
- package/lib/sketch/runner.js +390 -52
- package/lib/sketch/ui.d.ts +5 -8
- package/lib/sketch/ui.js +4 -2
- package/lib/stats.d.ts +1 -0
- package/lib/workers/probe-worker.d.ts +5 -0
- package/lib/workers/probe-worker.js +13 -4
- package/lib/workers/protocol.d.ts +71 -13
- package/lib/workers/protocol.js +4 -0
- package/lib/workers/render-worker.js +29 -5
- package/lib/workers/sketch-worker.js +108 -16
- package/package.json +2 -2
package/lib/render/recovery.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// new renderer on the same canvas, tells the sketch thread to record a frame that creates every GPU
|
|
3
3
|
// object again, and starts a new loop. After too many losses in a short time, or when no new device
|
|
4
4
|
// starts, it stops and reports the loss. Hold mode draws one frame on one device, so there a loss
|
|
5
|
-
// is reported at once.
|
|
5
|
+
// is reported at once. A page that the browser keeps in its back/forward cache gives its GPU back
|
|
6
|
+
// the same way, and takes a new one when it shows again, without counting a loss.
|
|
6
7
|
import { messageOf } from '../errors/message.js';
|
|
7
8
|
import { releaseCanvas } from '../gpu/canvas-release.js';
|
|
8
9
|
import { Slot } from '../shared/control.js';
|
|
@@ -26,6 +27,8 @@ export class Drawing {
|
|
|
26
27
|
live;
|
|
27
28
|
/** The recovery under way, which a stop waits for. */
|
|
28
29
|
recovering;
|
|
30
|
+
/** True while the page sits in the back/forward cache, with no renderer. */
|
|
31
|
+
released = false;
|
|
29
32
|
/**
|
|
30
33
|
* Starts drawing with `renderer`. `create` makes a replacement on the same canvas, `run` starts a
|
|
31
34
|
* loop with a renderer, and `fail` hears the reason when the engine gives up. Without
|
|
@@ -75,20 +78,29 @@ export class Drawing {
|
|
|
75
78
|
this.fail(`${reason}, and the GPU was lost ${this.losses.length} times within a minute`);
|
|
76
79
|
return;
|
|
77
80
|
}
|
|
81
|
+
if (await this.restart(reason))
|
|
82
|
+
console.warn(`null3D: the browser took the GPU away (${reason}); the engine started a new device.`);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Makes a new renderer on the canvas, tells the sketch thread to create every GPU object again,
|
|
86
|
+
* and starts a new loop. Returns false when the engine stopped meanwhile, or when no device
|
|
87
|
+
* started, which `reason` explains to the page.
|
|
88
|
+
*/
|
|
89
|
+
async restart(reason) {
|
|
78
90
|
try {
|
|
79
91
|
this.renderer = await this.create();
|
|
80
92
|
}
|
|
81
93
|
catch (error) {
|
|
82
94
|
this.fail(`${reason}, and no new GPU device started: ${messageOf(error)}`);
|
|
83
|
-
return;
|
|
95
|
+
return false;
|
|
84
96
|
}
|
|
85
97
|
this.live = this.renderer;
|
|
86
98
|
if (this.stopped)
|
|
87
|
-
return;
|
|
99
|
+
return false;
|
|
88
100
|
Atomics.add(this.slots, Slot.GpuEpoch, 1);
|
|
89
101
|
this.loop = this.run(this.renderer);
|
|
90
102
|
this.watch();
|
|
91
|
-
|
|
103
|
+
return true;
|
|
92
104
|
}
|
|
93
105
|
/**
|
|
94
106
|
* Resolves once the frame to capture is on the canvas. In hold mode, that is the held frame,
|
|
@@ -97,6 +109,34 @@ export class Drawing {
|
|
|
97
109
|
async nextFrame() {
|
|
98
110
|
await (this.loop.drawHeld?.() ?? nextFrameTaken(this.slots));
|
|
99
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Gives the GPU back while the page sits in the browser's back/forward cache: stops the loop and
|
|
114
|
+
* destroys the renderer, with its textures, buffers and device. A small device then has the
|
|
115
|
+
* room for the next page. Hold mode, and a drawing that recovers from a loss or has stopped, keep
|
|
116
|
+
* what they have.
|
|
117
|
+
*/
|
|
118
|
+
enterPageCache() {
|
|
119
|
+
if (!this.recovers || this.stopped || this.released || this.recovering)
|
|
120
|
+
return;
|
|
121
|
+
this.released = true;
|
|
122
|
+
this.loop.stop();
|
|
123
|
+
this.live = undefined;
|
|
124
|
+
this.renderer.destroy();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Takes a new renderer once the page shows again after `enterPageCache`, as a recovery from a GPU loss
|
|
128
|
+
* does: the sketch thread records a frame that creates every GPU object again. It counts no loss.
|
|
129
|
+
*/
|
|
130
|
+
leavePageCache() {
|
|
131
|
+
if (!this.released || this.stopped)
|
|
132
|
+
return Promise.resolve();
|
|
133
|
+
this.released = false;
|
|
134
|
+
this.recovering = this.restart('the page came back from the back/forward cache').then(() => undefined);
|
|
135
|
+
void this.recovering.finally(() => {
|
|
136
|
+
this.recovering = undefined;
|
|
137
|
+
});
|
|
138
|
+
return this.recovering;
|
|
139
|
+
}
|
|
100
140
|
/** Acts out a loss of the GPU, which the engine then recovers from as from a real one. */
|
|
101
141
|
simulateLoss() {
|
|
102
142
|
this.renderer.simulateLoss();
|
package/lib/render/renderer.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { PowerPreference } from '../page/capabilities.js';
|
|
|
4
4
|
import { type CoreDevice } from '../page/limits.js';
|
|
5
5
|
import type { GlTimingMode } from '../page/switches.js';
|
|
6
6
|
import type { ImageTable } from '../shared/images.js';
|
|
7
|
-
import type
|
|
7
|
+
import { DrawingSteps, type FrameRecorder } from '../shared/metrics.js';
|
|
8
8
|
import type { Tier } from '../shared/tier.js';
|
|
9
9
|
import { type GpuErrorReport } from './loss.js';
|
|
10
10
|
export type { Tier } from '../shared/tier.js';
|
|
@@ -89,9 +89,10 @@ export interface RendererOptions {
|
|
|
89
89
|
*/
|
|
90
90
|
gpuSamples?: 'every';
|
|
91
91
|
/**
|
|
92
|
-
* Hears a
|
|
93
|
-
* an object
|
|
94
|
-
*
|
|
92
|
+
* Hears a GPU failure that the engine draws on after: a WebGPU error that no error scope caught,
|
|
93
|
+
* as the GPU had no room for an object or rejected a command, or a pipeline of the scene's
|
|
94
|
+
* objects that the GPU's driver refused twice, on either GPU path. `message` is the GPU path's
|
|
95
|
+
* own text. The thread that draws reports each kind once per device, as E1304, E1305 or E1307.
|
|
95
96
|
*/
|
|
96
97
|
gpuError?: GpuErrorReport;
|
|
97
98
|
/**
|
|
@@ -99,18 +100,93 @@ export interface RendererOptions {
|
|
|
99
100
|
* `createEngine`'s `preload` lists them.
|
|
100
101
|
*/
|
|
101
102
|
preload?: readonly string[];
|
|
103
|
+
/**
|
|
104
|
+
* What the thread started before its first renderer: the times of its start's steps, and on
|
|
105
|
+
* WebGPU the device that it asked for, which the first renderer takes.
|
|
106
|
+
*/
|
|
107
|
+
early?: EarlyStart;
|
|
108
|
+
/**
|
|
109
|
+
* The pipeline list of the pipelines that the first frame of the sketch's last start built,
|
|
110
|
+
* which a scene's renderer starts to build at once (`gpu/early-builds.ts`).
|
|
111
|
+
*/
|
|
112
|
+
earlyBuilds?: Uint32Array;
|
|
113
|
+
/**
|
|
114
|
+
* Hears the pipeline list of the pipelines that a scene's renderer built for its first frame,
|
|
115
|
+
* once that frame has drawn.
|
|
116
|
+
*/
|
|
117
|
+
listBuilds?: (list: Uint32Array) => void;
|
|
118
|
+
}
|
|
119
|
+
/** What a scene's renderer does with pipeline lists, as `RendererOptions` gives it. */
|
|
120
|
+
export type PipelineLists = Pick<RendererOptions, 'earlyBuilds' | 'listBuilds'>;
|
|
121
|
+
/**
|
|
122
|
+
* What the thread that draws can start as soon as the probe has chosen the GPU path, before the
|
|
123
|
+
* core arrives: the downloads of its renderers, of its device's shader file and of the files of the
|
|
124
|
+
* features that `createEngine` preloads, and on WebGPU the request for its device.
|
|
125
|
+
*/
|
|
126
|
+
export interface DrawingPreload {
|
|
127
|
+
tier: Tier;
|
|
128
|
+
/**
|
|
129
|
+
* The device as the engine uses it: its fixed bits pick the shader file, and it says what the
|
|
130
|
+
* GPU device needs.
|
|
131
|
+
*/
|
|
132
|
+
device: CoreDevice;
|
|
133
|
+
/** Requests a compatibility-mode device without `core-features-and-limits`. */
|
|
134
|
+
forceCompat?: boolean;
|
|
135
|
+
/** Which GPU to draw with on a device with two; the browser chooses without it. */
|
|
136
|
+
powerPreference?: PowerPreference;
|
|
137
|
+
/** The features whose shader files load before the first frame, as `createEngine` lists them. */
|
|
138
|
+
preload?: readonly string[];
|
|
102
139
|
}
|
|
103
140
|
/** Encodes a linear color channel as sRGB, the way the final output does. */
|
|
104
141
|
export declare function linearToSrgb(c: number): number;
|
|
105
142
|
/**
|
|
106
|
-
* Starts
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
143
|
+
* Starts what a renderer that `preload` describes needs first: the downloads of its GPU path's
|
|
144
|
+
* renderers, of its device module of shaders and of the modules of the features that it preloads,
|
|
145
|
+
* and on WebGPU the request for its device. They then overlap the core's download. The renderer's
|
|
146
|
+
* own loads later get the same modules, because the browser keeps one module for each address,
|
|
147
|
+
* and the first renderer takes the device. Those loads report a failure, so these ignore it.
|
|
110
148
|
*/
|
|
111
|
-
export declare function
|
|
149
|
+
export declare function startEarly(preload: DrawingPreload): EarlyStart;
|
|
112
150
|
/**
|
|
113
151
|
* Creates the renderer for a tier on the canvas this thread owns, with the renderers of the tier's
|
|
114
152
|
* GPU path, which load here unless a preload started them.
|
|
115
153
|
*/
|
|
116
154
|
export declare function createRenderer(canvas: RenderCanvas, options: RendererOptions): Promise<Renderer>;
|
|
155
|
+
/** What a WebGPU device request reads. */
|
|
156
|
+
interface DeviceRequest extends Pick<RendererOptions, 'forceCompat' | 'powerPreference' | 'device'> {
|
|
157
|
+
/**
|
|
158
|
+
* True when the renderer times frames on the GPU, which asks for the GPU timer where the adapter
|
|
159
|
+
* has it.
|
|
160
|
+
*/
|
|
161
|
+
timestamps: boolean;
|
|
162
|
+
}
|
|
163
|
+
/** A WebGPU device and the tier that it runs. */
|
|
164
|
+
interface GpuDevice {
|
|
165
|
+
tier: Tier;
|
|
166
|
+
device: GPUDevice;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The start of the thread that draws, from the page's message after the probe: the times of its
|
|
170
|
+
* steps, and on WebGPU the device that it asked for before its first renderer, so the request
|
|
171
|
+
* overlaps the core's download. That renderer takes the device when it asks for the same one. A
|
|
172
|
+
* device that no renderer takes goes on `release`.
|
|
173
|
+
*/
|
|
174
|
+
export declare class EarlyStart {
|
|
175
|
+
readonly steps: DrawingSteps;
|
|
176
|
+
/** The early device, until a renderer takes it or the start lets it go. */
|
|
177
|
+
private device;
|
|
178
|
+
/** The key of what the early device was asked for. */
|
|
179
|
+
private key;
|
|
180
|
+
/** True once the browser took the early device away, as when its GPU process restarts. */
|
|
181
|
+
private lost;
|
|
182
|
+
/** Asks for the device that `request` describes, ahead of the renderer. */
|
|
183
|
+
requestDevice(request: DeviceRequest): void;
|
|
184
|
+
/**
|
|
185
|
+
* The early device for a renderer that asks for `request`, once, or undefined where no early
|
|
186
|
+
* device waits or it was asked for another device. A device that the browser took away meanwhile
|
|
187
|
+
* is asked for again.
|
|
188
|
+
*/
|
|
189
|
+
takeDevice(request: DeviceRequest): Promise<GpuDevice> | undefined;
|
|
190
|
+
/** Destroys the early device unless a renderer took it. */
|
|
191
|
+
release(): void;
|
|
192
|
+
}
|
package/lib/render/renderer.js
CHANGED
|
@@ -7,6 +7,7 @@ import { glslFirstUseFiles, loadGlslFeature, loadGlslShaders, loadWgslFeature, l
|
|
|
7
7
|
import { DeviceShaderSet, filesFor } from '../gpu/device-shaders.js';
|
|
8
8
|
import { reclaimContext, webgl2Context } from '../gpu/webgl2/context.js';
|
|
9
9
|
import { TEXTURE_COMPRESSION } from '../page/limits.js';
|
|
10
|
+
import { DrawingSteps } from '../shared/metrics.js';
|
|
10
11
|
import { contextLoss, contextRestored } from './loss.js';
|
|
11
12
|
import { freshSalt, saltShaders } from './shader-salt.js';
|
|
12
13
|
/** WebGPU's default `maxBufferSize`, which every device offers. */
|
|
@@ -15,33 +16,76 @@ const DEFAULT_MAX_BUFFER_BYTES = 256 * 1024 * 1024;
|
|
|
15
16
|
export function linearToSrgb(c) {
|
|
16
17
|
return c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055;
|
|
17
18
|
}
|
|
18
|
-
/** The loaded shaders, or a fresh copy that the browser must compile again when the device asks. */
|
|
19
|
-
const freshIf = (device, shaders) => device.freshShaders ? shaders.then((loaded) => saltShaders(loaded, freshSalt())) : shaders;
|
|
20
19
|
/**
|
|
21
20
|
* The feature whose file holds another feature's work on WebGPU. WebGPU morphs in the skinning
|
|
22
21
|
* pass and has no MORPH builds (decision record D-51), so a morphed mesh there needs the skinning
|
|
23
22
|
* file.
|
|
24
23
|
*/
|
|
25
24
|
const WGSL_FEATURE_FILES = { morph: 'skinning' };
|
|
25
|
+
const WGSL = {
|
|
26
|
+
load: loadWgslShaders,
|
|
27
|
+
loadFeature: loadWgslFeature,
|
|
28
|
+
files: wgslFirstUseFiles,
|
|
29
|
+
featureFiles: WGSL_FEATURE_FILES,
|
|
30
|
+
};
|
|
31
|
+
const GLSL = {
|
|
32
|
+
load: loadGlslShaders,
|
|
33
|
+
loadFeature: loadGlslFeature,
|
|
34
|
+
files: glslFirstUseFiles,
|
|
35
|
+
featureFiles: {},
|
|
36
|
+
};
|
|
37
|
+
const pathShaders = (tier) => (tier === 'webgl2' ? GLSL : WGSL);
|
|
38
|
+
/**
|
|
39
|
+
* Starts the downloads of the shader files of features as they are named, for a device with fixed
|
|
40
|
+
* bits: each feature's own file, and each file of the builds that need several features once all
|
|
41
|
+
* of them are named. Each file downloads once. The device's set takes the modules later, and the
|
|
42
|
+
* browser then gives it the module that is already on its way.
|
|
43
|
+
*/
|
|
44
|
+
class FeatureDownloads {
|
|
45
|
+
path;
|
|
46
|
+
bits;
|
|
47
|
+
wanted = new Set();
|
|
48
|
+
started = new Set();
|
|
49
|
+
constructor(path, bits) {
|
|
50
|
+
this.path = path;
|
|
51
|
+
this.bits = bits;
|
|
52
|
+
}
|
|
53
|
+
add(features) {
|
|
54
|
+
for (const feature of features)
|
|
55
|
+
this.wanted.add(this.path.featureFiles[feature] ?? feature);
|
|
56
|
+
for (const file of filesFor(this.path.files(), this.wanted)) {
|
|
57
|
+
if (this.started.has(file))
|
|
58
|
+
continue;
|
|
59
|
+
this.started.add(file);
|
|
60
|
+
// The set's own load of the module reports a failure.
|
|
61
|
+
this.path.loadFeature(file, this.bits).catch(() => undefined);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** The loaded shaders, or a fresh copy that the browser must compile again when the device asks. */
|
|
66
|
+
const freshIf = (device, shaders) => device.freshShaders ? shaders.then((loaded) => saltShaders(loaded, freshSalt())) : shaders;
|
|
26
67
|
/**
|
|
27
|
-
* The device's shaders, from the start's module of its fixed bits, as a set that
|
|
28
|
-
* of other fixed bits
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* the
|
|
32
|
-
*
|
|
33
|
-
* with another feature's builds, the feature whose file to load in its place.
|
|
68
|
+
* The device's shaders on a GPU path, from the start's module of its fixed bits, as a set that
|
|
69
|
+
* loads the module of other fixed bits, and a module of features that load on first use, when a
|
|
70
|
+
* pipeline needs it. The modules of the features that `options` preloads download with the
|
|
71
|
+
* start's, and the set holds them before the renderer starts. The features that the sketch asks
|
|
72
|
+
* for through the image table download as soon as they are asked for, also while the start's
|
|
73
|
+
* module downloads.
|
|
34
74
|
*/
|
|
35
|
-
async function deviceShaders(device, options,
|
|
36
|
-
const fileOf = (feature) => featureFiles[feature] ?? feature;
|
|
75
|
+
async function deviceShaders(device, options, path) {
|
|
76
|
+
const fileOf = (feature) => path.featureFiles[feature] ?? feature;
|
|
37
77
|
const bits = device.shaderBits;
|
|
38
78
|
const preload = (options.preload ?? []).map(fileOf);
|
|
39
|
-
// Every download starts at once: a module that the set imports again comes from the cache.
|
|
40
|
-
for (const file of filesFor(files, new Set(preload)))
|
|
41
|
-
loadFeature(file, bits).catch(() => undefined);
|
|
42
|
-
const shaders = new DeviceShaderSet(await freshIf(device, load(bits)), bits, (more, file) => freshIf(device, file === undefined ? load(more) : loadFeature(file, more)), files);
|
|
43
|
-
await shaders.preload(preload);
|
|
44
79
|
const table = options.imageTable;
|
|
80
|
+
const downloads = new FeatureDownloads(path, bits);
|
|
81
|
+
downloads.add(preload);
|
|
82
|
+
if (table) {
|
|
83
|
+
downloads.add(table.preloads);
|
|
84
|
+
table.onPreload = (feature) => downloads.add([feature]);
|
|
85
|
+
}
|
|
86
|
+
const shaders = new DeviceShaderSet(await freshIf(device, path.load(bits)), bits, (more, file) => freshIf(device, file === undefined ? path.load(more) : path.loadFeature(file, more)), path.files());
|
|
87
|
+
options.early?.steps.mark('shaders');
|
|
88
|
+
await shaders.preload(preload);
|
|
45
89
|
if (table) {
|
|
46
90
|
void shaders.preload([...table.preloads].map(fileOf));
|
|
47
91
|
table.onPreload = (feature) => void shaders.preload([fileOf(feature)]);
|
|
@@ -53,15 +97,25 @@ const loadWebGPURenderers = () => import('./webgpu-renderers.js');
|
|
|
53
97
|
/** Loads the renderers of the WebGL2 path, which a thread downloads only to draw with WebGL2. */
|
|
54
98
|
const loadWebGL2Renderers = () => import('./webgl2-renderers.js');
|
|
55
99
|
/**
|
|
56
|
-
* Starts
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
100
|
+
* Starts what a renderer that `preload` describes needs first: the downloads of its GPU path's
|
|
101
|
+
* renderers, of its device module of shaders and of the modules of the features that it preloads,
|
|
102
|
+
* and on WebGPU the request for its device. They then overlap the core's download. The renderer's
|
|
103
|
+
* own loads later get the same modules, because the browser keeps one module for each address,
|
|
104
|
+
* and the first renderer takes the device. Those loads report a failure, so these ignore it.
|
|
60
105
|
*/
|
|
61
|
-
export function
|
|
62
|
-
const
|
|
106
|
+
export function startEarly(preload) {
|
|
107
|
+
const early = new EarlyStart();
|
|
108
|
+
early.steps.mark('request');
|
|
109
|
+
const webgl2 = preload.tier === 'webgl2';
|
|
63
110
|
(webgl2 ? loadWebGL2Renderers() : loadWebGPURenderers()).catch(() => undefined);
|
|
64
|
-
|
|
111
|
+
const path = pathShaders(preload.tier);
|
|
112
|
+
const bits = preload.device.shaderBits;
|
|
113
|
+
path.load(bits).then(() => early.steps.mark('shaders'), () => undefined);
|
|
114
|
+
new FeatureDownloads(path, bits).add(preload.preload ?? []);
|
|
115
|
+
// Every thread that draws times its frames, so its device asks for the GPU timer.
|
|
116
|
+
if (!webgl2)
|
|
117
|
+
early.requestDevice({ ...preload, timestamps: true });
|
|
118
|
+
return early;
|
|
65
119
|
}
|
|
66
120
|
/**
|
|
67
121
|
* Creates the renderer for a tier on the canvas this thread owns, with the renderers of the tier's
|
|
@@ -69,6 +123,8 @@ export function preloadDeviceFiles(tier, bits) {
|
|
|
69
123
|
*/
|
|
70
124
|
export async function createRenderer(canvas, options) {
|
|
71
125
|
const { scene, device } = options;
|
|
126
|
+
const path = pathShaders(options.tier);
|
|
127
|
+
const steps = options.early?.steps;
|
|
72
128
|
if (options.tier === 'webgl2') {
|
|
73
129
|
// A canvas keeps the settings of the first request for its context and ignores later ones,
|
|
74
130
|
// so the context is made here with the engine's settings, before anything else asks for it.
|
|
@@ -84,8 +140,7 @@ export async function createRenderer(canvas, options) {
|
|
|
84
140
|
const [, , shaders, timing, renderers] = await Promise.all([
|
|
85
141
|
reclaimContext(canvas),
|
|
86
142
|
contextRestored(gl),
|
|
87
|
-
scene &&
|
|
88
|
-
deviceShaders(device, options, loadGlslShaders, loadGlslFeature, glslFirstUseFiles()),
|
|
143
|
+
scene && deviceShaders(device, options, path),
|
|
89
144
|
options.glTiming && import('../gpu/webgl2/call-timing.js'),
|
|
90
145
|
loadWebGL2Renderers(),
|
|
91
146
|
]);
|
|
@@ -93,19 +148,31 @@ export async function createRenderer(canvas, options) {
|
|
|
93
148
|
// context that is back, in the same task, so its own listener hears the next loss.
|
|
94
149
|
while (gl.isContextLost())
|
|
95
150
|
await contextRestored(gl);
|
|
96
|
-
|
|
151
|
+
const renderer = renderers.webgl2Renderer(canvas, gl, options, shaders, timing || undefined);
|
|
152
|
+
steps?.mark('renderer');
|
|
153
|
+
return renderer;
|
|
97
154
|
}
|
|
98
155
|
finally {
|
|
99
156
|
starting.abort();
|
|
100
157
|
}
|
|
101
158
|
}
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
159
|
+
const request = { ...options, timestamps: options.metrics !== undefined };
|
|
160
|
+
const gpuRequest = options.early?.takeDevice(request) ?? requestDevice(request, steps);
|
|
161
|
+
try {
|
|
162
|
+
const [gpu, shaders, renderers] = await Promise.all([
|
|
163
|
+
gpuRequest,
|
|
164
|
+
scene && deviceShaders(device, options, path),
|
|
165
|
+
loadWebGPURenderers(),
|
|
166
|
+
]);
|
|
167
|
+
const renderer = renderers.webgpuRenderer(gpu, canvas, options, shaders);
|
|
168
|
+
steps?.mark('renderer');
|
|
169
|
+
return renderer;
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
// A device that no renderer holds goes now, not when the browser collects it.
|
|
173
|
+
gpuRequest.then((gpu) => gpu.device.destroy(), () => undefined);
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
109
176
|
}
|
|
110
177
|
/**
|
|
111
178
|
* A feature that the engine chose to draw with, which the adapter must offer. `use` says what the
|
|
@@ -116,34 +183,105 @@ function adapterFeature(adapter, feature, use) {
|
|
|
116
183
|
throw new Error(`the GPU adapter lacks the WebGPU feature ${feature}, which the engine chose for ${use} on the GPU it started with`);
|
|
117
184
|
return feature;
|
|
118
185
|
}
|
|
119
|
-
/**
|
|
120
|
-
|
|
186
|
+
/**
|
|
187
|
+
* The values of `request` that `requestDevice` reads, as one string: two requests with the same key
|
|
188
|
+
* ask for the same device.
|
|
189
|
+
*/
|
|
190
|
+
function requestKey({ forceCompat, powerPreference, timestamps, device }) {
|
|
191
|
+
const { capabilities, sceneColor, effectsSceneColor, shaderBits, storageBindingBytes } = device;
|
|
192
|
+
return [
|
|
193
|
+
forceCompat === true,
|
|
194
|
+
powerPreference,
|
|
195
|
+
timestamps,
|
|
196
|
+
capabilities,
|
|
197
|
+
sceneColor,
|
|
198
|
+
effectsSceneColor,
|
|
199
|
+
shaderBits & PERMUTATION_HALF,
|
|
200
|
+
storageBindingBytes,
|
|
201
|
+
].join();
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The start of the thread that draws, from the page's message after the probe: the times of its
|
|
205
|
+
* steps, and on WebGPU the device that it asked for before its first renderer, so the request
|
|
206
|
+
* overlaps the core's download. That renderer takes the device when it asks for the same one. A
|
|
207
|
+
* device that no renderer takes goes on `release`.
|
|
208
|
+
*/
|
|
209
|
+
export class EarlyStart {
|
|
210
|
+
steps = new DrawingSteps();
|
|
211
|
+
/** The early device, until a renderer takes it or the start lets it go. */
|
|
212
|
+
device;
|
|
213
|
+
/** The key of what the early device was asked for. */
|
|
214
|
+
key = '';
|
|
215
|
+
/** True once the browser took the early device away, as when its GPU process restarts. */
|
|
216
|
+
lost = false;
|
|
217
|
+
/** Asks for the device that `request` describes, ahead of the renderer. */
|
|
218
|
+
requestDevice(request) {
|
|
219
|
+
this.release();
|
|
220
|
+
this.key = requestKey(request);
|
|
221
|
+
this.lost = false;
|
|
222
|
+
const device = requestDevice(request, this.steps);
|
|
223
|
+
this.device = device;
|
|
224
|
+
// A failure waits for the renderer that takes the device, which reports it.
|
|
225
|
+
device.then((gpu) => gpu.device.lost.then(() => {
|
|
226
|
+
if (this.device === device)
|
|
227
|
+
this.lost = true;
|
|
228
|
+
}), () => undefined);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* The early device for a renderer that asks for `request`, once, or undefined where no early
|
|
232
|
+
* device waits or it was asked for another device. A device that the browser took away meanwhile
|
|
233
|
+
* is asked for again.
|
|
234
|
+
*/
|
|
235
|
+
takeDevice(request) {
|
|
236
|
+
const device = this.device;
|
|
237
|
+
if (!device)
|
|
238
|
+
return undefined;
|
|
239
|
+
if (requestKey(request) !== this.key) {
|
|
240
|
+
this.release();
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
this.device = undefined;
|
|
244
|
+
return device.then((gpu) => (this.lost ? requestDevice(request, this.steps) : gpu));
|
|
245
|
+
}
|
|
246
|
+
/** Destroys the early device unless a renderer took it. */
|
|
247
|
+
release() {
|
|
248
|
+
const device = this.device;
|
|
249
|
+
this.device = undefined;
|
|
250
|
+
device?.then((gpu) => gpu.device.destroy(), () => undefined);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Requests a WebGPU device with the features and limits that the engine uses, and its tier, and
|
|
255
|
+
* notes in `steps` when the adapter and the device arrive.
|
|
256
|
+
*/
|
|
257
|
+
async function requestDevice(request, steps) {
|
|
121
258
|
const adapter = await navigator.gpu?.requestAdapter({
|
|
122
259
|
featureLevel: 'compatibility',
|
|
123
|
-
powerPreference:
|
|
260
|
+
powerPreference: request.powerPreference,
|
|
124
261
|
});
|
|
125
262
|
if (!adapter)
|
|
126
263
|
throw new Error('no WebGPU adapter');
|
|
127
|
-
|
|
264
|
+
steps?.mark('adapter');
|
|
265
|
+
const core = !request.forceCompat && adapter.features.has('core-features-and-limits');
|
|
128
266
|
const requiredFeatures = [];
|
|
129
267
|
if (core)
|
|
130
268
|
requiredFeatures.push('core-features-and-limits');
|
|
131
|
-
if (
|
|
269
|
+
if (request.timestamps && adapter.features.has('timestamp-query'))
|
|
132
270
|
requiredFeatures.push('timestamp-query');
|
|
133
271
|
// The compressed formats that the sketch thread picks for KTX2 files, from the same adapter.
|
|
134
272
|
for (const [flag, feature] of TEXTURE_COMPRESSION)
|
|
135
|
-
if (
|
|
273
|
+
if (request.device.capabilities & flag && adapter.features.has(feature))
|
|
136
274
|
requiredFeatures.push(feature);
|
|
137
275
|
// The scene color at the start, or after an effect that needs HDR color switches to it. The
|
|
138
276
|
// engine chose these from the page's adapter, and a new adapter, as after a GPU loss on a
|
|
139
277
|
// machine with two GPUs, can lack them.
|
|
140
|
-
const { sceneColor, effectsSceneColor } =
|
|
278
|
+
const { sceneColor, effectsSceneColor } = request.device;
|
|
141
279
|
if (sceneColor === FORMAT_RG11B10_UFLOAT || effectsSceneColor === FORMAT_RG11B10_UFLOAT)
|
|
142
280
|
requiredFeatures.push(adapterFeature(adapter, 'rg11b10ufloat-renderable', 'its HDR color'));
|
|
143
281
|
// The device chose half precision only where the adapter offers 16-bit floats.
|
|
144
|
-
if (
|
|
282
|
+
if (request.device.shaderBits & PERMUTATION_HALF)
|
|
145
283
|
requiredFeatures.push(adapterFeature(adapter, 'shader-f16', 'its half precision shaders'));
|
|
146
|
-
const binding =
|
|
284
|
+
const binding = request.device.storageBindingBytes;
|
|
147
285
|
const device = await adapter.requestDevice({
|
|
148
286
|
requiredFeatures,
|
|
149
287
|
// A buffer as large as a binding must fit the device's largest buffer too.
|
|
@@ -152,5 +290,6 @@ async function requestDevice(options) {
|
|
|
152
290
|
maxBufferSize: Math.max(binding, DEFAULT_MAX_BUFFER_BYTES),
|
|
153
291
|
},
|
|
154
292
|
});
|
|
293
|
+
steps?.mark('device');
|
|
155
294
|
return { tier: core ? 'webgpu' : 'webgpu-compat', device };
|
|
156
295
|
}
|
|
@@ -2,6 +2,7 @@ import type { JoinedBuilds } from '../gpu/effect-join.js';
|
|
|
2
2
|
import type { GpuMemory } from '../gpu/memory.js';
|
|
3
3
|
import { ReadSink } from '../gpu/readback.js';
|
|
4
4
|
import { type FrameRecorder } from '../shared/metrics.js';
|
|
5
|
+
import type { PipelineLists } from './renderer.js';
|
|
5
6
|
/**
|
|
6
7
|
* The longest that a capture waits for pipelines to build. A software rasteriser builds a
|
|
7
8
|
* showcase's pipelines slower than a GPU: the island needed more than thirty seconds at every
|
|
@@ -38,6 +39,10 @@ interface SceneBackend {
|
|
|
38
39
|
readonly joins: JoinedBuilds;
|
|
39
40
|
/** Where the bytes of the draw lists' reads land, which the frame replay sets. */
|
|
40
41
|
readSink: ReadSink | undefined;
|
|
42
|
+
/** Starts to build the pipelines of a pipeline list ahead of their commands. */
|
|
43
|
+
buildEarly(list: Uint32Array): void;
|
|
44
|
+
/** Ends the list of the pipelines that the frames before the first one created, and returns it. */
|
|
45
|
+
takeListing(): Uint32Array | undefined;
|
|
41
46
|
}
|
|
42
47
|
/**
|
|
43
48
|
* Adds what the backend did since its last reset to a frame's record, then resets its counts. While
|
|
@@ -70,11 +75,24 @@ export declare class FrameReplay {
|
|
|
70
75
|
private complete;
|
|
71
76
|
/** The first frame of the last hold that a prepared frame reached. */
|
|
72
77
|
private held;
|
|
73
|
-
|
|
78
|
+
/** True until the first frame has drawn: the backend lists the pipelines that it builds. */
|
|
79
|
+
private listing;
|
|
80
|
+
/** Hears the pipelines that the first frame built, once that frame has drawn. */
|
|
81
|
+
private listBuilds;
|
|
82
|
+
/**
|
|
83
|
+
* `lists` gives the pipeline list of the sketch's last start, whose pipelines the backend starts
|
|
84
|
+
* to build at once, and the listener of this start's list.
|
|
85
|
+
*/
|
|
86
|
+
constructor(backend: SceneBackend, memory: WebAssembly.Memory, control: ArrayBufferLike, lists?: PipelineLists);
|
|
74
87
|
/** Starts the builds of a frame's pipelines, once, and returns true when the frame may draw. */
|
|
75
88
|
prepare(frame: number): boolean;
|
|
76
89
|
/** Replays a frame's list, apart from the pipelines it creates, which are building already. */
|
|
77
90
|
replay(frame: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Ends the backend's list of the first frame's pipelines, once that frame has drawn, and gives
|
|
93
|
+
* it to its listener.
|
|
94
|
+
*/
|
|
95
|
+
private endListing;
|
|
78
96
|
/** Replays the list that a capture draws for the frame taken last. */
|
|
79
97
|
replayForCapture(frame: number): void;
|
|
80
98
|
/**
|
|
@@ -62,12 +62,23 @@ export class FrameReplay {
|
|
|
62
62
|
complete = false;
|
|
63
63
|
/** The first frame of the last hold that a prepared frame reached. */
|
|
64
64
|
held = 0;
|
|
65
|
-
|
|
65
|
+
/** True until the first frame has drawn: the backend lists the pipelines that it builds. */
|
|
66
|
+
listing = true;
|
|
67
|
+
/** Hears the pipelines that the first frame built, once that frame has drawn. */
|
|
68
|
+
listBuilds;
|
|
69
|
+
/**
|
|
70
|
+
* `lists` gives the pipeline list of the sketch's last start, whose pipelines the backend starts
|
|
71
|
+
* to build at once, and the listener of this start's list.
|
|
72
|
+
*/
|
|
73
|
+
constructor(backend, memory, control, lists = {}) {
|
|
66
74
|
this.backend = backend;
|
|
67
75
|
this.views = new MemoryViews(memory);
|
|
68
76
|
this.slots = controlViews(control).slots;
|
|
69
77
|
backend.readSink = new ReadSink(this.views, this.slots);
|
|
70
78
|
backend.joins.onFailed = (template) => Atomics.store(this.slots, Slot.JoinFailed, template);
|
|
79
|
+
if (lists.earlyBuilds)
|
|
80
|
+
backend.buildEarly(lists.earlyBuilds);
|
|
81
|
+
this.listBuilds = lists.listBuilds;
|
|
71
82
|
}
|
|
72
83
|
/** Starts the builds of a frame's pipelines, once, and returns true when the frame may draw. */
|
|
73
84
|
prepare(frame) {
|
|
@@ -93,6 +104,19 @@ export class FrameReplay {
|
|
|
93
104
|
this.backend.replay(words, this.views.heap(Float32Array), from, this.end, words.buffer);
|
|
94
105
|
if (!this.backend.building)
|
|
95
106
|
this.complete = true;
|
|
107
|
+
if (this.listing)
|
|
108
|
+
this.endListing();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Ends the backend's list of the first frame's pipelines, once that frame has drawn, and gives
|
|
112
|
+
* it to its listener.
|
|
113
|
+
*/
|
|
114
|
+
endListing() {
|
|
115
|
+
this.listing = false;
|
|
116
|
+
const list = this.backend.takeListing();
|
|
117
|
+
if (this.listBuilds && list)
|
|
118
|
+
this.listBuilds(list);
|
|
119
|
+
this.listBuilds = undefined;
|
|
96
120
|
}
|
|
97
121
|
/** Replays the list that a capture draws for the frame taken last. */
|
|
98
122
|
replayForCapture(frame) {
|