@null3d/engine 0.1.1 → 0.1.3
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/dist/wasm/single/null3d.js +4 -4
- package/dist/wasm/single/null3d_bg.wasm +0 -0
- package/dist/wasm/threaded/null3d.js +4 -4
- package/dist/wasm/threaded/null3d_bg.wasm +0 -0
- package/docs/api/reference/engine.md +2 -1
- package/docs/cli/null3d.md +60 -4
- package/docs/concepts/backends.md +4 -0
- package/docs/concepts/quality-presets.md +2 -0
- package/docs/errors/E1308.md +31 -0
- package/docs/errors/E1404.md +5 -1
- package/docs/errors/index.md +1 -0
- package/docs/getting-started/cdn.md +1 -1
- package/docs/getting-started/first-scene.md +3 -1
- package/docs/getting-started/hosting.md +13 -3
- package/docs/getting-started/install.md +21 -1
- package/docs/getting-started/project-structure.md +1 -1
- package/docs/guides/agents.md +12 -9
- package/docs/guides/assets-pipeline.md +77 -6
- package/docs/guides/content-pages.md +33 -0
- package/docs/guides/debugging.md +2 -0
- package/docs/guides/deploying.md +5 -1
- package/docs/guides/deterministic-simulation.md +5 -2
- package/docs/guides/loading-screens.md +4 -0
- package/docs/guides/performance.md +2 -0
- package/docs/guides/start-time.md +8 -0
- package/docs/guides/testing.md +20 -0
- package/docs/pages.md +1 -1
- package/docs/porting/verification.md +1 -1
- package/lib/errors/codes.js +11 -0
- package/lib/errors/engine-error.js +1 -1
- package/lib/errors/fixes.d.ts +1 -0
- package/lib/errors/fixes.js +2 -1
- package/lib/generated/shader-permutations.d.ts +6 -0
- package/lib/generated/shader-permutations.js +6 -0
- package/lib/gpu/device-shaders.d.ts +5 -0
- package/lib/gpu/device-shaders.js +10 -1
- package/lib/gpu/variants.d.ts +25 -0
- package/lib/gpu/variants.js +75 -5
- package/lib/gpu/webgl2/backend.d.ts +22 -3
- package/lib/gpu/webgl2/backend.js +108 -22
- package/lib/gpu/webgl2/programs.d.ts +5 -0
- package/lib/gpu/webgl2/programs.js +25 -2
- package/lib/gpu/webgpu/backend.d.ts +34 -1
- package/lib/gpu/webgpu/backend.js +173 -27
- package/lib/gpu/webgpu/pipelines.d.ts +2 -2
- package/lib/gpu/webgpu/pipelines.js +15 -15
- package/lib/page/engine.d.ts +15 -2
- package/lib/page/engine.js +124 -9
- package/lib/page/permutation-recording.d.ts +5 -3
- package/lib/page/permutation-recording.js +13 -7
- package/lib/quality/chooser.d.ts +2 -0
- package/lib/quality/chooser.js +4 -0
- package/lib/shader-artifact.json +1 -1
- package/lib/shared/permutation-words.d.ts +6 -0
- package/lib/shared/permutation-words.js +6 -0
- package/lib/shared/tier.d.ts +9 -0
- package/lib/shared/tier.js +4 -1
- package/lib/shared/version.d.ts +1 -1
- package/lib/shared/version.js +1 -1
- package/lib/workers/protocol.d.ts +29 -0
- package/lib/workers/render-worker.js +6 -3
- package/lib/workers/sketch-worker.js +6 -3
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ import { DEBUG_LINES_SHADER, DEBUG_VIEW_SHADER, MOTION_VIEW_SHADER, } from '../.
|
|
|
8
8
|
import { LINE_VERTICES } from '../line-vertices.js';
|
|
9
9
|
import { PARTICLE_RECORDS } from '../particle-records.js';
|
|
10
10
|
import { pipelineName } from '../pipeline-name.js';
|
|
11
|
-
import {
|
|
11
|
+
import { listedWord, MissingVariantError, missingShaderError, missingVariant, variantFor, } from '../variants.js';
|
|
12
12
|
import { plainScale, variantLocations, vertexAttribute, vertexStride, } from '../vertex-format.js';
|
|
13
13
|
/**
|
|
14
14
|
* True in development builds, which add the debug views' templates. This file reads the constant
|
|
@@ -1603,8 +1603,8 @@ export class Pipelines {
|
|
|
1603
1603
|
}
|
|
1604
1604
|
/**
|
|
1605
1605
|
* True when the pipelines of a template draw objects of the scene: meshes, or a custom material's
|
|
1606
|
-
* draw shader. A
|
|
1607
|
-
*
|
|
1606
|
+
* draw shader. A driver's refusal of such a pipeline is retried, and then its draws skip. A
|
|
1607
|
+
* missing shader or a failed load skips any pipeline or pass (D-405).
|
|
1608
1608
|
*/
|
|
1609
1609
|
drawsObjects(id) {
|
|
1610
1610
|
const template = this.templates[id];
|
|
@@ -1693,7 +1693,7 @@ export class Pipelines {
|
|
|
1693
1693
|
const build = ownPrepass && !cutoutPrepass ? (permutation & ~PERMUTATION_PREPASS) >>> 0 : permutation;
|
|
1694
1694
|
const shader = variantFor(t.shader, build, 'wgsl')?.wgsl;
|
|
1695
1695
|
if (!shader)
|
|
1696
|
-
throw new
|
|
1696
|
+
throw new MissingVariantError(listedWord(build), `render template ${template}: ${missingVariant(build)}`);
|
|
1697
1697
|
const module = this.module(t.label, shader);
|
|
1698
1698
|
const entryPoints = shader.pipelines[t.pipeline];
|
|
1699
1699
|
const skins = (permutation & PERMUTATION_SKIN) !== 0;
|
|
@@ -1837,7 +1837,7 @@ export class Pipelines {
|
|
|
1837
1837
|
mipDescriptor(format, entry) {
|
|
1838
1838
|
const shader = this.mipmap;
|
|
1839
1839
|
if (!shader)
|
|
1840
|
-
throw
|
|
1840
|
+
throw missingShaderError('mip level', 0);
|
|
1841
1841
|
const module = this.module('mipmaps', shader);
|
|
1842
1842
|
const entryPoints = shader.pipelines[entry];
|
|
1843
1843
|
return {
|
|
@@ -1895,7 +1895,7 @@ export class Pipelines {
|
|
|
1895
1895
|
const color = (permutation & PERMUTATION_VERTEX_COLOR) !== 0 ? ' color' : '';
|
|
1896
1896
|
const shader = variantFor(this.skin, permutation, 'wgsl')?.wgsl;
|
|
1897
1897
|
if (!shader)
|
|
1898
|
-
throw
|
|
1898
|
+
throw missingShaderError('skinning', permutation);
|
|
1899
1899
|
const constants = this.floatSkinnedDirections ? { [NARROW_DIRECTIONS_ID]: 0 } : undefined;
|
|
1900
1900
|
return {
|
|
1901
1901
|
label: `skin${tangent}${color}`,
|
|
@@ -1906,7 +1906,7 @@ export class Pipelines {
|
|
|
1906
1906
|
if (template === TEMPLATE_CULL && permutation & PERMUTATION_MOTION) {
|
|
1907
1907
|
const shader = variantFor(this.cullMotion, permutation, 'wgsl')?.wgsl;
|
|
1908
1908
|
if (!shader)
|
|
1909
|
-
throw
|
|
1909
|
+
throw missingShaderError('motion culling', permutation);
|
|
1910
1910
|
return {
|
|
1911
1911
|
label: 'cull motion',
|
|
1912
1912
|
layout: this.cullLayout,
|
|
@@ -1915,7 +1915,7 @@ export class Pipelines {
|
|
|
1915
1915
|
}
|
|
1916
1916
|
if (template === TEMPLATE_CULL) {
|
|
1917
1917
|
if (!this.cull)
|
|
1918
|
-
throw
|
|
1918
|
+
throw missingShaderError('culling', 0);
|
|
1919
1919
|
return {
|
|
1920
1920
|
label: 'cull',
|
|
1921
1921
|
layout: this.cullLayout,
|
|
@@ -1926,7 +1926,7 @@ export class Pipelines {
|
|
|
1926
1926
|
if (phase) {
|
|
1927
1927
|
const shader = variantFor(this.occlusion, 0, 'wgsl')?.wgsl;
|
|
1928
1928
|
if (!shader)
|
|
1929
|
-
throw
|
|
1929
|
+
throw missingShaderError('occlusion culling', 0);
|
|
1930
1930
|
return {
|
|
1931
1931
|
label: `occlusion ${phase}`,
|
|
1932
1932
|
layout: this.cullLayout,
|
|
@@ -1936,7 +1936,7 @@ export class Pipelines {
|
|
|
1936
1936
|
if (template === TEMPLATE_CLUSTER) {
|
|
1937
1937
|
const shader = this.cluster ? variantFor(this.cluster, 0, 'wgsl')?.wgsl : undefined;
|
|
1938
1938
|
if (!shader)
|
|
1939
|
-
throw
|
|
1939
|
+
throw missingShaderError('cluster', 0);
|
|
1940
1940
|
return {
|
|
1941
1941
|
label: 'cluster cull',
|
|
1942
1942
|
layout: this.clusterLayout,
|
|
@@ -1946,7 +1946,7 @@ export class Pipelines {
|
|
|
1946
1946
|
if (template === TEMPLATE_DEPTH_PYRAMID) {
|
|
1947
1947
|
const shader = variantFor(this.pyramid, 0, 'wgsl')?.wgsl;
|
|
1948
1948
|
if (!shader)
|
|
1949
|
-
throw
|
|
1949
|
+
throw missingShaderError('depth pyramid', 0);
|
|
1950
1950
|
return {
|
|
1951
1951
|
label: 'depth pyramid',
|
|
1952
1952
|
layout: this.pyramidLayout,
|
|
@@ -1956,7 +1956,7 @@ export class Pipelines {
|
|
|
1956
1956
|
if (template === TEMPLATE_FEATURE_ROWS) {
|
|
1957
1957
|
const shader = variantFor(this.featureRows, 0, 'wgsl')?.wgsl;
|
|
1958
1958
|
if (!shader)
|
|
1959
|
-
throw
|
|
1959
|
+
throw missingShaderError('feature rows', 0);
|
|
1960
1960
|
this.featureRowsLayout ??= this.device.createPipelineLayout({
|
|
1961
1961
|
bindGroupLayouts: [this.layout(LAYOUT_FEATURE_ROWS)],
|
|
1962
1962
|
});
|
|
@@ -1970,7 +1970,7 @@ export class Pipelines {
|
|
|
1970
1970
|
if (exposureEntry) {
|
|
1971
1971
|
const shader = variantFor(this.exposureHistogram, 0, 'wgsl')?.wgsl;
|
|
1972
1972
|
if (!shader)
|
|
1973
|
-
throw
|
|
1973
|
+
throw missingShaderError('exposure histogram', 0);
|
|
1974
1974
|
this.exposureLayout ??= this.device.createPipelineLayout({
|
|
1975
1975
|
bindGroupLayouts: [this.layout(LAYOUT_EXPOSURE)],
|
|
1976
1976
|
});
|
|
@@ -1988,7 +1988,7 @@ export class Pipelines {
|
|
|
1988
1988
|
const clear = template === TEMPLATE_LIGHT_DEPTH_CLEAR || template === TEMPLATE_LIGHT_DEPTH_CLEAR_MS;
|
|
1989
1989
|
const shader = multisampled ? this.lightDepthMs : this.lightDepth;
|
|
1990
1990
|
if (!shader)
|
|
1991
|
-
throw
|
|
1991
|
+
throw missingShaderError('light depth', 0);
|
|
1992
1992
|
return {
|
|
1993
1993
|
label: clear ? 'light depth clear' : 'light depth',
|
|
1994
1994
|
layout: multisampled ? this.lightDepthMsLayout : this.lightDepthLayout,
|
|
@@ -2003,7 +2003,7 @@ export class Pipelines {
|
|
|
2003
2003
|
throw new Error(`unknown compute template ${template}`);
|
|
2004
2004
|
const shader = this.lightClusters;
|
|
2005
2005
|
if (!shader)
|
|
2006
|
-
throw
|
|
2006
|
+
throw missingShaderError('light clustering', 0);
|
|
2007
2007
|
return {
|
|
2008
2008
|
label: entryPoint,
|
|
2009
2009
|
layout: this.lightLayout,
|
package/lib/page/engine.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { type QualityPreset } from '../quality/presets.js';
|
|
|
7
7
|
import type { GpuErrorKind } from '../render/loss.js';
|
|
8
8
|
import type { Tier } from '../render/renderer.js';
|
|
9
9
|
import type { ReplayResult } from '../shared/recording.js';
|
|
10
|
+
import { type GpuPath } from '../shared/tier.js';
|
|
10
11
|
import type { QualityUpdate } from '../sketch/quality.js';
|
|
11
12
|
import type { LabelSlotSender } from '../sketch/ui.js';
|
|
12
13
|
import type { RendererRequest, WorkerReply } from '../workers/protocol.js';
|
|
@@ -761,8 +762,20 @@ interface TierChoice {
|
|
|
761
762
|
tier: Tier;
|
|
762
763
|
forceCompat: boolean;
|
|
763
764
|
}
|
|
764
|
-
/**
|
|
765
|
-
export declare function
|
|
765
|
+
/** True when this build holds the shaders of `path`. */
|
|
766
|
+
export declare function shipsPath(path: GpuPath): boolean;
|
|
767
|
+
/**
|
|
768
|
+
* Picks the GPU tier from feature tests, never from browser or GPU names. A path whose shaders this
|
|
769
|
+
* build does not ship counts as unavailable, whether or not the browser offers it.
|
|
770
|
+
*/
|
|
771
|
+
export declare function chooseTier(report: CapabilityReport, wanted: GpuSwitch, inWorker: boolean, ships?: (path: GpuPath) => boolean): TierChoice | null;
|
|
772
|
+
/**
|
|
773
|
+
* The error for a start that found no usable GPU tier. When the build holds the shaders of one path
|
|
774
|
+
* and this start would draw with the other, it names the build's choice (E1308), because no browser
|
|
775
|
+
* or setting can fix that page. Otherwise the browser offers no path the engine can draw with, or
|
|
776
|
+
* none that the page asked for (E1301).
|
|
777
|
+
*/
|
|
778
|
+
export declare function noTierError(report: CapabilityReport, requested: GpuSwitch, inWorker: boolean, ships?: (path: GpuPath) => boolean): EngineError;
|
|
766
779
|
/**
|
|
767
780
|
* The error of a worker that failed to start. An engine error keeps its code and message; any
|
|
768
781
|
* other failure becomes E1405.
|
package/lib/page/engine.js
CHANGED
|
@@ -15,9 +15,10 @@ import { EngineError, errorFixesReady, errorOfMessage } from '../errors/engine-e
|
|
|
15
15
|
import { messageOf } from '../errors/message.js';
|
|
16
16
|
import { FORMAT_CANVAS, PERMUTATION_HALF } from '../generated/gpu.js';
|
|
17
17
|
import { SHADER_FEATURES } from '../generated/shader-features.js';
|
|
18
|
-
import {
|
|
18
|
+
import { SHIPPED_GPU_PATHS } from '../generated/shader-permutations.js';
|
|
19
|
+
import { receiveMissingVariants, receiveUnavailableShaders, recordPermutations, reportPermutations, stopRecordingPermutations, } from '../gpu/variants.js';
|
|
19
20
|
import { maxTargetFps, } from '../quality/check.js';
|
|
20
|
-
import { choosePreset, crashLowest, crashTier, deviceKind, gpuOcclusionChoice, memoryPreset, textureMemoryCap, withinTier, } from '../quality/chooser.js';
|
|
21
|
+
import { choosePreset, crashLowest, crashTier, deviceKind, gpuOcclusionChoice, memoryPreset, presetCapped, textureMemoryCap, withinTier, } from '../quality/chooser.js';
|
|
21
22
|
import { readDeviceHints } from '../quality/device-hints.js';
|
|
22
23
|
import { capTextureMemory, checkedSettings, checkSettings, lowestTierSettings, presetCheckOption, presetOption, presetValue, targetFpsOption, } from '../quality/presets.js';
|
|
23
24
|
import { loadDrawModule, preloadDrawing } from '../render/load-draw.js';
|
|
@@ -32,9 +33,10 @@ import { KEY_CODES } from '../shared/key-codes.js';
|
|
|
32
33
|
import { memoryBytes } from '../shared/memory-views.js';
|
|
33
34
|
import { createMetricsBuffer, MetricsReader, threadRoles } from '../shared/metrics.js';
|
|
34
35
|
import { addMeasurementRelease } from '../shared/page-measurement.js';
|
|
35
|
-
import { PERMUTATION_WORD_EVENT } from '../shared/permutation-words.js';
|
|
36
|
+
import { GPU_PATH_EVENT, PERMUTATION_WORD_EVENT } from '../shared/permutation-words.js';
|
|
36
37
|
import { sketchDataText } from '../shared/sketch-data.js';
|
|
37
38
|
import { clearJobTasks, jobAsker, setJobTasks } from '../shared/task-host.js';
|
|
39
|
+
import { pathOfTier } from '../shared/tier.js';
|
|
38
40
|
import { hearAddonsEarly, onAddonChecked } from '../shared/version.js';
|
|
39
41
|
import { VIDEO_FOLLOW } from '../shared/videos.js';
|
|
40
42
|
import { notifySlot, setWakeByMessage } from '../shared/wake.js';
|
|
@@ -75,6 +77,40 @@ function fallbackText(report) {
|
|
|
75
77
|
let warnedFallback = false;
|
|
76
78
|
/** True once an engine on the page has warned that a service worker's page lost its isolation. */
|
|
77
79
|
let warnedIsolation = false;
|
|
80
|
+
/** The words that the loaded shader set lacks on this page, for a production build's check. */
|
|
81
|
+
const missingWords = new Set();
|
|
82
|
+
/**
|
|
83
|
+
* Publishes a word that the loaded shader set lacks, once per word, and warns. A production
|
|
84
|
+
* build's check reads `window.__null3dMissingWords`, which also holds the words in a release.
|
|
85
|
+
*/
|
|
86
|
+
function publishMissingWord(pipeline, word) {
|
|
87
|
+
if (missingWords.has(word))
|
|
88
|
+
return;
|
|
89
|
+
missingWords.add(word);
|
|
90
|
+
globalThis.__null3dMissingWords = [...missingWords].sort((a, b) => a - b);
|
|
91
|
+
console.warn(`null3D: ${pipeline} asks for the permutation word 0x${word.toString(16).padStart(8, '0')}, which the shader list lacks. The engine draws without it. Record the pages again with bunx @null3d/cli shaders record.`);
|
|
92
|
+
}
|
|
93
|
+
/** The shader files that did not load on this page, by the pipeline that needed one. */
|
|
94
|
+
const unavailableShaders = new Set();
|
|
95
|
+
/**
|
|
96
|
+
* Warns about a pipeline or pass whose shader file did not load, once for each cause. The engine
|
|
97
|
+
* draws without it, so the rest of the scene stays.
|
|
98
|
+
*/
|
|
99
|
+
function publishUnavailableShader(pipeline, reason) {
|
|
100
|
+
const key = `${pipeline}\n${reason}`;
|
|
101
|
+
if (unavailableShaders.has(key))
|
|
102
|
+
return;
|
|
103
|
+
unavailableShaders.add(key);
|
|
104
|
+
console.warn(`null3D: ${pipeline} needs a shader file that did not load, so the engine draws without it: ${reason}`);
|
|
105
|
+
}
|
|
106
|
+
/** Starts a new engine's record of missing words, and publishes an empty list for its check. */
|
|
107
|
+
function resetMissingWords() {
|
|
108
|
+
missingWords.clear();
|
|
109
|
+
unavailableShaders.clear();
|
|
110
|
+
globalThis.__null3dMissingWords = [];
|
|
111
|
+
}
|
|
112
|
+
/** True once an engine on the page has warned that a named preset ran on WebGL2 without WebGPU. */
|
|
113
|
+
let warnedCappedPreset = false;
|
|
78
114
|
/** The global where the `?bench` switch publishes the running engine. */
|
|
79
115
|
const BENCH_GLOBAL = '__null3dEngine';
|
|
80
116
|
/** The global where a development build publishes its inspection bridge, for the MCP server. */
|
|
@@ -116,11 +152,26 @@ const INSPECT_REPLY_LIMIT_MS = 30_000;
|
|
|
116
152
|
* than waiting for a worker that may never speak.
|
|
117
153
|
*/
|
|
118
154
|
export const RETRY_REPLY_MS = 10_000;
|
|
119
|
-
/**
|
|
120
|
-
|
|
155
|
+
/** The GPU paths whose shaders this build ships, or null for both, as the plugin's build wrote it. */
|
|
156
|
+
const SHIPPED_PATHS = SHIPPED_GPU_PATHS === null ? null : new Set(SHIPPED_GPU_PATHS);
|
|
157
|
+
/** True when this build holds the shaders of `path`. */
|
|
158
|
+
export function shipsPath(path) {
|
|
159
|
+
return SHIPPED_PATHS === null || SHIPPED_PATHS.has(path);
|
|
160
|
+
}
|
|
161
|
+
/** The path that a page's GPU switch draws with, or undefined for the engine's own choice. */
|
|
162
|
+
function pathOfSwitch(wanted) {
|
|
163
|
+
return wanted === 'auto' ? undefined : pathOfTier(wanted === 'webgl2' ? 'webgl2' : 'webgpu');
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Picks the GPU tier from feature tests, never from browser or GPU names. A path whose shaders this
|
|
167
|
+
* build does not ship counts as unavailable, whether or not the browser offers it.
|
|
168
|
+
*/
|
|
169
|
+
export function chooseTier(report, wanted, inWorker, ships = shipsPath) {
|
|
121
170
|
const worker = 'failure' in report.worker ? undefined : report.worker;
|
|
122
|
-
const webgpu =
|
|
123
|
-
|
|
171
|
+
const webgpu = ships('webgpu') &&
|
|
172
|
+
report.webgpu.compatibilityAdapter &&
|
|
173
|
+
(!inWorker || worker?.offscreenWebGPU === true);
|
|
174
|
+
const webgl2 = ships('webgl2') && (inWorker ? worker?.offscreenWebGL2 === true : report.webgl2.available);
|
|
124
175
|
if (wanted === 'webgl2')
|
|
125
176
|
return webgl2 ? { tier: 'webgl2', forceCompat: false } : null;
|
|
126
177
|
if (wanted === 'compat')
|
|
@@ -136,6 +187,38 @@ export function chooseTier(report, wanted, inWorker) {
|
|
|
136
187
|
};
|
|
137
188
|
return webgl2 ? { tier: 'webgl2', forceCompat: false } : null;
|
|
138
189
|
}
|
|
190
|
+
/** The name of a GPU path, as the error messages carry it. */
|
|
191
|
+
function pathName(path) {
|
|
192
|
+
return path === 'webgl2' ? 'WebGL2' : 'WebGPU';
|
|
193
|
+
}
|
|
194
|
+
/** The GPU paths that this build ships, as the error messages carry them. */
|
|
195
|
+
function shippedNames(ships) {
|
|
196
|
+
if (ships('webgpu') && ships('webgl2'))
|
|
197
|
+
return 'WebGPU and WebGL2';
|
|
198
|
+
return ships('webgpu') ? 'WebGPU' : 'WebGL2';
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The error for a start that found no usable GPU tier. When the build holds the shaders of one path
|
|
202
|
+
* and this start would draw with the other, it names the build's choice (E1308), because no browser
|
|
203
|
+
* or setting can fix that page. Otherwise the browser offers no path the engine can draw with, or
|
|
204
|
+
* none that the page asked for (E1301).
|
|
205
|
+
*/
|
|
206
|
+
export function noTierError(report, requested, inWorker, ships = shipsPath) {
|
|
207
|
+
const named = pathOfSwitch(requested);
|
|
208
|
+
if (named !== undefined && !ships(named))
|
|
209
|
+
return new EngineError('E1308', `this build ships only the ${shippedNames(ships)} shaders, and ?gpu=${requested} asks for ${pathName(named)}. Build the project with both GPU paths, or remove the switch.`);
|
|
210
|
+
if (named !== undefined)
|
|
211
|
+
return new EngineError('E1301', `no usable GPU path for ?gpu=${requested} in this browser.`);
|
|
212
|
+
const worker = 'failure' in report.worker ? undefined : report.worker;
|
|
213
|
+
const offered = report.webgpu.compatibilityAdapter
|
|
214
|
+
? 'webgpu'
|
|
215
|
+
: (inWorker ? worker?.offscreenWebGL2 === true : report.webgl2.available)
|
|
216
|
+
? 'webgl2'
|
|
217
|
+
: undefined;
|
|
218
|
+
if (offered !== undefined && !ships(offered))
|
|
219
|
+
return new EngineError('E1308', `this build ships only the ${shippedNames(ships)} shaders, and this device would draw with ${pathName(offered)}. The Vite plugin's shaders.gpuPaths option left ${pathName(offered)} out. Build the project with both GPU paths, or run the page in a browser that offers ${pathName(ships('webgpu') ? 'webgpu' : 'webgl2')}.`);
|
|
220
|
+
return new EngineError('E1301', `no usable GPU path for ?gpu=${requested} in this browser.`);
|
|
221
|
+
}
|
|
139
222
|
/**
|
|
140
223
|
* True while this page is hidden. A hidden page draws no frames, so a capture's answer comes once
|
|
141
224
|
* the page shows again, however long that takes, and the answer's limit counts only the time the
|
|
@@ -283,6 +366,15 @@ export class EngineWorker {
|
|
|
283
366
|
if (DEV)
|
|
284
367
|
announcePermutationWord(reply.word);
|
|
285
368
|
return;
|
|
369
|
+
case 'recorded-word':
|
|
370
|
+
this.recording?.heard(reply.word);
|
|
371
|
+
return;
|
|
372
|
+
case 'missing-word':
|
|
373
|
+
publishMissingWord(reply.pipeline, reply.word);
|
|
374
|
+
return;
|
|
375
|
+
case 'unavailable-shader':
|
|
376
|
+
publishUnavailableShader(reply.pipeline, reply.reason);
|
|
377
|
+
return;
|
|
286
378
|
case 'sketch-message':
|
|
287
379
|
events.sketchMessage(reply.name, reply.data);
|
|
288
380
|
return;
|
|
@@ -850,6 +942,7 @@ function prefetch(url) {
|
|
|
850
942
|
*/
|
|
851
943
|
export async function createEngine(options) {
|
|
852
944
|
const switches = parseSwitches(URL_SWITCHES ? (globalThis.location?.search ?? '') : '');
|
|
945
|
+
resetMissingWords();
|
|
853
946
|
const holding = options.hold !== undefined || switches.hold !== undefined || switches.replay !== undefined;
|
|
854
947
|
const place = placement(options, switches);
|
|
855
948
|
if (DEV && !warnedIsolation) {
|
|
@@ -925,6 +1018,12 @@ function placement(options, switches) {
|
|
|
925
1018
|
function announcePermutationWord(word) {
|
|
926
1019
|
globalThis.dispatchEvent?.(new CustomEvent(PERMUTATION_WORD_EVENT, { detail: word }));
|
|
927
1020
|
}
|
|
1021
|
+
/** In a development build, tells the dev server the GPU path that this engine draws with. */
|
|
1022
|
+
function announceGpuPath(tier) {
|
|
1023
|
+
if (!DEV)
|
|
1024
|
+
return;
|
|
1025
|
+
globalThis.dispatchEvent?.(new CustomEvent(GPU_PATH_EVENT, { detail: pathOfTier(tier) }));
|
|
1026
|
+
}
|
|
928
1027
|
/**
|
|
929
1028
|
* Starts the engine with the page's switches. With a hold time or a replay, it resolves once the
|
|
930
1029
|
* last frame is read back, and publishes it.
|
|
@@ -1614,8 +1713,9 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
|
|
|
1614
1713
|
drawModule ??= loadDrawModule();
|
|
1615
1714
|
}
|
|
1616
1715
|
if (!choice)
|
|
1617
|
-
throw
|
|
1716
|
+
throw noTierError(report, requested, renderThread !== 'main');
|
|
1618
1717
|
tier = choice.tier;
|
|
1718
|
+
announceGpuPath(tier);
|
|
1619
1719
|
const { forceCompat } = choice;
|
|
1620
1720
|
// Where the page draws, it moves the label elements right after each frame it draws.
|
|
1621
1721
|
const labels = new PageLabels(views, renderThread === 'main');
|
|
@@ -1639,6 +1739,17 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
|
|
|
1639
1739
|
const stored = switches.freshCheck ? undefined : checkStore?.read();
|
|
1640
1740
|
const storedCheck = stored && checkEnded(stored) ? stored : undefined;
|
|
1641
1741
|
const preset = stored ? checkedPreset(stored) : chosen;
|
|
1742
|
+
// A page that names a heavier preset than WebGL2 can run gets Medium with no other sign. When
|
|
1743
|
+
// the browser reports WebGPU but offers no adapter, the browser's start switch is the cause.
|
|
1744
|
+
if (DEV &&
|
|
1745
|
+
!warnedCappedPreset &&
|
|
1746
|
+
tier === 'webgl2' &&
|
|
1747
|
+
presetCapped(presetRequest.wanted, tier) &&
|
|
1748
|
+
report.webgpu.available &&
|
|
1749
|
+
!report.webgpu.compatibilityAdapter) {
|
|
1750
|
+
warnedCappedPreset = true;
|
|
1751
|
+
console.warn(`null3D: this page asked for the ${presetRequest.wanted} preset, and runs ${preset} on WebGL2. The browser reports WebGPU but offers no adapter: Chromium offers one only when it starts with --enable-unsafe-webgpu. Start the browser with that switch to draw the WebGPU presets.`);
|
|
1752
|
+
}
|
|
1642
1753
|
// Occlusion culling on the GPU needs WebGPU's compute passes. Phones and tablets run it only
|
|
1643
1754
|
// when the page asks.
|
|
1644
1755
|
const gpuOcclusion = tier === 'webgl2'
|
|
@@ -1727,7 +1838,11 @@ async function startEngine(options, switches, modes, { threaded, sketchThread },
|
|
|
1727
1838
|
if (recording && hold === undefined)
|
|
1728
1839
|
globalThis.__null3dStopRecording = stopRecording;
|
|
1729
1840
|
if (recording && renderThread === 'main')
|
|
1730
|
-
recordPermutations();
|
|
1841
|
+
recordPermutations((word) => recording.heard(word));
|
|
1842
|
+
if (renderThread === 'main')
|
|
1843
|
+
receiveMissingVariants(publishMissingWord);
|
|
1844
|
+
if (renderThread === 'main')
|
|
1845
|
+
receiveUnavailableShaders(publishUnavailableShader);
|
|
1731
1846
|
// The dev server compares each word that the page draws with against the project's list.
|
|
1732
1847
|
if (DEV && renderThread === 'main')
|
|
1733
1848
|
reportPermutations(announcePermutationWord);
|
|
@@ -13,14 +13,16 @@ declare global {
|
|
|
13
13
|
export declare class PermutationRecording {
|
|
14
14
|
private readonly drawing;
|
|
15
15
|
private readonly words;
|
|
16
|
-
/** True once the words are published, so a later answer changes nothing. */
|
|
17
|
-
private published;
|
|
18
16
|
constructor(drawing: DrawingThread);
|
|
19
17
|
/**
|
|
20
18
|
* Takes the drawing thread's words, which publishes them. Another thread that does not draw asks
|
|
21
19
|
* no pipelines for a variant, so its words wait for the drawing thread.
|
|
22
20
|
*/
|
|
23
21
|
answered(role: 'sketch' | 'render' | 'page', words: readonly number[]): void;
|
|
24
|
-
/**
|
|
22
|
+
/** Takes a word as the drawing thread finds it, and publishes the growing set at once. */
|
|
23
|
+
heard(word: number): void;
|
|
24
|
+
/** Adds a word, and says whether it was new. */
|
|
25
|
+
private add;
|
|
26
|
+
/** Publishes the words gathered so far. A live page's set grows until its tool stops it. */
|
|
25
27
|
private publish;
|
|
26
28
|
}
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
export class PermutationRecording {
|
|
8
8
|
drawing;
|
|
9
9
|
words = new Set();
|
|
10
|
-
/** True once the words are published, so a later answer changes nothing. */
|
|
11
|
-
published = false;
|
|
12
10
|
constructor(drawing) {
|
|
13
11
|
this.drawing = drawing;
|
|
14
12
|
}
|
|
@@ -18,15 +16,23 @@ export class PermutationRecording {
|
|
|
18
16
|
*/
|
|
19
17
|
answered(role, words) {
|
|
20
18
|
for (const word of words)
|
|
21
|
-
this.
|
|
19
|
+
this.add(word);
|
|
22
20
|
if (role === this.drawing)
|
|
23
21
|
this.publish();
|
|
24
22
|
}
|
|
25
|
-
/**
|
|
23
|
+
/** Takes a word as the drawing thread finds it, and publishes the growing set at once. */
|
|
24
|
+
heard(word) {
|
|
25
|
+
if (this.add(word))
|
|
26
|
+
this.publish();
|
|
27
|
+
}
|
|
28
|
+
/** Adds a word, and says whether it was new. */
|
|
29
|
+
add(word) {
|
|
30
|
+
const held = this.words.has(word >>> 0);
|
|
31
|
+
this.words.add(word >>> 0);
|
|
32
|
+
return !held;
|
|
33
|
+
}
|
|
34
|
+
/** Publishes the words gathered so far. A live page's set grows until its tool stops it. */
|
|
26
35
|
publish() {
|
|
27
|
-
if (this.published)
|
|
28
|
-
return;
|
|
29
|
-
this.published = true;
|
|
30
36
|
window.__null3dPermutations = [...this.words].sort((a, b) => a - b);
|
|
31
37
|
}
|
|
32
38
|
}
|
package/lib/quality/chooser.d.ts
CHANGED
|
@@ -70,6 +70,8 @@ export interface PresetRequest {
|
|
|
70
70
|
export declare function deviceKind(hints: DeviceHints): DeviceKind;
|
|
71
71
|
/** `preset`, or the GPU path's highest preset when `preset` is heavier. */
|
|
72
72
|
export declare function withinTier(preset: QualityPreset, tier: Tier): QualityPreset;
|
|
73
|
+
/** True when the page asked for a heavier preset than the GPU path can run. */
|
|
74
|
+
export declare function presetCapped(wanted: QualityPreset | 'auto', tier: Tier): boolean;
|
|
73
75
|
/** The preset that the hints give: the device's own, one lower when its memory reads under 4 GB. */
|
|
74
76
|
export declare function hintedPreset(hints: DeviceHints): QualityPreset;
|
|
75
77
|
/** `preset` after crashed starts: the same with none, one lower after one, and Low after two. */
|
package/lib/quality/chooser.js
CHANGED
|
@@ -62,6 +62,10 @@ export function withinTier(preset, tier) {
|
|
|
62
62
|
const ceiling = TIER_CEILINGS[tier];
|
|
63
63
|
return presetIndex(preset) <= presetIndex(ceiling) ? preset : ceiling;
|
|
64
64
|
}
|
|
65
|
+
/** True when the page asked for a heavier preset than the GPU path can run. */
|
|
66
|
+
export function presetCapped(wanted, tier) {
|
|
67
|
+
return wanted !== 'auto' && withinTier(wanted, tier) !== wanted;
|
|
68
|
+
}
|
|
65
69
|
/** The preset that the hints give: the device's own, one lower when its memory reads under 4 GB. */
|
|
66
70
|
export function hintedPreset(hints) {
|
|
67
71
|
const preset = DEVICE_PRESETS[deviceKind(hints)];
|
package/lib/shader-artifact.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"tag":"0.1.
|
|
1
|
+
{"tag":"0.1.3","file":"0.1.3-shaders.tar.br","url":"https://github.com/null3d-engine/null3d/releases/download/0.1.3/0.1.3-shaders.tar.br","sha256":"6ab4019ca61ff2b66f5cff07f62692330afc34ddbbad623c555fbc45c7a01be5"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
/** The event on the page's global object that carries a word that the page draws with. */
|
|
2
2
|
export declare const PERMUTATION_WORD_EVENT = "null3d:permutation";
|
|
3
|
+
/**
|
|
4
|
+
* The event on the page's global object that carries the GPU path that the engine started on. The
|
|
5
|
+
* dev server compares it with the paths that a production build ships, and warns when a page draws
|
|
6
|
+
* with a path that the build leaves out.
|
|
7
|
+
*/
|
|
8
|
+
export declare const GPU_PATH_EVENT = "null3d:gpu-path";
|
|
@@ -6,3 +6,9 @@
|
|
|
6
6
|
// too.
|
|
7
7
|
/** The event on the page's global object that carries a word that the page draws with. */
|
|
8
8
|
export const PERMUTATION_WORD_EVENT = 'null3d:permutation';
|
|
9
|
+
/**
|
|
10
|
+
* The event on the page's global object that carries the GPU path that the engine started on. The
|
|
11
|
+
* dev server compares it with the paths that a production build ships, and warns when a page draws
|
|
12
|
+
* with a path that the build leaves out.
|
|
13
|
+
*/
|
|
14
|
+
export const GPU_PATH_EVENT = 'null3d:gpu-path';
|
package/lib/shared/tier.d.ts
CHANGED
|
@@ -5,3 +5,12 @@
|
|
|
5
5
|
* @category api/engine
|
|
6
6
|
*/
|
|
7
7
|
export type Tier = 'webgpu' | 'webgpu-compat' | 'webgl2';
|
|
8
|
+
/**
|
|
9
|
+
* A GPU path that a build can ship: WebGPU, whose shaders are WGSL, or WebGL2, whose shaders are
|
|
10
|
+
* GLSL ES 3.00. WebGPU's compatibility mode draws with the WebGPU shaders.
|
|
11
|
+
*
|
|
12
|
+
* @category api/engine
|
|
13
|
+
*/
|
|
14
|
+
export type GpuPath = 'webgpu' | 'webgl2';
|
|
15
|
+
/** The path whose shaders a tier draws with. */
|
|
16
|
+
export declare function pathOfTier(tier: Tier): GpuPath;
|
package/lib/shared/tier.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
// The GPU paths, in a file of their own, so code without browser types can name them: the quality
|
|
2
2
|
// presets and the docs generator.
|
|
3
|
-
|
|
3
|
+
/** The path whose shaders a tier draws with. */
|
|
4
|
+
export function pathOfTier(tier) {
|
|
5
|
+
return tier === 'webgl2' ? 'webgl2' : 'webgpu';
|
|
6
|
+
}
|
package/lib/shared/version.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @category api/engine
|
|
5
5
|
*/
|
|
6
|
-
export declare const VERSION = "0.1.
|
|
6
|
+
export declare const VERSION = "0.1.3";
|
|
7
7
|
/**
|
|
8
8
|
* The version of the plugin interface that an add-on from another developer builds against. It is
|
|
9
9
|
* a whole number, and it changes only when a stable add-on hook changes, never with every engine
|
package/lib/shared/version.js
CHANGED
|
@@ -11,7 +11,7 @@ import { DEV } from './dev.js';
|
|
|
11
11
|
*
|
|
12
12
|
* @category api/engine
|
|
13
13
|
*/
|
|
14
|
-
export const VERSION = '0.1.
|
|
14
|
+
export const VERSION = '0.1.3';
|
|
15
15
|
/**
|
|
16
16
|
* The version of the plugin interface that an add-on from another developer builds against. It is
|
|
17
17
|
* a whole number, and it changes only when a stable add-on hook changes, never with every engine
|
|
@@ -188,6 +188,35 @@ export type WorkerReply = {
|
|
|
188
188
|
role: 'sketch' | 'render';
|
|
189
189
|
permutations: number[];
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* A permutation word that the drawing thread's pipelines reached while it recorded, sent as it
|
|
193
|
+
* arrives so a live page streams its growing set to the tool that records it.
|
|
194
|
+
*/
|
|
195
|
+
| {
|
|
196
|
+
type: 'recorded-word';
|
|
197
|
+
role: 'sketch' | 'render';
|
|
198
|
+
word: number;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* An object pipeline whose shader variant the loaded set lacks. Its draws draw nothing, and the
|
|
202
|
+
* page publishes the word for a production build's check.
|
|
203
|
+
*/
|
|
204
|
+
| {
|
|
205
|
+
type: 'missing-word';
|
|
206
|
+
role: 'sketch' | 'render';
|
|
207
|
+
pipeline: string;
|
|
208
|
+
word: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A pipeline or pass whose shader file failed to load. The engine draws without it, and the
|
|
212
|
+
* page warns once.
|
|
213
|
+
*/
|
|
214
|
+
| {
|
|
215
|
+
type: 'unavailable-shader';
|
|
216
|
+
role: 'sketch' | 'render';
|
|
217
|
+
pipeline: string;
|
|
218
|
+
reason: string;
|
|
219
|
+
}
|
|
191
220
|
/**
|
|
192
221
|
* In a development build, a permutation word that the drawing thread's pipelines found for the
|
|
193
222
|
* first time, which the page hands to the dev server to compare with the project's shader list.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// the engine's memory, and the next engine on the same canvas starts it again with its own.
|
|
6
6
|
import { DEV } from '../errors/checks.js';
|
|
7
7
|
import { messageOf } from '../errors/message.js';
|
|
8
|
-
import { recordPermutations, reportPermutations, stopRecordingPermutations } from '../gpu/variants.js';
|
|
8
|
+
import { receiveMissingVariants, receiveUnavailableShaders, recordPermutations, reportPermutations, stopRecordingPermutations, } from '../gpu/variants.js';
|
|
9
9
|
import { captureFrame, captureImage, startDrawing, startEarly } from '../render/draw.js';
|
|
10
10
|
import { controlViews } from '../shared/control.js';
|
|
11
11
|
import { setWakeByMessage } from '../shared/wake.js';
|
|
@@ -39,9 +39,12 @@ startWorker('render', step, async (event) => {
|
|
|
39
39
|
if (!canvas)
|
|
40
40
|
throw new Error('the page gave the render worker no canvas');
|
|
41
41
|
// A recording starts here, before the scene's draws ask for their pipelines, and the
|
|
42
|
-
// page stops it once the held frame has drawn them.
|
|
42
|
+
// page stops it once the held frame has drawn them. Each word reaches the page as it
|
|
43
|
+
// arrives, so a live page streams its growing set to the tool that records it.
|
|
43
44
|
if (message.recordPermutations)
|
|
44
|
-
recordPermutations();
|
|
45
|
+
recordPermutations((word) => replyToPage({ type: 'recorded-word', role: 'render', word }));
|
|
46
|
+
receiveMissingVariants((pipeline, word) => replyToPage({ type: 'missing-word', role: 'render', pipeline, word }));
|
|
47
|
+
receiveUnavailableShaders((pipeline, reason) => replyToPage({ type: 'unavailable-shader', role: 'render', pipeline, reason }));
|
|
45
48
|
if (DEV)
|
|
46
49
|
reportPermutations((word) => replyToPage({ type: 'permutation', word }));
|
|
47
50
|
host = new DrawingHost();
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// starts it again.
|
|
10
10
|
import { DEV } from '../errors/checks.js';
|
|
11
11
|
import { messageOf } from '../errors/message.js';
|
|
12
|
-
import { recordPermutations, reportPermutations, stopRecordingPermutations } from '../gpu/variants.js';
|
|
12
|
+
import { receiveMissingVariants, receiveUnavailableShaders, recordPermutations, reportPermutations, stopRecordingPermutations, } from '../gpu/variants.js';
|
|
13
13
|
import { loadDrawModule, preloadDrawing } from '../render/load-draw.js';
|
|
14
14
|
import { awaitLater } from '../shared/await-later.js';
|
|
15
15
|
import { controlViews } from '../shared/control.js';
|
|
@@ -157,9 +157,12 @@ startWorker('sketch', step, async (event) => {
|
|
|
157
157
|
if (message.renderer && drawModule) {
|
|
158
158
|
draw = await drawModule;
|
|
159
159
|
// This thread draws in low-latency mode, so a recording here lists the words that its
|
|
160
|
-
// pipelines ask for. The page stops it once the held frame has drawn them
|
|
160
|
+
// pipelines ask for. The page stops it once the held frame has drawn them, and each
|
|
161
|
+
// word reaches the page as it arrives.
|
|
161
162
|
if (message.renderer.recordPermutations)
|
|
162
|
-
recordPermutations();
|
|
163
|
+
recordPermutations((word) => replyToPage({ type: 'recorded-word', role: 'sketch', word }));
|
|
164
|
+
receiveMissingVariants((pipeline, word) => replyToPage({ type: 'missing-word', role: 'sketch', pipeline, word }));
|
|
165
|
+
receiveUnavailableShaders((pipeline, reason) => replyToPage({ type: 'unavailable-shader', role: 'sketch', pipeline, reason }));
|
|
163
166
|
if (DEV)
|
|
164
167
|
reportPermutations((word) => replyToPage({ type: 'permutation', word }));
|
|
165
168
|
step('renderer loaded');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@null3d/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "The null3D engine, a high-performance browser 3D engine for agents, faster than three.js, with wide device compatibility: the TypeScript API, the page shim, the worker entry points, both WebAssembly builds and the docs.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": "Ramesh Nair (https://hiddentao.com)",
|