@threenative/core 0.3.12 → 0.3.15
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 +1 -1
- package/capabilities.json +1047 -44
- package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
- package/dist/{canvas-layer-CWuFRT7G.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
- package/dist/{chunk-7UUT3TY5.js → chunk-2GPHICV6.js} +1 -1
- package/dist/{chunk-GMHATRPW.js → chunk-GEMQJBY4.js} +1650 -383
- package/dist/{chunk-VAZM36TV.js → chunk-H4J6IAJE.js} +17 -10
- package/dist/{chunk-5O73CDMR.js → chunk-QAMSM3Z5.js} +415 -27
- package/dist/{chunk-2Z44XSI2.js → chunk-QAQHYOWY.js} +3 -7
- package/dist/{chunk-DBELTTTM.js → chunk-U4YHUKKL.js} +1 -1
- package/dist/{chunk-OKXUCASC.js → chunk-VBBYWGAT.js} +3 -4
- package/dist/chunk-VP43GIWW.js +18 -0
- package/dist/{chunk-N5LRP4BR.js → chunk-VQRPEOKY.js} +66 -3
- package/dist/{chunk-6KLNISRJ.js → chunk-XDTZ4QMO.js} +11 -4
- package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
- package/dist/{game-D7pAzZUY.d.ts → game-k8K3hZai.d.ts} +72 -8
- package/dist/hot.d.ts +5 -4
- package/dist/hot.js +5 -8
- package/dist/index.d.ts +871 -1018
- package/dist/index.js +4786 -1631
- package/dist/{model-lod-B6BMqS1r.d.ts → model-lod-DPTzeCcD.d.ts} +4 -2
- package/dist/playtest.d.ts +5 -4
- package/dist/playtest.js +6 -5
- package/dist/quality-BADStsTn.d.ts +868 -0
- package/dist/react.d.ts +3 -2
- package/dist/render-environment.d.ts +170 -0
- package/dist/render-environment.js +352 -0
- package/dist/{renderer-DvFVoAgj.d.ts → renderer-BtOSseYf.d.ts} +29 -31
- package/dist/spells/index.js +1 -1
- package/dist/ui-layer.js +3 -2
- package/dist/worker.js +12 -5
- package/dist/world.d.ts +280 -16
- package/dist/world.js +1529 -642
- package/mcp/animation-server.mjs +1 -1
- package/mcp/engine-server.mjs +135 -11
- package/mcp/servers.mjs +4 -4
- package/package.json +10 -6
- package/scripts/ensure-mcp.mjs +6 -1
- package/src/animation-batch.ts +193 -0
- package/src/animation-layers.ts +7 -3
- package/src/animation.ts +209 -29
- package/src/asset-cache.ts +3 -3
- package/src/asset-memo.ts +202 -0
- package/src/assets.ts +436 -131
- package/src/auto-batch.ts +190 -44
- package/src/clustered-batch.ts +146 -3
- package/src/clustered-mesh.ts +548 -20
- package/src/compute-driven.ts +1 -1
- package/src/config.ts +8 -0
- package/src/debug.ts +119 -22
- package/src/dev-global.ts +54 -0
- package/src/displaced-surface.ts +428 -0
- package/src/engine-hooks.ts +37 -0
- package/src/frame-budget.ts +35 -3
- package/src/game-boot-phase.ts +269 -0
- package/src/game-dev-tools.ts +7 -14
- package/src/game-frame-loop.ts +45 -82
- package/src/game-startup.ts +145 -70
- package/src/game-ui.ts +84 -0
- package/src/game.ts +168 -552
- package/src/gamepad-mappings.ts +269 -0
- package/src/generated/console-markers.ts +14 -0
- package/src/geometry-capture.ts +28 -4
- package/src/gpu-readings.ts +98 -0
- package/src/gpu-scene-bvh.ts +149 -36
- package/src/grass-field.ts +628 -0
- package/src/hot.ts +4 -7
- package/src/index.ts +227 -8
- package/src/input.ts +237 -25
- package/src/instanced-batch-lod.ts +3 -8
- package/src/interpolation.ts +171 -40
- package/src/look/ao-admission.ts +4 -3
- package/src/look/auto-exposure.ts +5 -16
- package/src/look/default-tone-mapping.ts +41 -5
- package/src/look/local-exposure.ts +2 -7
- package/src/look/quad-pass.ts +21 -0
- package/src/look/quality.ts +4 -0
- package/src/look/unreal-bloom.ts +4 -13
- package/src/look/world-environment.ts +58 -115
- package/src/merge-parts.ts +20 -24
- package/src/model-lod.ts +97 -14
- package/src/particle-significance.ts +12 -0
- package/src/particles.ts +19 -10
- package/src/platform.ts +23 -4
- package/src/profiling/FrameStages.ts +5 -6
- package/src/profiling/Spans.ts +3 -17
- package/src/profiling/debug-telemetry.ts +2 -6
- package/src/profiling/render-list-validate.ts +6 -15
- package/src/projection-marker.ts +2 -1
- package/src/quiet-markers.ts +3 -10
- package/src/render/cpu-bvh.ts +100 -0
- package/src/render/depth-pyramid.ts +6 -14
- package/src/render/environment/environmentContribution.ts +202 -0
- package/src/render/environment/environmentRadiance.ts +44 -0
- package/src/render/environment/environmentSampleCache.ts +56 -0
- package/src/render/environment/environmentSampling.ts +201 -0
- package/src/render/environment/environmentSnapshot.ts +71 -0
- package/src/render/environment/gate.ts +57 -0
- package/src/render/material-key.ts +21 -1
- package/src/render/mesh-pool.ts +3 -19
- package/src/render/probe-trace.ts +872 -0
- package/src/render/probe-volume.ts +780 -34
- package/src/render/radiance-cache.ts +17 -0
- package/src/render/screen-probe-gather.ts +303 -0
- package/src/render/short-range-ao.ts +274 -0
- package/src/render/virtual-shadow-partial.ts +13 -0
- package/src/render/virtual-shadow.ts +18 -16
- package/src/render/world-impostor-surface.ts +207 -9
- package/src/render/world-impostor.ts +5 -2
- package/src/render-camera-cull.ts +105 -4
- package/src/render-environment.ts +41 -0
- package/src/renderer-config.ts +36 -0
- package/src/renderer-facts.ts +37 -0
- package/src/renderer.ts +78 -32
- package/src/resolution-scaler.ts +3 -2
- package/src/scatter-field.ts +496 -0
- package/src/scene-entry-inspectors.ts +61 -0
- package/src/snow-field.ts +1 -0
- package/src/startup-offscreen-bytes.ts +84 -0
- package/src/state.ts +16 -3
- package/src/static-transform.ts +100 -25
- package/src/streamed-textures.ts +112 -0
- package/src/streaming.ts +68 -4
- package/src/texture-streaming.ts +331 -0
- package/src/tile-ring.ts +294 -0
- package/src/version.ts +1 -1
- package/src/warmup.ts +15 -2
- package/src/worker.ts +12 -2
- package/src/world-bundle-safety.ts +55 -10
- package/src/world-cell-batches.ts +166 -200
- package/src/world-cell-chunks.ts +3 -7
- package/src/world-cell-data.ts +7 -0
- package/src/world-cell-impostors.ts +20 -8
- package/src/world-cell-models.ts +36 -8
- package/src/world-cell-options.ts +2 -14
- package/src/world-cell-placements.ts +194 -90
- package/src/world-cell-prewarm.ts +39 -4
- package/src/world-cell-records.ts +401 -0
- package/src/world-cell-render-bundles.ts +2 -2
- package/src/world-cell-render-gpu-dress.ts +17 -19
- package/src/world-cell-render-main-cull.ts +73 -17
- package/src/world-cell-render-util.ts +18 -5
- package/src/world-cell-render.ts +13 -5
- package/src/world-cell-residency.ts +15 -6
- package/src/world-cell-stale.ts +238 -0
- package/src/world-cells.ts +23 -6
- package/src/world-gpu-flags.ts +18 -50
- package/src/world-gpu-reference.ts +22 -8
- package/src/world-gpu-scene.ts +44 -24
- package/src/world-gpu-shadow.ts +21 -8
- package/src/world-gpu-types.ts +41 -13
- package/src/world-load-limiter.ts +5 -0
- package/src/world-model-sections.ts +80 -0
- package/src/world-river-ribbon.ts +273 -0
- package/src/world-root-frame.ts +39 -0
- package/src/world-shore-field.ts +91 -0
- package/src/world-static-pose.ts +163 -0
- package/src/world-surface-sampler.ts +48 -0
- package/src/world-terrain-splat.ts +10 -18
- package/src/world-tile-budget.ts +4 -11
- package/src/world-tiles.ts +79 -12
- package/src/world-validate.ts +6 -14
- package/src/world-warm.ts +51 -0
- package/src/world-water-bodies.ts +113 -3
- package/src/world.ts +13 -0
package/src/renderer-config.ts
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
1
|
import type { IThreeNativeConfig } from "./config.js";
|
|
2
2
|
import type { MatrixWorldMode } from "./matrix-world.js";
|
|
3
3
|
import type { PlatformOS } from "./platform.js";
|
|
4
|
+
import type { IRendererOptions } from "./renderer.js";
|
|
4
5
|
import { RESOLUTION_SCALER } from "./resolution-scaler.js";
|
|
5
6
|
|
|
6
7
|
type RendererConfig = NonNullable<IThreeNativeConfig["renderer"]>;
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* What `defineGame({ renderer })` accepts: the project's portable renderer config (`threenative.config.ts`
|
|
11
|
+
* `renderer`, including its `android` block and `"auto"` scale) beside the live renderer options.
|
|
12
|
+
*
|
|
13
|
+
* One key for both. `defineGame` once took the portable config as `render` and the live options as
|
|
14
|
+
* `renderer`, so a game wrote `render: config.renderer` beside a second `renderer:` and the
|
|
15
|
+
* antialias and scale resolvers each fell back from one to the other. The scale is the one field
|
|
16
|
+
* the two disagreed on, and the portable form (a number or `"auto"`) is the superset.
|
|
17
|
+
*/
|
|
18
|
+
export type GameRendererConfig = Omit<IRendererOptions, "resolutionScale" | "scaleSource"> &
|
|
19
|
+
RendererConfig;
|
|
20
|
+
|
|
21
|
+
const LEGACY_RENDER_KEY_MESSAGE =
|
|
22
|
+
'TN_GAME_RENDER_KEY_RENAMED: defineGame({ render }) is now defineGame({ renderer }). Move the object to `renderer` with no other change: preferWebGPU, antialias, alphaAntialiasing, resolutionScale (a number in (0, 1] or "auto"), the android block, matrixWorld, projection and minimumProjectedPixels keep their names and meaning, and `config.renderer` from threenative.config.ts passes through unchanged. `scaleSource` is reported by the engine and is not an input. Where a game set both keys, `render` won, so merge them with the `render` values on top.';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Adopt the retired `render` key for one release, reporting the rename it names.
|
|
26
|
+
*
|
|
27
|
+
* Dropping the key silently would lose a game's scale, sampling and Android overrides; throwing on
|
|
28
|
+
* it refuses to boot every game written against 0.3.12, `config.renderer` and all. So the values are
|
|
29
|
+
* forwarded onto `renderer` — where a game set both, `render` won, so they go on top — and the
|
|
30
|
+
* rename is reported once with the guidance that names every field and its meaning.
|
|
31
|
+
*/
|
|
32
|
+
export function adoptLegacyRenderKey<T extends object>(config: T): T {
|
|
33
|
+
const { render, ...rest } = config as T & { render?: unknown };
|
|
34
|
+
if (render === undefined) return config;
|
|
35
|
+
if (typeof render !== "object" || render === null)
|
|
36
|
+
throw new Error(
|
|
37
|
+
`TN_GAME_RENDER_KEY_INVALID: defineGame({ render }) must be an object, received ${typeof render}.`,
|
|
38
|
+
);
|
|
39
|
+
console.warn(LEGACY_RENDER_KEY_MESSAGE);
|
|
40
|
+
const renderer = (config as { renderer?: object }).renderer;
|
|
41
|
+
return { ...rest, renderer: { ...renderer, ...render } } as T;
|
|
42
|
+
}
|
|
43
|
+
|
|
8
44
|
/** How the active drawing-buffer scale was arrived at, reported beside every fps number. */
|
|
9
45
|
export type ScaleSource = "pinned" | "auto";
|
|
10
46
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a renderer is, asked in one place.
|
|
3
|
+
*
|
|
4
|
+
* The facade wraps either the owned C++ engine or upstream three, and four core subsystems used to
|
|
5
|
+
* answer that by probing the renderer's own `info` object with `"engine" in info` — a fact spelled
|
|
6
|
+
* in four files, so a rename in the engine's info table would have left them all reporting the wrong
|
|
7
|
+
* backend with nothing failing. This is the one reader.
|
|
8
|
+
*
|
|
9
|
+
* `kind` is the wrapper's own label (`"webgpu"` for either backend: three's WebGPU renderer can run
|
|
10
|
+
* a WebGL fallback behind it, which is `isWebGLFallbackRenderer`'s question, not this one).
|
|
11
|
+
*/
|
|
12
|
+
export interface IRendererFacts {
|
|
13
|
+
/** The wrapper's backend label, as `OutputRenderer.kind` reports it. */
|
|
14
|
+
readonly kind: string;
|
|
15
|
+
/** Whether the owned engine is behind the facade, rather than upstream three. */
|
|
16
|
+
readonly ownedEngine: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The renderer shape these facts are read from: a `kind` label and the raw three renderer. */
|
|
20
|
+
export interface IRendererFactSource {
|
|
21
|
+
readonly kind?: string;
|
|
22
|
+
readonly raw?: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The facts about `renderer`, from its own `info` table.
|
|
27
|
+
*
|
|
28
|
+
* A renderer with no `info` at all, or one from upstream three, is not the owned engine. A test
|
|
29
|
+
* double may pass nothing, which is the same answer.
|
|
30
|
+
*/
|
|
31
|
+
export function rendererFacts(renderer: IRendererFactSource | undefined): IRendererFacts {
|
|
32
|
+
const info = (renderer?.raw as { info?: { engine?: unknown } } | undefined)?.info;
|
|
33
|
+
return {
|
|
34
|
+
kind: renderer?.kind ?? "unknown",
|
|
35
|
+
ownedEngine: info !== undefined && info.engine !== undefined,
|
|
36
|
+
};
|
|
37
|
+
}
|
package/src/renderer.ts
CHANGED
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
} from "./render/chain.js";
|
|
44
44
|
import { type IResolutionSubrect, ResolutionSubrect } from "./render/resolution-subrect.js";
|
|
45
45
|
|
|
46
|
+
import { GPU_STALE_FRAME_LIMIT, GpuReadings } from "./gpu-readings.js";
|
|
46
47
|
import type { IStartupImageState } from "./startup-readiness.js";
|
|
47
48
|
import {
|
|
48
49
|
type IStorageBufferLease,
|
|
@@ -155,6 +156,22 @@ export function prewarm(object: Object3D | readonly Object3D[]): void {
|
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
|
|
159
|
+
/** Where one resolved frame's GPU time went, when the renderer times its own passes (the owned engine). */
|
|
160
|
+
export interface IGpuFrameSplit {
|
|
161
|
+
/** The scene (main colour) pass. */
|
|
162
|
+
readonly main: number;
|
|
163
|
+
/** Every shadow map the frame drew: the sun's and the lamps'. */
|
|
164
|
+
readonly shadow: number;
|
|
165
|
+
/** Everything else: post chain, output, global illumination gather. */
|
|
166
|
+
readonly other: number;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** One resolved GPU frame: its duration, the Three.js frame id it belongs to, and its pass split when known. */
|
|
170
|
+
export interface IGpuFrameSample extends Partial<IGpuFrameSplit> {
|
|
171
|
+
readonly frame: number;
|
|
172
|
+
readonly ms: number;
|
|
173
|
+
}
|
|
174
|
+
|
|
158
175
|
export interface IRendererLike {
|
|
159
176
|
readonly domElement: HTMLCanvasElement;
|
|
160
177
|
readonly kind: RendererKind;
|
|
@@ -375,7 +392,7 @@ export interface IRendererLike {
|
|
|
375
392
|
* resolve twice. Optional like `gpuFrameAge`, for stubs that implement only the drawing
|
|
376
393
|
* contract. `createRenderer` always provides it.
|
|
377
394
|
*/
|
|
378
|
-
gpuFrameSample?():
|
|
395
|
+
gpuFrameSample?(): IGpuFrameSample | undefined;
|
|
379
396
|
/**
|
|
380
397
|
* Observes complete allocated render-query groups without changing ordinary sampling.
|
|
381
398
|
* Frame IDs are Three query IDs, including any overlay draws; callers map world callbacks.
|
|
@@ -735,7 +752,7 @@ function wrapRenderer(
|
|
|
735
752
|
*/
|
|
736
753
|
const currentFrame = (): number | undefined =>
|
|
737
754
|
timestampFrame >= 0 ? timestampFrame : raw.info?.frame;
|
|
738
|
-
const gpuFrameSample = ():
|
|
755
|
+
const gpuFrameSample = (): IGpuFrameSample | undefined => {
|
|
739
756
|
const frame = currentFrame();
|
|
740
757
|
const frames = raw.backend?.getTimestampFrames?.("render");
|
|
741
758
|
const sampled = frames?.[frames.length - 1];
|
|
@@ -752,7 +769,19 @@ function wrapRenderer(
|
|
|
752
769
|
timestamp <= 0
|
|
753
770
|
)
|
|
754
771
|
return undefined;
|
|
755
|
-
|
|
772
|
+
// The owned engine times its own passes (`info.engine.gpuSplit`); the split joins the sample
|
|
773
|
+
// only while it describes that same frame.
|
|
774
|
+
const split = (
|
|
775
|
+
raw.info as { engine?: { gpuSplit?: IGpuFrameSplit & { frame: number } } } | undefined
|
|
776
|
+
)?.engine?.gpuSplit;
|
|
777
|
+
if (split?.frame !== sampled) return { frame: sampled, ms: timestamp };
|
|
778
|
+
return {
|
|
779
|
+
frame: sampled,
|
|
780
|
+
ms: timestamp,
|
|
781
|
+
main: split.main,
|
|
782
|
+
shadow: split.shadow,
|
|
783
|
+
other: split.other,
|
|
784
|
+
};
|
|
756
785
|
};
|
|
757
786
|
|
|
758
787
|
/**
|
|
@@ -768,6 +797,20 @@ function wrapRenderer(
|
|
|
768
797
|
};
|
|
769
798
|
|
|
770
799
|
let renderingFrame = 0;
|
|
800
|
+
// three's `compileAsync` runs a viewport texture's `updateBefore`, which copies the framebuffer from
|
|
801
|
+
// a render context the compile never bound to a target, so the backend reads the canvas
|
|
802
|
+
// (rgba8unorm) into the scene copy (rgba16float) and logs a format error per refracting material.
|
|
803
|
+
// A compile draws no pixels: the copy it triggers outside a real frame is skipped, and a frame the
|
|
804
|
+
// compile yields to still copies.
|
|
805
|
+
const copyingBackend = raw.backend as
|
|
806
|
+
| { copyFramebufferToTexture?: (...args: unknown[]) => unknown }
|
|
807
|
+
| undefined;
|
|
808
|
+
const stockFramebufferCopy = copyingBackend?.copyFramebufferToTexture;
|
|
809
|
+
if (copyingBackend !== undefined && typeof stockFramebufferCopy === "function")
|
|
810
|
+
copyingBackend.copyFramebufferToTexture = (...args: unknown[]) =>
|
|
811
|
+
activeCompiles > 0 && renderingFrame === 0
|
|
812
|
+
? undefined
|
|
813
|
+
: stockFramebufferCopy.apply(copyingBackend, args);
|
|
771
814
|
let temporalUpscaleActive = false;
|
|
772
815
|
const renderFrame = (scene: Object3D, camera: Camera): void => {
|
|
773
816
|
const temporal = wrapped.temporalUpscale?.() === true;
|
|
@@ -834,32 +877,13 @@ function wrapRenderer(
|
|
|
834
877
|
}
|
|
835
878
|
};
|
|
836
879
|
// The main pass's own GPU series, fed a frame at a time by `game.ts` because only the pass
|
|
837
|
-
// recorder can attribute the render pool to its main call. Half/half smoothing, and
|
|
838
|
-
//
|
|
839
|
-
//
|
|
840
|
-
const
|
|
841
|
-
const mainStaleLimit = 8;
|
|
842
|
-
let gpuMainEma: number | undefined;
|
|
880
|
+
// recorder can attribute the render pool to its main call. Half/half smoothing, and the engine's
|
|
881
|
+
// stale limit: the adaptive LOD loop reads this every half second and must not act on a resolve
|
|
882
|
+
// that stopped landing.
|
|
883
|
+
const mainReadings = new GpuReadings({ smoothing: 0.5, staleLimit: GPU_STALE_FRAME_LIMIT });
|
|
843
884
|
let targetFps: number | undefined;
|
|
844
|
-
let gpuMainStaleFrames = 0;
|
|
845
|
-
let gpuMainLastFrame: number | undefined;
|
|
846
885
|
const noteGpuMainMs = (ms: number | undefined, frame?: number): void => {
|
|
847
|
-
|
|
848
|
-
gpuMainStaleFrames += 1;
|
|
849
|
-
if (gpuMainStaleFrames >= mainStaleLimit) gpuMainEma = undefined;
|
|
850
|
-
};
|
|
851
|
-
if (ms === undefined || !Number.isFinite(ms) || ms < 0) {
|
|
852
|
-
stale();
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
// A repeated frame id is the previous resolve still in flight, not a new reading.
|
|
856
|
-
if (frame !== undefined && frame === gpuMainLastFrame) {
|
|
857
|
-
stale();
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
if (frame !== undefined) gpuMainLastFrame = frame;
|
|
861
|
-
gpuMainStaleFrames = 0;
|
|
862
|
-
gpuMainEma = gpuMainEma === undefined ? ms : gpuMainEma + (ms - gpuMainEma) * mainSmoothing;
|
|
886
|
+
mainReadings.note(ms, frame);
|
|
863
887
|
};
|
|
864
888
|
const wrapped: IRendererLike = {
|
|
865
889
|
get compileCount() {
|
|
@@ -1051,7 +1075,7 @@ function wrapRenderer(
|
|
|
1051
1075
|
);
|
|
1052
1076
|
return gpuObservation;
|
|
1053
1077
|
},
|
|
1054
|
-
gpuMainMs: () =>
|
|
1078
|
+
gpuMainMs: () => mainReadings.ema,
|
|
1055
1079
|
noteGpuMainMs,
|
|
1056
1080
|
targetFps: () => targetFps,
|
|
1057
1081
|
noteTargetFps: (fps: number) => {
|
|
@@ -1316,6 +1340,9 @@ function wrapRenderer(
|
|
|
1316
1340
|
prepareTextures: async (textures, signal, onProgress, replacements) => {
|
|
1317
1341
|
if (disposed) throw new Error("Renderer disposed during texture preparation.");
|
|
1318
1342
|
if (kind !== "webgpu") return 0;
|
|
1343
|
+
// The owned engine keeps compressed mip bytes in its own heap and uploads them itself: its
|
|
1344
|
+
// texture facade shows no CPU mips, so there is nothing here to stage, and no work to report.
|
|
1345
|
+
if ((raw.info as { engine?: unknown } | undefined)?.engine !== undefined) return 0;
|
|
1319
1346
|
// Snapshot the caller's iterable once. An owned replacement resolves back to its original,
|
|
1320
1347
|
// so a repeated call that hands back a published replacement keeps a stable identity instead
|
|
1321
1348
|
// of looking like an unrelated texture and returning stale work.
|
|
@@ -2086,6 +2113,9 @@ export async function createRenderer(options: IRendererOptions = {}): Promise<IR
|
|
|
2086
2113
|
// Why WebGPU did not start, when it was tried: the boot failure must name it, or a fault in the
|
|
2087
2114
|
// WebGPU path (PRD-752: a DOM-only canvas call in a worker) reads as a device without WebGPU.
|
|
2088
2115
|
let webgpuFailure: string | undefined;
|
|
2116
|
+
// The instance the WebGPU attempt built, held outside the try: a start that failed in `init()`
|
|
2117
|
+
// keeps it, and a facade that failed still holds the page's one renderer slot until it is released.
|
|
2118
|
+
let opening: RendererInstance | undefined;
|
|
2089
2119
|
|
|
2090
2120
|
if (preferWebGPU && (source?.hasWebGPU() ?? "gpu" in (globalThis.navigator ?? {}))) {
|
|
2091
2121
|
try {
|
|
@@ -2101,6 +2131,7 @@ export async function createRenderer(options: IRendererOptions = {}): Promise<IR
|
|
|
2101
2131
|
});
|
|
2102
2132
|
});
|
|
2103
2133
|
const instance = raw as RendererInstance;
|
|
2134
|
+
opening = instance;
|
|
2104
2135
|
await instance.init?.();
|
|
2105
2136
|
// A game that sets `toneMapping` on the renderer later (WorldEnvironment, Daylight) replaces this.
|
|
2106
2137
|
applyRendererToneMapping(instance, options.toneMapping ?? "filmic", report);
|
|
@@ -2125,10 +2156,25 @@ export async function createRenderer(options: IRendererOptions = {}): Promise<IR
|
|
|
2125
2156
|
if (adapter.gpuClass !== undefined)
|
|
2126
2157
|
report(`${GPU_CLASS_MARKER}:${JSON.stringify(adapter.gpuClass)}`);
|
|
2127
2158
|
} catch (error) {
|
|
2128
|
-
//
|
|
2129
|
-
//
|
|
2130
|
-
|
|
2131
|
-
|
|
2159
|
+
// Release the page's one slot before anything else: a renderer that failed to start still
|
|
2160
|
+
// holds it, so the next start in this page (a hot reload) threw TN_WASM_RENDERER_SINGLE and
|
|
2161
|
+
// hid this failure.
|
|
2162
|
+
try {
|
|
2163
|
+
opening?.dispose?.();
|
|
2164
|
+
} catch {
|
|
2165
|
+
// A half-started renderer may refuse to release; the fallback still has to be built.
|
|
2166
|
+
}
|
|
2167
|
+
// The engine names its own refusals: a TN_WASM_, TN_NATIVE_ or TN_ABI_ code is a fault in the
|
|
2168
|
+
// game's own code or its install (a background it cannot draw, a facade and Wasm engine from
|
|
2169
|
+
// two builds), and reporting it as a device without WebGPU hides the fix. A device that cannot
|
|
2170
|
+
// start is the one case TN_NO_RENDERER is for, and its reason already rides along in that
|
|
2171
|
+
// message, so the adapter, device, lost device, surface and init codes keep the fallback. The
|
|
2172
|
+
// code ends where its message does, so TN_WASM_INIT_TEXTURE and TN_WASM_DEVICE_ERROR stay the
|
|
2173
|
+
// content faults they are.
|
|
2174
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2175
|
+
const deviceFault = /^TN_WASM_(?:DEVICE_LOST|DEVICE|ADAPTER|SURFACE|INIT):/u;
|
|
2176
|
+
if (/^TN_(?:WASM|NATIVE|ABI)_/u.test(message) && !deviceFault.test(message)) throw error;
|
|
2177
|
+
webgpuFailure = message;
|
|
2132
2178
|
renderer = undefined;
|
|
2133
2179
|
}
|
|
2134
2180
|
}
|
package/src/resolution-scaler.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import type { GpuClass } from "./gpu-class.js";
|
|
18
|
+
import { GPU_READING_MAX_AGE_FRAMES, GPU_WINDOW_MIN_SAMPLES } from "./gpu-readings.js";
|
|
18
19
|
|
|
19
20
|
/** How the active scale was arrived at, reported beside every fps number. */
|
|
20
21
|
export type ScaleSource = "pinned" | "auto" | "auto-pinned";
|
|
@@ -104,9 +105,9 @@ export const RESOLUTION_SCALER = {
|
|
|
104
105
|
downWindows: 1,
|
|
105
106
|
upWindows: 4,
|
|
106
107
|
/** Eight frames for the sampled GPU reading plus eight for asynchronous query resolution. */
|
|
107
|
-
maxGpuAgeFrames:
|
|
108
|
+
maxGpuAgeFrames: GPU_READING_MAX_AGE_FRAMES,
|
|
108
109
|
/** Window GPU samples that make the window's own median fresh evidence; see `IScalerWindow.gpu`. */
|
|
109
|
-
minWindowGpuSamples:
|
|
110
|
+
minWindowGpuSamples: GPU_WINDOW_MIN_SAMPLES,
|
|
110
111
|
/** The resize frame is itself a hitch and must never feed the controller. */
|
|
111
112
|
cooldownWindows: 1,
|
|
112
113
|
/** Continuous sub-rectangle changes are separated by this many rendered frames. */
|