@threenative/core 0.3.8 → 0.3.10

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.
@@ -6,7 +6,7 @@ import { createRequire } from "node:module";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
 
9
- const THREE_VERSION = "0.185.1";
9
+ const THREE_VERSION = "0.187.0";
10
10
  const PATCH_NAME = `three@${THREE_VERSION}.patch`;
11
11
  const UPGRADE_PATCH_NAME = `three@${THREE_VERSION}-prd269-upgrade.patch`;
12
12
 
@@ -322,7 +322,9 @@ function classifyFile(lines, hunks) {
322
322
  else if (locate(lines, oldLines, hunk.oldStart - 1 + offset) !== undefined)
323
323
  states.push("stock");
324
324
  else states.push("unknown");
325
- offset += newLines.length - oldLines.length;
325
+ // Classification reads the file as it is on disk, where only already-patched hunks moved the
326
+ // lines below them; a stock hunk has not been applied yet and shifts nothing.
327
+ if (states.at(-1) === "patched") offset += newLines.length - oldLines.length;
326
328
  }
327
329
  return states;
328
330
  }
@@ -108,6 +108,8 @@ export class GpuFrameObservation implements IGpuFrameObservation {
108
108
  #stopFrame: number | undefined;
109
109
  #failure: string | undefined;
110
110
  #pool: IPool | undefined;
111
+ #watched = new WeakSet<object>();
112
+ #wrapped = false;
111
113
  #batches = new Map<number, IBatch>();
112
114
  #queue: IGpuObservedFrame[] = [];
113
115
  #nextBatch = 0;
@@ -152,6 +154,26 @@ export class GpuFrameObservation implements IGpuFrameObservation {
152
154
  throw new Error(`${PREFIX}LIMITS`);
153
155
  this.#maxFrames = options.maxFrames;
154
156
  this.#maxQueries = options.maxQueries;
157
+ this.#watch(getPool());
158
+ }
159
+ /**
160
+ * three 0.187 never leaves a pool full: an allocation past `maxQueries` resolves the pool by itself and
161
+ * restarts at slot 0, so the earlier queries vanish without a trace. Allocation is the one place a restart
162
+ * shows, as the index going backwards; r185 returned null there and left the pool full instead.
163
+ */
164
+ #watch(value: unknown) {
165
+ const pool = value as
166
+ | { currentQueryIndex?: number; allocateQueriesForContext?: unknown }
167
+ | undefined;
168
+ if (typeof pool?.allocateQueriesForContext !== "function" || this.#watched.has(pool)) return;
169
+ this.#watched.add(pool);
170
+ const allocate = pool.allocateQueriesForContext as (...args: unknown[]) => unknown;
171
+ pool.allocateQueriesForContext = (...args: unknown[]) => {
172
+ const before = pool.currentQueryIndex ?? 0;
173
+ const result = allocate.apply(pool, args);
174
+ if ((pool.currentQueryIndex ?? 0) < before) this.#wrapped = true;
175
+ return result;
176
+ };
155
177
  }
156
178
  #fail(reason: string) {
157
179
  if (this.#state === "failed" || this.#state === "disposed") return;
@@ -175,6 +197,7 @@ export class GpuFrameObservation implements IGpuFrameObservation {
175
197
  }
176
198
  #refreshUndrained(): IBatch | undefined {
177
199
  const value = this.getPool();
200
+ this.#watch(value);
178
201
  if (value === undefined && this.#pool === undefined) return;
179
202
  const pool = readPool(value);
180
203
  if (this.#pool !== undefined && this.#pool !== pool) throw new Error(`${PREFIX}POOL_RESET`);
@@ -219,7 +242,7 @@ export class GpuFrameObservation implements IGpuFrameObservation {
219
242
  const slots = [...selected.values()].reduce((sum, group) => sum + group.length * 2, 0);
220
243
  this.#undrainedFrames = selected.size;
221
244
  this.#undrainedQueries = slots;
222
- if (pool.currentQueryIndex >= pool.maxQueries) {
245
+ if (pool.currentQueryIndex >= pool.maxQueries || this.#wrapped) {
223
246
  this.#allocationLoss = "unknown-after-saturation";
224
247
  throw new Error(`${PREFIX}SATURATED_POOL`);
225
248
  }
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * unavoidable here — core is bundled for browsers and cannot read `package.json` at runtime — so
7
7
  * the spec now asserts this equals the manifest instead of asserting a number somebody typed.
8
8
  */
9
- export const version = "0.3.8";
9
+ export const version = "0.3.10";
10
10
 
11
11
  /**
12
12
  * Play a skinned or sprite animation from game code.
@@ -4,14 +4,13 @@
4
4
  import { type RenderTarget, Texture, Vector2 } from "three";
5
5
  import { float, ivec2, nodeObject, texture, textureLoad, uniform, vec4 } from "three/tsl";
6
6
  import {
7
- type Node,
7
+ Node,
8
8
  type NodeBuilder,
9
9
  type NodeFrame,
10
10
  NodeMaterial,
11
11
  NodeUpdateType,
12
12
  QuadMesh,
13
13
  RendererUtils,
14
- TempNode,
15
14
  } from "three/webgpu";
16
15
  import {
17
16
  type IExposureSettings,
@@ -42,7 +41,7 @@ export function applyExposure(colour: Node<"vec4">, exposure: Node<"float">): No
42
41
  }
43
42
 
44
43
  /** Owns scratch targets only. Never draws the world or installs another output transform. */
45
- export class AutoExposureNode extends TempNode<"float"> {
44
+ export class AutoExposureNode extends Node<"float"> {
46
45
  static get type(): string {
47
46
  return "AutoExposureNode";
48
47
  }
@@ -61,7 +60,7 @@ export class AutoExposureNode extends TempNode<"float"> {
61
60
  readonly #seed = uniform(0);
62
61
  readonly #enabled = uniform(false);
63
62
  readonly #bias = uniform(0);
64
- readonly #quad = new QuadMesh();
63
+ readonly #quad: QuadMesh;
65
64
  readonly #meterMaterial = new NodeMaterial();
66
65
  readonly #reduceMaterial = new NodeMaterial();
67
66
  readonly #tilesMaterial = new NodeMaterial();
@@ -117,6 +116,8 @@ export class AutoExposureNode extends TempNode<"float"> {
117
116
  decode,
118
117
  this.#bias,
119
118
  );
119
+ // Three 0.187's QuadMesh takes its material in the constructor; each pass replaces it before drawing.
120
+ this.#quad = new QuadMesh(this.#meterMaterial);
120
121
  }
121
122
 
122
123
  override setup(builder: NodeBuilder): Node<"float"> {
@@ -9,16 +9,15 @@ import {
9
9
  mix,
10
10
  screenCoordinate,
11
11
  smoothstep,
12
- type texture,
13
12
  textureLoad,
14
13
  textureSize,
15
14
  vec2,
16
15
  vec4,
17
16
  } from "three/tsl";
18
- import type { Node } from "three/webgpu";
17
+ import type { Node, TextureNode } from "three/webgpu";
19
18
  import type { IExposureSettings } from "./exposure-settings.js";
20
19
 
21
- export type ColourTexture = ReturnType<typeof texture>;
20
+ export type ColourTexture = TextureNode;
22
21
  export type Meter = (colour: Node<"vec4">, uv: Node<"vec2">) => Node<"vec2">;
23
22
  export type Decode = (mean: Node<"float">) => Node<"float">;
24
23
 
@@ -835,6 +835,18 @@ export function filmicToneMappingNode(
835
835
  };
836
836
  }
837
837
 
838
+ /**
839
+ * The curve each renderer's library already holds, by its options.
840
+ *
841
+ * `createRenderer` installs Unreal's curve as the default and a `WorldEnvironment` installs it again
842
+ * for `tonemapMode: "filmic"`, so the same curve reaches the same library twice. r187's
843
+ * `NodeLibrary.addType` keeps the first registration and warns `Redefinition of node 5` for the
844
+ * second (src/renderers/common/nodes/NodeLibrary.js:158). Registering each curve once per library
845
+ * leaves the frame identical and the console clean; a *different* curve still registers (and still
846
+ * warns), because three keeps whichever came first.
847
+ */
848
+ const installedCurves = new WeakMap<object, string>();
849
+
838
850
  /**
839
851
  * Registers the curve with a WebGPU renderer and returns the tone-mapping constant to assign.
840
852
  * A renderer without a node library (the WebGL fallback) keeps ACES and says so.
@@ -847,6 +859,10 @@ export function installFilmicToneMapping(
847
859
  const library = (raw as { library?: { addToneMapping?(node: unknown, mode: number): void } })
848
860
  .library;
849
861
  if (library?.addToneMapping === undefined) return undefined;
850
- library.addToneMapping(filmicToneMappingNode(c, grade), CustomToneMapping);
862
+ const curve = JSON.stringify([c, grade]);
863
+ if (installedCurves.get(library) !== curve) {
864
+ library.addToneMapping(filmicToneMappingNode(c, grade), CustomToneMapping);
865
+ installedCurves.set(library, curve);
866
+ }
851
867
  return CustomToneMapping;
852
868
  }
@@ -22,18 +22,18 @@ import {
22
22
  vec4,
23
23
  } from "three/tsl";
24
24
  import {
25
- type Node,
25
+ Node,
26
26
  type NodeBuilder,
27
27
  type NodeFrame,
28
28
  NodeMaterial,
29
29
  NodeUpdateType,
30
30
  QuadMesh,
31
31
  RendererUtils,
32
- TempNode,
32
+ type TextureNode,
33
33
  } from "three/webgpu";
34
34
  import { exposureMeter, exposureSettings } from "./exposure-settings.js";
35
35
 
36
- type ColourTexture = ReturnType<typeof texture>;
36
+ type ColourTexture = TextureNode;
37
37
 
38
38
  /** The look: change a number here, not the passes below. */
39
39
  const localExposureSettings = {
@@ -123,7 +123,7 @@ function mirror(u: Node<"float">): Node<"float"> {
123
123
  }
124
124
 
125
125
  /** Owns scratch targets only. Never draws the world or installs another output transform. */
126
- export class LocalExposureNode extends TempNode<"float"> {
126
+ export class LocalExposureNode extends Node<"float"> {
127
127
  static get type(): string {
128
128
  return "LocalExposureNode";
129
129
  }
@@ -139,7 +139,7 @@ export class LocalExposureNode extends TempNode<"float"> {
139
139
  readonly #blurSize = uniform(new Vector2(1, 1));
140
140
  readonly #blurRadius = uniform(BLUR_RADIUS);
141
141
  readonly #rangeStride = uniform(1);
142
- readonly #quad = new QuadMesh();
142
+ readonly #quad: QuadMesh;
143
143
  readonly #logMaterial = new NodeMaterial();
144
144
  readonly #lumMaterial = new NodeMaterial();
145
145
  readonly #blurXMaterial = new NodeMaterial();
@@ -362,6 +362,8 @@ export class LocalExposureNode extends TempNode<"float"> {
362
362
  });
363
363
  return sum;
364
364
  })();
365
+ // Three 0.187's QuadMesh takes its material in the constructor; each pass replaces it before drawing.
366
+ this.#quad = new QuadMesh(this.#logMaterial);
365
367
  }
366
368
 
367
369
  override setup(builder: NodeBuilder): Node<"float"> {
@@ -1,17 +1,17 @@
1
1
  import { HalfFloatType, LinearFilter, RenderTarget, Vector2 } from "three";
2
2
  import { Fn, Loop, float, nodeObject, texture, uniform, uv, vec2, vec3, vec4 } from "three/tsl";
3
3
  import {
4
- type Node,
4
+ Node,
5
5
  type NodeBuilder,
6
6
  type NodeFrame,
7
7
  NodeMaterial,
8
8
  NodeUpdateType,
9
9
  QuadMesh,
10
10
  RendererUtils,
11
- TempNode,
11
+ type TextureNode,
12
12
  } from "three/webgpu";
13
13
 
14
- type ColourTexture = ReturnType<typeof texture>;
14
+ type ColourTexture = TextureNode;
15
15
 
16
16
  /** The look: Scene.cpp defaults. Stage 1 is the tightest, stage 6 the widest. */
17
17
  const unrealBloomSettings = {
@@ -95,7 +95,7 @@ interface IStage {
95
95
  }
96
96
 
97
97
  /** Owns scratch targets only. Never draws the world or installs another output transform. */
98
- export class UnrealBloomNode extends TempNode<"vec3"> {
98
+ export class UnrealBloomNode extends Node<"vec3"> {
99
99
  static get type(): string {
100
100
  return "UnrealBloomNode";
101
101
  }
@@ -103,7 +103,7 @@ export class UnrealBloomNode extends TempNode<"vec3"> {
103
103
  static readonly schedule = bloomSchedule;
104
104
  readonly input: ColourTexture;
105
105
  readonly #size = new Vector2();
106
- readonly #quad = new QuadMesh();
106
+ readonly #quad: QuadMesh;
107
107
  readonly #downMaterials: NodeMaterial[] = [];
108
108
  readonly #downTargets: RenderTarget[] = [];
109
109
  readonly #downTextures: ColourTexture[] = [];
@@ -142,6 +142,8 @@ export class UnrealBloomNode extends TempNode<"vec3"> {
142
142
  })();
143
143
  this.#downMaterials.push(material);
144
144
  }
145
+ // Three 0.187's QuadMesh takes its material in the constructor; each pass replaces it before drawing.
146
+ this.#quad = new QuadMesh(this.#downMaterials[0] as NodeMaterial);
145
147
  // Stage 1 is Bloom1 (tightest, level 1); stage 6 is Bloom6 (widest, level 6). Unreal runs them
146
148
  // widest first, each adding the one before it.
147
149
  const { sizes, tints, intensity, gaussianIntensity } = unrealBloomSettings;
@@ -600,13 +600,14 @@ function stage(definition: {
600
600
  }
601
601
 
602
602
  /**
603
- * `three/addons` declares each TSL stage as its raw node class, and `DenoiseNode` is the only
604
- * one in this chain whose declaration omits the element API (`.mul`, `.rgb`, `.r`) that the
605
- * proxied node object it actually hands back at runtime carries — every other stage here is a
606
- * `ChainNode` on its own, checked by the compiler. This is an assertion and nothing else: no
607
- * conversion runs, no node is added to the graph, so it cannot move a pixel.
603
+ * `three/addons` declares these as raw nodes: `DenoiseNode` for the filter, and the SSGI gather's
604
+ * own `TextureNode` outputs, typed at their channel count rather than as the vec4 the chain reads.
605
+ * Their declarations omit element API (`.mul`, `.rgb`, `.r`) that the proxied node object they
606
+ * hand back at runtime carries — every other stage here is a `ChainNode` on its own, checked by the
607
+ * compiler. This is an assertion and nothing else: no conversion runs, no node is added to the
608
+ * graph, so it cannot move a pixel.
608
609
  */
609
- function denoised(node: ReturnType<typeof denoise>): ChainNode {
610
+ function denoised(node: Node): ChainNode {
610
611
  return node as typeof node & ChainNode;
611
612
  }
612
613
  type OutputInstallation = { isCurrent(): boolean; dispose(): void };
@@ -1126,9 +1127,9 @@ export class WorldEnvironment {
1126
1127
  sample(texture);
1127
1128
  return texture;
1128
1129
  };
1129
- const giDenoise = (node: ChainNode): ChainNode => {
1130
- if (!options.denoiseEnabled) return node;
1131
- let result = node;
1130
+ const giDenoise = (node: ChainNode | Node<"float"> | Node<"vec3">): ChainNode => {
1131
+ let result = denoised(node);
1132
+ if (!options.denoiseEnabled) return result;
1132
1133
  for (let pass = 0; pass < options.giDenoisePasses; pass += 1) {
1133
1134
  const filter = denoise(result, depth(), normal(), view) as {
1134
1135
  gpuStage?: string;
@@ -971,12 +971,28 @@ export class PipelineCensus {
971
971
  pipeline,
972
972
  compute,
973
973
  renderObject: undefined,
974
- mode: "sync",
974
+ mode: asyncPromises(args[2]).length > 0 ? "async" : "sync",
975
975
  });
976
976
  const started = this.#now();
977
977
  try {
978
978
  const result = this.#throughBackend(() => original.apply(backend, [...args]));
979
- this.#settleEvent(backend, event, started, undefined);
979
+ // Three creates a compute pipeline asynchronously when it is handed a compilation promise
980
+ // list, which is what `compileComputeAsync` does (src/renderers/common/Renderer.js:1359), and
981
+ // installs the handle only when that promise resolves. Read it then, not before: three calls
982
+ // the device synchronously in both paths, so the settle order is the only difference.
983
+ const promises = asyncPromises(args[2]);
984
+ if (promises.length > 0) {
985
+ event.mode = "async";
986
+ event.status = "pending";
987
+ event.pending = true;
988
+ this.#pending += 1;
989
+ void Promise.all(promises).then(
990
+ () => this.#settleEvent(backend, event, started, undefined),
991
+ (error: unknown) => this.#settleEvent(backend, event, started, error),
992
+ );
993
+ } else {
994
+ this.#settleEvent(backend, event, started, undefined);
995
+ }
980
996
  return result;
981
997
  } catch (error) {
982
998
  this.#settleEvent(backend, event, started, error);
@@ -4,7 +4,8 @@ const THREE_NATIVE_BATCHED_VELOCITY_PATCH = "threeNativeBatchedVelocityPatch";
4
4
 
5
5
  interface IBatchedMeshVelocityState {
6
6
  _matricesTexture: Texture | null;
7
- _previousMatricesTexture?: Texture;
7
+ /** Three.js 0.187 owns this field and sets it to `null` while no previous texture exists. */
8
+ _previousMatricesTexture?: Texture | null;
8
9
  }
9
10
 
10
11
  interface IBatchedMatrixImage {
@@ -34,7 +35,7 @@ function state(mesh: BatchedMesh): IBatchedMeshVelocityState {
34
35
  export function ensureBatchedMeshVelocity(mesh: BatchedMesh): void {
35
36
  const current = state(mesh)._matricesTexture;
36
37
  if (current === null) throw new Error("BatchedMesh has no current matrix texture.");
37
- if (state(mesh)._previousMatricesTexture !== undefined) return;
38
+ if (state(mesh)._previousMatricesTexture != null) return;
38
39
  const image = matrixImage(current);
39
40
  const previous = new DataTexture(
40
41
  image.data.slice(),
@@ -105,12 +106,12 @@ export function setBatchedMeshPreviousMatrices(
105
106
  export function disposeBatchedMeshVelocity(mesh: BatchedMesh): void {
106
107
  const previous = state(mesh)._previousMatricesTexture;
107
108
  previous?.dispose();
108
- state(mesh)._previousMatricesTexture = undefined;
109
+ state(mesh)._previousMatricesTexture = null;
109
110
  }
110
111
 
111
112
  /** Returns the previous texture for focused conformance tests and renderer adapters. */
112
113
  export function readBatchedMeshPreviousMatrices(mesh: BatchedMesh): Texture | undefined {
113
- return state(mesh)._previousMatricesTexture;
114
+ return state(mesh)._previousMatricesTexture ?? undefined;
114
115
  }
115
116
 
116
117
  function matrixImage(texture: Texture): IBatchedMatrixImage {
@@ -43,7 +43,7 @@ import {
43
43
  RenderTarget,
44
44
  RenderTarget3D,
45
45
  } from "three/webgpu";
46
- import type { Node } from "three/webgpu";
46
+ import type { Node, TextureNode } from "three/webgpu";
47
47
  import type { IComputeDriven } from "../compute-driven.js";
48
48
  import type { IRendererLike } from "../renderer.js";
49
49
 
@@ -292,7 +292,7 @@ export class ProbeVolume extends Object3D implements IComputeDriven {
292
292
  #projectionMaterial: NodeMaterial | undefined;
293
293
  #repackMaterials: NodeMaterial[] | undefined;
294
294
  #repackSlice = uniform(0, "int");
295
- #batchTextureNode: ReturnType<typeof texture> | undefined;
295
+ #batchTextureNode: TextureNode | undefined;
296
296
  #gpuWarmupStarted = false;
297
297
  #gpuWarmupSettled = true;
298
298
  #sceneWarmupStarted = false;
@@ -1484,7 +1484,7 @@ function createProjectionMaterial(cubeTarget: CubeRenderTarget, cubemapSize: num
1484
1484
  }
1485
1485
 
1486
1486
  function createRepackMaterials(
1487
- batchTextureNode: ReturnType<typeof texture>,
1487
+ batchTextureNode: TextureNode,
1488
1488
  slice: Node<"int">,
1489
1489
  dimensions: Vector3,
1490
1490
  probeCount: number,
@@ -5,7 +5,6 @@ import {
5
5
  HalfFloatType,
6
6
  Mesh,
7
7
  NoToneMapping,
8
- type RenderTarget,
9
8
  Scene,
10
9
  SphereGeometry,
11
10
  type Texture,
@@ -85,7 +84,7 @@ export class SkyCapture {
85
84
  readonly #mask: Scene | undefined;
86
85
  readonly #maskMesh: Mesh<SphereGeometry, MeshBasicNodeMaterial> | undefined;
87
86
  #pmrem: PMREMGenerator | undefined;
88
- #filtered: RenderTarget | undefined;
87
+ #filtered: CubeRenderTarget | undefined;
89
88
  #disposed = false;
90
89
 
91
90
  constructor(
@@ -23,13 +23,12 @@ import {
23
23
  reference,
24
24
  sqrt,
25
25
  step,
26
- type texture,
27
26
  textureLoad,
28
27
  uniform,
29
28
  vec2,
30
29
  vec3,
31
30
  } from "three/tsl";
32
- import type { Node } from "three/webgpu";
31
+ import type { Node, TextureNode } from "three/webgpu";
33
32
 
34
33
  /** tan(5 degrees): Unreal's `r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle`, the sun's least source on a leaf. */
35
34
  export const LEAF_MIN_SOURCE_TANGENT = Math.tan((5 * Math.PI) / 180);
@@ -215,8 +214,7 @@ export function sourceAngleShadowFilter({
215
214
  ).div(reference("zoom", "float", camera));
216
215
  const texel = vec2(1).div(size);
217
216
  const isArray = "isArrayTexture" in depthTexture && depthTexture.isArrayTexture === true;
218
- const withLayer = (sample: ReturnType<typeof texture>) =>
219
- isArray ? sample.depth(float(depthLayer)) : sample;
217
+ const withLayer = (sample: TextureNode) => (isArray ? sample.depth(float(depthLayer)) : sample);
220
218
  const linearDepth = (depth: Node<"float">) => (reversed ? depth.oneMinus() : depth);
221
219
  return Fn(
222
220
  (_inputs: unknown, builder: { readonly material?: Parameters<typeof isLeafReceiver>[0] }) => {
@@ -21,7 +21,7 @@ import {
21
21
  vec3,
22
22
  vec4,
23
23
  } from "three/tsl";
24
- import type { Node } from "three/webgpu";
24
+ import type { Node, TextureNode } from "three/webgpu";
25
25
  import {
26
26
  EDGE_TOLERANCE,
27
27
  type ITraceScene,
@@ -133,9 +133,9 @@ export class TracedReflections {
133
133
  readonly maxRoughnessToEvaluateRoughSpecular: number;
134
134
  readonly roughSpecularFadeLength: number;
135
135
  readonly maxSteps: number;
136
- readonly #nodes: ReturnType<typeof texture>;
137
- readonly #triangles: ReturnType<typeof texture>;
138
- readonly #materials: ReturnType<typeof texture>;
136
+ readonly #nodes: TextureNode;
137
+ readonly #triangles: TextureNode;
138
+ readonly #materials: TextureNode;
139
139
 
140
140
  constructor(root: Object3D, options: ITracedReflectionsOptions = {}) {
141
141
  const maxRoughnessToTrace = options.maxRoughnessToTrace ?? 0.4;
@@ -254,7 +254,7 @@ export class TracedReflections {
254
254
  }
255
255
 
256
256
  /** The texel at `index` of a row-major pack texture, `TRACE_TEXTURE_WIDTH` wide. */
257
- #fetch(source: ReturnType<typeof texture>, index: Node<"float">): Node<"vec4"> {
257
+ #fetch(source: TextureNode, index: Node<"float">): Node<"vec4"> {
258
258
  const row = floor(index.div(TRACE_TEXTURE_WIDTH));
259
259
  const column = index.sub(row.mul(TRACE_TEXTURE_WIDTH));
260
260
  return textureLoad(source, ivec2(int(column), int(row)));
@@ -401,7 +401,7 @@ function batchedMatrixData(mesh: BatchedMesh): ArrayLike<number> | undefined {
401
401
  }
402
402
 
403
403
  function hasBatchedPreviousMatrices(mesh: BatchedMesh): boolean {
404
- return (mesh as BatchedMesh & IBatchedMatrixSource)._previousMatricesTexture !== undefined;
404
+ return (mesh as BatchedMesh & IBatchedMatrixSource)._previousMatricesTexture != null;
405
405
  }
406
406
 
407
407
  function isNode(value: unknown): value is Node {
@@ -28,7 +28,6 @@ import {
28
28
  dFdx,
29
29
  dFdy,
30
30
  float,
31
- getShadowMaterial,
32
31
  length,
33
32
  lightShadowMatrix,
34
33
  max,
@@ -2612,7 +2611,7 @@ export class VirtualShadowNode extends ShadowBaseNode {
2612
2611
  if (this.options.autoMapSize) this.#measureMapSizes(builder);
2613
2612
  const source = this.light as DirectionalLight;
2614
2613
  source.addEventListener("removed", this.#onLightRemoved);
2615
- let shadowColor: ReturnType<typeof getShadowMaterial>["colorNode"] = null;
2614
+ let shadowColor: ReturnType<ShadowBaseNode["getShadowMaterial"]>["colorNode"] = null;
2616
2615
  this.options.clipExtents.forEach((extent, index) => {
2617
2616
  const levelShadow = source.shadow.clone();
2618
2617
  syncShadowSettings(source.shadow, levelShadow);
@@ -2746,7 +2745,8 @@ export class VirtualShadowNode extends ShadowBaseNode {
2746
2745
  }
2747
2746
  // Stock shadow colours are identical, but their node identities split the shader cache.
2748
2747
  // Share only that constant; each level keeps its material, camera and render bindings.
2749
- const material = getShadowMaterial(node.light);
2748
+ // r187 made the per-light shadow material a method on the shadow node that owns the light.
2749
+ const material = node.getShadowMaterial();
2750
2750
  shadowColor ??= material.colorNode;
2751
2751
  material.colorNode = shadowColor;
2752
2752
  const entry: ILevel = {
package/src/renderer.ts CHANGED
@@ -1066,10 +1066,12 @@ function wrapRenderer(
1066
1066
  // reported absence rather than a frame-time error.
1067
1067
  const resolveTimestampsAsync = raw.resolveTimestampsAsync;
1068
1068
  if (resolveTimestampsAsync === undefined) return;
1069
- const observationBatch =
1070
- gpuObservation !== undefined && raw.backend?.trackTimestamp === true
1071
- ? gpuObservation.capture()
1072
- : undefined;
1069
+ // Three records nothing on a frame its own cadence turned off (`setTimestampTracking`), and
1070
+ // r187 answers the resolve with "WebGPURenderer: Timestamp tracking is disabled"
1071
+ // (src/renderers/common/Backend.js:682). Ask only on a sampled frame. A renderer this engine
1072
+ // never sampled (`timestampCapable` false) keeps three's tracking on and keeps resolving.
1073
+ if (timestampCapable && raw.backend?.trackTimestamp !== true) return;
1074
+ const observationBatch = gpuObservation !== undefined ? gpuObservation.capture() : undefined;
1073
1075
  void resolveTimestampsAsync.call(raw)?.catch(() => undefined);
1074
1076
  gpuObservation?.submitted(observationBatch);
1075
1077
  // Three maintains independent 2,048-query pools for render and compute passes. Resolving
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generate-version.mjs - do not edit. Source: package.json.
2
- export const CORE_VERSION = "0.3.8";
2
+ export const CORE_VERSION = "0.3.10";
package/src/warmup.ts CHANGED
@@ -236,6 +236,7 @@ export interface IWarmUpReport {
236
236
  /** The narrow slice of the renderer this needs. Structural so a test needs no renderer. */
237
237
  export interface IWarmUpRenderer {
238
238
  compileAsync?: (scene: Object3D, camera: Camera, targetScene?: Object3D) => Promise<void>;
239
+ compileComputeAsync?: (node: unknown) => Promise<void>;
239
240
  computeAsync?: (node: unknown) => Promise<void>;
240
241
  pipelineCensus?: () => IPipelineCensus;
241
242
  /**
@@ -447,18 +448,36 @@ export interface IComputeWarmUpReport {
447
448
  readonly timedOut: boolean;
448
449
  }
449
450
 
450
- function computeAsyncOf(renderer: IWarmUpRenderer): ((node: unknown) => Promise<void>) | undefined {
451
- const receiver = typeof renderer.computeAsync === "function" ? renderer : renderer.raw;
451
+ /** Compiles kernels without running them. */
452
+ interface IComputeWarmUpSeam {
453
+ warm(node: unknown): Promise<void>;
454
+ }
455
+
456
+ function computeAsyncOf(renderer: IWarmUpRenderer): IComputeWarmUpSeam | undefined {
457
+ const receiver =
458
+ typeof renderer.compileComputeAsync === "function" ||
459
+ typeof renderer.computeAsync === "function"
460
+ ? renderer
461
+ : renderer.raw;
452
462
  if (typeof receiver !== "object" || receiver === null) return undefined;
453
- const { backend, computeAsync } = receiver as {
463
+ const { backend, compileComputeAsync, computeAsync } = receiver as {
454
464
  backend?: { isWebGPUBackend?: boolean };
455
- computeAsync?: (node: unknown, dispatchSize?: number) => Promise<void>;
465
+ compileComputeAsync?: (node: unknown) => Promise<void>;
466
+ computeAsync?: (node: unknown, dispatchSize?: number | readonly number[]) => Promise<void>;
456
467
  };
468
+ if (backend?.isWebGPUBackend === true) {
469
+ // Three 0.187 compiles a compute pipeline and its bindings without dispatching it
470
+ // (src/renderers/common/Renderer.js:1359, `compileComputeAsync`), so warm-up builds the pipeline
471
+ // the real dispatch uses and nothing runs against the live storage buffers. Dispatching the same
472
+ // kernel with a zeroed count instead made Chrome report `DispatchWorkgroups with a workgroup
473
+ // count of 0 is unusual` once per kernel per warm-up. A renderer without that path reports its
474
+ // kernels as uncompiled rather than silently running them.
475
+ if (typeof compileComputeAsync !== "function") return undefined;
476
+ return { warm: (node) => compileComputeAsync.call(receiver, node) };
477
+ }
457
478
  if (typeof computeAsync !== "function") return undefined;
458
- // WebGPU compiles zero workgroups without running a solver against its live storage buffers.
459
- return backend?.isWebGPUBackend === true
460
- ? (node) => computeAsync.call(receiver, node, 0)
461
- : computeAsync.bind(receiver);
479
+ const plain = computeAsync.bind(receiver);
480
+ return { warm: (node) => plain(node) };
462
481
  }
463
482
 
464
483
  /**
@@ -547,8 +566,8 @@ async function runComputeWarmUp(
547
566
  now: () => number,
548
567
  yieldFrame: () => Promise<void>,
549
568
  ): Promise<IComputeWarmUpReport> {
550
- const computeAsync = computeAsyncOf(renderer);
551
- if (computeAsync === undefined) {
569
+ const seam = computeAsyncOf(renderer);
570
+ if (seam === undefined) {
552
571
  return { compiled: 0, abandoned: 0, unsupported: true, timedOut: false };
553
572
  }
554
573
 
@@ -564,7 +583,7 @@ async function runComputeWarmUp(
564
583
  }
565
584
  const finished = await withinDeadline(
566
585
  Math.min(deadline, now() + compileTimeoutMs),
567
- Promise.resolve().then(() => computeAsync(nodes[index])),
586
+ Promise.resolve().then(() => seam.warm(nodes[index])),
568
587
  yieldFrame,
569
588
  now,
570
589
  );
@@ -6066,7 +6066,7 @@ export class WorldCells extends Group implements IComputeDriven {
6066
6066
  };
6067
6067
  }
6068
6068
 
6069
- dispose(): void {
6069
+ override dispose(): void {
6070
6070
  if (this.#released) return;
6071
6071
  this.#released = true;
6072
6072
  for (const [mesh, entry] of [...this.#awaited]) {
@@ -6107,6 +6107,9 @@ export class WorldCells extends Group implements IComputeDriven {
6107
6107
  drainMeshPool();
6108
6108
  this.#terrain?.dispose();
6109
6109
  this.removeFromParent();
6110
+ // r186's Object3D.dispose() dispatches the dispose event the renderer frees this object's
6111
+ // render objects on, so an override must reach it.
6112
+ super.dispose();
6110
6113
  }
6111
6114
 
6112
6115
  #updateResidency(followCell: { x: number; z: number }, x: number, z: number): void {
@@ -2678,7 +2678,7 @@ export class TerrainTiles extends Object3D implements IComputeDriven {
2678
2678
  this.dispose();
2679
2679
  }
2680
2680
 
2681
- dispose(): void {
2681
+ override dispose(): void {
2682
2682
  if (this.#released) return;
2683
2683
  this.#released = true;
2684
2684
  this.#renderer = undefined;
@@ -2690,6 +2690,9 @@ export class TerrainTiles extends Object3D implements IComputeDriven {
2690
2690
  for (const tile of [...this.#resident.values()]) this.#evict(tile);
2691
2691
  this.#resident.clear();
2692
2692
  this.removeFromParent();
2693
+ // r186's Object3D.dispose() dispatches the dispose event the renderer frees this object's
2694
+ // render objects on, so an override must reach it.
2695
+ super.dispose();
2693
2696
  }
2694
2697
 
2695
2698
  *#createField(origin: IHeightfieldOrigin, chunked: boolean): Generator<void, Heightfield> {