@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.
Files changed (165) hide show
  1. package/README.md +1 -1
  2. package/capabilities.json +1047 -44
  3. package/dist/{assets-YUbXa3-Y.d.ts → assets-CfMKnOsK.d.ts} +78 -1
  4. package/dist/{canvas-layer-CWuFRT7G.d.ts → canvas-layer-G7ttVy7y.d.ts} +1 -1
  5. package/dist/{chunk-7UUT3TY5.js → chunk-2GPHICV6.js} +1 -1
  6. package/dist/{chunk-GMHATRPW.js → chunk-GEMQJBY4.js} +1650 -383
  7. package/dist/{chunk-VAZM36TV.js → chunk-H4J6IAJE.js} +17 -10
  8. package/dist/{chunk-5O73CDMR.js → chunk-QAMSM3Z5.js} +415 -27
  9. package/dist/{chunk-2Z44XSI2.js → chunk-QAQHYOWY.js} +3 -7
  10. package/dist/{chunk-DBELTTTM.js → chunk-U4YHUKKL.js} +1 -1
  11. package/dist/{chunk-OKXUCASC.js → chunk-VBBYWGAT.js} +3 -4
  12. package/dist/chunk-VP43GIWW.js +18 -0
  13. package/dist/{chunk-N5LRP4BR.js → chunk-VQRPEOKY.js} +66 -3
  14. package/dist/{chunk-6KLNISRJ.js → chunk-XDTZ4QMO.js} +11 -4
  15. package/dist/default-tone-mapping-GgKPTiBP.d.ts +4 -0
  16. package/dist/{game-D7pAzZUY.d.ts → game-k8K3hZai.d.ts} +72 -8
  17. package/dist/hot.d.ts +5 -4
  18. package/dist/hot.js +5 -8
  19. package/dist/index.d.ts +871 -1018
  20. package/dist/index.js +4786 -1631
  21. package/dist/{model-lod-B6BMqS1r.d.ts → model-lod-DPTzeCcD.d.ts} +4 -2
  22. package/dist/playtest.d.ts +5 -4
  23. package/dist/playtest.js +6 -5
  24. package/dist/quality-BADStsTn.d.ts +868 -0
  25. package/dist/react.d.ts +3 -2
  26. package/dist/render-environment.d.ts +170 -0
  27. package/dist/render-environment.js +352 -0
  28. package/dist/{renderer-DvFVoAgj.d.ts → renderer-BtOSseYf.d.ts} +29 -31
  29. package/dist/spells/index.js +1 -1
  30. package/dist/ui-layer.js +3 -2
  31. package/dist/worker.js +12 -5
  32. package/dist/world.d.ts +280 -16
  33. package/dist/world.js +1529 -642
  34. package/mcp/animation-server.mjs +1 -1
  35. package/mcp/engine-server.mjs +135 -11
  36. package/mcp/servers.mjs +4 -4
  37. package/package.json +10 -6
  38. package/scripts/ensure-mcp.mjs +6 -1
  39. package/src/animation-batch.ts +193 -0
  40. package/src/animation-layers.ts +7 -3
  41. package/src/animation.ts +209 -29
  42. package/src/asset-cache.ts +3 -3
  43. package/src/asset-memo.ts +202 -0
  44. package/src/assets.ts +436 -131
  45. package/src/auto-batch.ts +190 -44
  46. package/src/clustered-batch.ts +146 -3
  47. package/src/clustered-mesh.ts +548 -20
  48. package/src/compute-driven.ts +1 -1
  49. package/src/config.ts +8 -0
  50. package/src/debug.ts +119 -22
  51. package/src/dev-global.ts +54 -0
  52. package/src/displaced-surface.ts +428 -0
  53. package/src/engine-hooks.ts +37 -0
  54. package/src/frame-budget.ts +35 -3
  55. package/src/game-boot-phase.ts +269 -0
  56. package/src/game-dev-tools.ts +7 -14
  57. package/src/game-frame-loop.ts +45 -82
  58. package/src/game-startup.ts +145 -70
  59. package/src/game-ui.ts +84 -0
  60. package/src/game.ts +168 -552
  61. package/src/gamepad-mappings.ts +269 -0
  62. package/src/generated/console-markers.ts +14 -0
  63. package/src/geometry-capture.ts +28 -4
  64. package/src/gpu-readings.ts +98 -0
  65. package/src/gpu-scene-bvh.ts +149 -36
  66. package/src/grass-field.ts +628 -0
  67. package/src/hot.ts +4 -7
  68. package/src/index.ts +227 -8
  69. package/src/input.ts +237 -25
  70. package/src/instanced-batch-lod.ts +3 -8
  71. package/src/interpolation.ts +171 -40
  72. package/src/look/ao-admission.ts +4 -3
  73. package/src/look/auto-exposure.ts +5 -16
  74. package/src/look/default-tone-mapping.ts +41 -5
  75. package/src/look/local-exposure.ts +2 -7
  76. package/src/look/quad-pass.ts +21 -0
  77. package/src/look/quality.ts +4 -0
  78. package/src/look/unreal-bloom.ts +4 -13
  79. package/src/look/world-environment.ts +58 -115
  80. package/src/merge-parts.ts +20 -24
  81. package/src/model-lod.ts +97 -14
  82. package/src/particle-significance.ts +12 -0
  83. package/src/particles.ts +19 -10
  84. package/src/platform.ts +23 -4
  85. package/src/profiling/FrameStages.ts +5 -6
  86. package/src/profiling/Spans.ts +3 -17
  87. package/src/profiling/debug-telemetry.ts +2 -6
  88. package/src/profiling/render-list-validate.ts +6 -15
  89. package/src/projection-marker.ts +2 -1
  90. package/src/quiet-markers.ts +3 -10
  91. package/src/render/cpu-bvh.ts +100 -0
  92. package/src/render/depth-pyramid.ts +6 -14
  93. package/src/render/environment/environmentContribution.ts +202 -0
  94. package/src/render/environment/environmentRadiance.ts +44 -0
  95. package/src/render/environment/environmentSampleCache.ts +56 -0
  96. package/src/render/environment/environmentSampling.ts +201 -0
  97. package/src/render/environment/environmentSnapshot.ts +71 -0
  98. package/src/render/environment/gate.ts +57 -0
  99. package/src/render/material-key.ts +21 -1
  100. package/src/render/mesh-pool.ts +3 -19
  101. package/src/render/probe-trace.ts +872 -0
  102. package/src/render/probe-volume.ts +780 -34
  103. package/src/render/radiance-cache.ts +17 -0
  104. package/src/render/screen-probe-gather.ts +303 -0
  105. package/src/render/short-range-ao.ts +274 -0
  106. package/src/render/virtual-shadow-partial.ts +13 -0
  107. package/src/render/virtual-shadow.ts +18 -16
  108. package/src/render/world-impostor-surface.ts +207 -9
  109. package/src/render/world-impostor.ts +5 -2
  110. package/src/render-camera-cull.ts +105 -4
  111. package/src/render-environment.ts +41 -0
  112. package/src/renderer-config.ts +36 -0
  113. package/src/renderer-facts.ts +37 -0
  114. package/src/renderer.ts +78 -32
  115. package/src/resolution-scaler.ts +3 -2
  116. package/src/scatter-field.ts +496 -0
  117. package/src/scene-entry-inspectors.ts +61 -0
  118. package/src/snow-field.ts +1 -0
  119. package/src/startup-offscreen-bytes.ts +84 -0
  120. package/src/state.ts +16 -3
  121. package/src/static-transform.ts +100 -25
  122. package/src/streamed-textures.ts +112 -0
  123. package/src/streaming.ts +68 -4
  124. package/src/texture-streaming.ts +331 -0
  125. package/src/tile-ring.ts +294 -0
  126. package/src/version.ts +1 -1
  127. package/src/warmup.ts +15 -2
  128. package/src/worker.ts +12 -2
  129. package/src/world-bundle-safety.ts +55 -10
  130. package/src/world-cell-batches.ts +166 -200
  131. package/src/world-cell-chunks.ts +3 -7
  132. package/src/world-cell-data.ts +7 -0
  133. package/src/world-cell-impostors.ts +20 -8
  134. package/src/world-cell-models.ts +36 -8
  135. package/src/world-cell-options.ts +2 -14
  136. package/src/world-cell-placements.ts +194 -90
  137. package/src/world-cell-prewarm.ts +39 -4
  138. package/src/world-cell-records.ts +401 -0
  139. package/src/world-cell-render-bundles.ts +2 -2
  140. package/src/world-cell-render-gpu-dress.ts +17 -19
  141. package/src/world-cell-render-main-cull.ts +73 -17
  142. package/src/world-cell-render-util.ts +18 -5
  143. package/src/world-cell-render.ts +13 -5
  144. package/src/world-cell-residency.ts +15 -6
  145. package/src/world-cell-stale.ts +238 -0
  146. package/src/world-cells.ts +23 -6
  147. package/src/world-gpu-flags.ts +18 -50
  148. package/src/world-gpu-reference.ts +22 -8
  149. package/src/world-gpu-scene.ts +44 -24
  150. package/src/world-gpu-shadow.ts +21 -8
  151. package/src/world-gpu-types.ts +41 -13
  152. package/src/world-load-limiter.ts +5 -0
  153. package/src/world-model-sections.ts +80 -0
  154. package/src/world-river-ribbon.ts +273 -0
  155. package/src/world-root-frame.ts +39 -0
  156. package/src/world-shore-field.ts +91 -0
  157. package/src/world-static-pose.ts +163 -0
  158. package/src/world-surface-sampler.ts +48 -0
  159. package/src/world-terrain-splat.ts +10 -18
  160. package/src/world-tile-budget.ts +4 -11
  161. package/src/world-tiles.ts +79 -12
  162. package/src/world-validate.ts +6 -14
  163. package/src/world-warm.ts +51 -0
  164. package/src/world-water-bodies.ts +113 -3
  165. package/src/world.ts +13 -0
@@ -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?(): { readonly frame: number; readonly ms: number } | undefined;
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 = (): { frame: number; ms: number } | undefined => {
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
- return { frame: sampled, ms: timestamp };
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 a short
838
- // freshness window: the adaptive LOD loop reads this every half second and must not act on a
839
- // resolve that stopped landing.
840
- const mainSmoothing = 0.5;
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
- const stale = (): void => {
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: () => gpuMainEma,
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
- // A facade and Wasm engine from two builds is an install fault, not a device without
2129
- // WebGPU: falling back would report TN_NO_RENDERER and hide the fix.
2130
- if (error instanceof Error && error.message.startsWith("TN_WASM_ABI_MISMATCH")) throw error;
2131
- webgpuFailure = error instanceof Error ? error.message : String(error);
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
  }
@@ -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: 16,
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: 4,
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. */