rhodonite 0.22.0 → 0.22.2

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 (33) hide show
  1. package/README.md +4 -4
  2. package/VERSION-FILE +1 -1
  3. package/dist/esm/foundation/components/Light/LightComponent.d.ts +7 -0
  4. package/dist/esm/foundation/components/SceneGraph/SceneGraphComponent.d.ts +28 -1
  5. package/dist/esm/foundation/core/ComponentRepository.d.ts +7 -0
  6. package/dist/esm/foundation/core/Config.d.ts +34 -0
  7. package/dist/esm/foundation/math/Transform3D.d.ts +26 -2
  8. package/dist/esm/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +7 -1
  9. package/dist/esm/foundation/renderer/lightCluster/LightClusterLayout.d.ts +11 -0
  10. package/dist/esm/foundation/renderer/lightCluster/LightClusterSystem.d.ts +22 -0
  11. package/dist/esm/foundation/system/Engine.d.ts +13 -2
  12. package/dist/esm/index.js +394 -227
  13. package/dist/esm/webgl/WebGLStrategyWebGL2.d.ts +9 -5
  14. package/dist/esm/webgpu/WebGpuGpuTimer.d.ts +18 -7
  15. package/dist/esm/webgpu/WebGpuLightClusterBuilder.d.ts +4 -1
  16. package/dist/esm/webgpu/convertFloat32ToFloat16Bits.d.ts +16 -0
  17. package/dist/esm/webgpu/packRgbaRowsForUpload.d.ts +23 -0
  18. package/dist/esmdev/foundation/components/Light/LightComponent.d.ts +7 -0
  19. package/dist/esmdev/foundation/components/SceneGraph/SceneGraphComponent.d.ts +28 -1
  20. package/dist/esmdev/foundation/core/ComponentRepository.d.ts +7 -0
  21. package/dist/esmdev/foundation/core/Config.d.ts +34 -0
  22. package/dist/esmdev/foundation/math/Transform3D.d.ts +26 -2
  23. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterBuilder.d.ts +7 -1
  24. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterLayout.d.ts +11 -0
  25. package/dist/esmdev/foundation/renderer/lightCluster/LightClusterSystem.d.ts +22 -0
  26. package/dist/esmdev/foundation/system/Engine.d.ts +13 -2
  27. package/dist/esmdev/index.js +954 -128
  28. package/dist/esmdev/webgl/WebGLStrategyWebGL2.d.ts +9 -5
  29. package/dist/esmdev/webgpu/WebGpuGpuTimer.d.ts +18 -7
  30. package/dist/esmdev/webgpu/WebGpuLightClusterBuilder.d.ts +4 -1
  31. package/dist/esmdev/webgpu/convertFloat32ToFloat16Bits.d.ts +16 -0
  32. package/dist/esmdev/webgpu/packRgbaRowsForUpload.d.ts +23 -0
  33. package/package.json +1 -1
@@ -489,16 +489,20 @@ export declare class WebGLStrategyWebGL2 implements CGAPIStrategy, WebGLStrategy
489
489
  * between draw calls and only updating GPU state when necessary.
490
490
  */
491
491
  private __renderInner;
492
- /**
493
- * Uploads the currentComponentSIDs uniform unless the same values were already uploaded to the
494
- * same program by the previous upload. Uniform values persist in the program object, so
495
- * consecutive draws of the same material (e.g. a shadow pass) do not need to upload again.
496
- */
497
492
  /**
498
493
  * Uploads the light cluster view of the camera of the draw (`u_lightClusterView`) when the program uses it and
499
494
  * the camera or the light cluster data changed since the last upload to the program.
495
+ *
496
+ * The 7 vec4 are [header (6 vec4)][(view vec4 index, 0, 0, 0)], or a view index of -1 when the camera has no
497
+ * clusters. Uniform values persist in the program object, so consecutive draws of the same camera skip the
498
+ * upload; the check keeps the per-draw cost to a comparison in the common case.
500
499
  */
501
500
  private __uploadLightClusterView;
501
+ /**
502
+ * Uploads the currentComponentSIDs uniform unless the same values were already uploaded to the
503
+ * same program by the previous upload. Uniform values persist in the program object, so
504
+ * consecutive draws of the same material (e.g. a shadow pass) do not need to upload again.
505
+ */
502
506
  private __uploadCurrentComponentSIDs;
503
507
  /**
504
508
  * Binds the data texture to the WebGL context for shader access.
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Measures the GPU time of each frame with the `timestamp-query` feature.
3
3
  *
4
- * Every render pass begun between beginFrame() and endFrame() writes timestamps at its beginning and end;
5
- * the frame's GPU time is the sum of the pass durations. The timestamps are resolved when the command
4
+ * Every render or compute pass begun between beginFrame() and endFrame() writes timestamps at its beginning and
5
+ * end; the frame's GPU time is the sum of the pass durations. The timestamps are resolved when the command
6
6
  * encoder is submitted and read back asynchronously, so `lastGpuTimeMilliseconds` reports the latest
7
- * frame whose results have arrived, not the current one.
7
+ * frame whose results have arrived, not the current one. The duration of each pass label is also published.
8
8
  *
9
9
  * Browsers may quantize timestamps (e.g. to 100µs) unless developer features are enabled.
10
10
  */
@@ -16,25 +16,36 @@ export declare class WebGpuGpuTimer {
16
16
  private __readbackBufferCount;
17
17
  /** Timestamps written by passes recorded into the current command encoder. */
18
18
  private __timestampCount;
19
+ /** The labels of the passes recorded into the current command encoder, one per pass. */
20
+ private __encoderPassLabels;
19
21
  /** The frame the timestamps of the current command encoder belong to. */
20
22
  private __encoderFrame?;
21
23
  private __currentFrame?;
22
24
  private __readbacksToMap;
23
25
  private __lastGpuTimeMilliseconds?;
26
+ private __lastPassGpuTimesMilliseconds?;
24
27
  constructor(device: GPUDevice);
25
28
  /** Whether the device supports timestamp queries. */
26
29
  get isSupported(): boolean;
27
30
  /** The GPU time of the latest measured frame in milliseconds, or undefined if none is available yet. */
28
31
  get lastGpuTimeMilliseconds(): number | undefined;
29
- /** Starts measuring the render passes begun from now on. */
32
+ /**
33
+ * The GPU time of each pass of the latest measured frame in milliseconds, keyed by the pass label.
34
+ * Undefined until a complete frame is available.
35
+ */
36
+ get lastPassGpuTimesMilliseconds(): ReadonlyMap<string, number> | undefined;
37
+ /** Starts measuring the render and compute passes begun from now on. */
30
38
  beginFrame(): void;
31
39
  /** Stops measuring. The frame's time is published once all of its timestamps have been read back. */
32
40
  endFrame(): void;
33
41
  /**
34
- * Returns the timestamp writes to set on a render pass descriptor, or undefined when the pass is not
35
- * measured (outside a frame, or when the query set is full).
42
+ * Returns the timestamp writes to set on a render or compute pass descriptor, or undefined when the
43
+ * pass is not measured (outside a frame, or when the query set is full).
44
+ *
45
+ * @param label - The label of the pass, used to report its duration in
46
+ * {@link WebGpuGpuTimer.lastPassGpuTimesMilliseconds}. Passes with the same label are summed.
36
47
  */
37
- getTimestampWrites(): GPURenderPassTimestampWrites | undefined;
48
+ getTimestampWrites(label: string): GPURenderPassTimestampWrites | undefined;
38
49
  /**
39
50
  * Encodes the resolve of the timestamps written by the passes of `encoder`.
40
51
  * Call this before finishing the encoder, and call afterSubmit() after submitting it.
@@ -1,4 +1,5 @@
1
1
  import type { LightClusterGpuBuildParams } from '../foundation/renderer/lightCluster/LightClusterSystem';
2
+ import type { WebGpuGpuTimer } from './WebGpuGpuTimer';
2
3
  /**
3
4
  * Builds the light cluster tables of Clustered Forward rendering with compute shaders.
4
5
  * The tables are written into the storage buffer of the GPU instance data, where the CPU build would write them.
@@ -25,8 +26,10 @@ export declare class WebGpuLightClusterBuilder {
25
26
  *
26
27
  * @param storageBuffer - The storage buffer of the GPU instance data
27
28
  * @param params - The views to build and their sorted light input
29
+ * @param gpuTimer - When set (and a frame is being measured), measures the build as the
30
+ * 'LightClusterBuild' pass
28
31
  */
29
- build(storageBuffer: GPUBuffer, params: LightClusterGpuBuildParams): void;
32
+ build(storageBuffer: GPUBuffer, params: LightClusterGpuBuildParams, gpuTimer?: WebGpuGpuTimer): void;
30
33
  /**
31
34
  * Releases the GPU resources.
32
35
  */
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts Float32 values to IEEE 754 half-float (Float16) bits.
3
+ *
4
+ * HDR textures are uploaded as half floats on devices without the optional
5
+ * `float32-filterable` feature (e.g. iOS Safari). There an `rgba32float` texture cannot be
6
+ * bound with the default `sampleType: 'float'` of the texture bind group layouts, so every
7
+ * draw using it is rejected. Filtering 16-bit float textures is core WebGPU, so half floats
8
+ * work everywhere.
9
+ *
10
+ * The conversion rounds to nearest, ties to even, and handles denormals, Infinity and NaN
11
+ * exactly like the platform `Float16Array` conversion.
12
+ *
13
+ * @param src - Float32 values
14
+ * @returns The same values encoded as half-float bits
15
+ */
16
+ export declare function convertFloat32ToFloat16Bits(src: Float32Array): Uint16Array;
@@ -0,0 +1,23 @@
1
+ /** RGBA float rows packed for GPUQueue.copyBufferToTexture. */
2
+ export type PackedRgbaRows = {
3
+ /** Padded rows, ready to copy into a mapped GPUBuffer. */
4
+ data: Uint16Array | Float32Array;
5
+ /** `bytesPerRow` for the copy, padded to the 256-byte alignment WebGPU requires. */
6
+ bytesPerRow: number;
7
+ /** Number of array elements per row (row stride of `data`). */
8
+ elementsPerRow: number;
9
+ };
10
+ /**
11
+ * Packs tightly packed RGBA Float32 rows into the padded layout that
12
+ * GPUQueue.copyBufferToTexture requires.
13
+ *
14
+ * Rows must be padded to a multiple of 256 bytes. A row also has to be copied at
15
+ * `elementsPerRow` in the destination array (components per row, including padding),
16
+ * not at the number of texels in the row.
17
+ *
18
+ * @param src - Tightly packed RGBA Float32 pixel data
19
+ * @param width - Width in pixels
20
+ * @param height - Height in pixels
21
+ * @param isFloat16 - Encode as half floats instead of 32-bit floats
22
+ */
23
+ export declare function packRgbaRowsForUpload(src: Float32Array, width: number, height: number, isFloat16: boolean): PackedRgbaRows;
@@ -41,6 +41,7 @@ export declare class LightComponent extends Component {
41
41
  private __updateCount;
42
42
  private __lastUpdateCount;
43
43
  private __lastTransformUpdateCount;
44
+ private __lastRangeScale;
44
45
  /** The number of changes of all light components, per engine. */
45
46
  private static __updateCountMap;
46
47
  /**
@@ -295,6 +296,12 @@ export declare class LightComponent extends Component {
295
296
  * to avoid unnecessary recalculations when nothing has changed.
296
297
  */
297
298
  $logic(): void;
299
+ /**
300
+ * Returns the intensity factor that compensates the shortened range. The factors are the measured brightness
301
+ * balance of the Sponza scene: 0.9 -> 1.16 and 0.8 -> 1.35. Values in between interpolate; below 0.8 the last
302
+ * slope continues. A constant factor compensates the range window approximately, not exactly.
303
+ */
304
+ private static __getIntensityScale;
298
305
  /**
299
306
  * Returns the range used for shading. Point and spot lights without a range get an automatic range
300
307
  * when `Config.lightAutoRangeThreshold` is greater than 0.
@@ -31,6 +31,12 @@ export declare class SceneGraphComponent extends Component {
31
31
  private __isGizmoChild;
32
32
  private __physicsComponentCountInSubtree;
33
33
  private static __hierarchyVersion;
34
+ /**
35
+ * Validity epoch of the per-node `__aabbDirtyChainEpoch` marks. Advancing it invalidates all marks at
36
+ * once; this is required whenever an AABB-dirty flag is cleared or a parent-child link changes, since
37
+ * either can break the "this node and all ancestors are AABB-dirty" guarantee of a mark.
38
+ */
39
+ private static __aabbDirtyChainEpoch;
34
40
  private _worldMatrix;
35
41
  private _worldMatrixRest;
36
42
  private _normalMatrix;
@@ -47,6 +53,16 @@ export declare class SceneGraphComponent extends Component {
47
53
  private __worldMergedAABBWithSkeletal;
48
54
  private __worldMergedAABB;
49
55
  private __isWorldAABBDirty;
56
+ /**
57
+ * Epoch at which this node was last visited by {@link setWorldAABBDirtyParentRecursively}.
58
+ * While it equals the static epoch, this node and all of its ancestors are known to be AABB-dirty,
59
+ * so an upward propagation reaching this node can stop here.
60
+ */
61
+ private __aabbDirtyChainEpoch;
62
+ /** `__worldMatrixVersion` when logicForce last ran; while unchanged, $logic has nothing to update. */
63
+ private __settledWorldMatrixVersion;
64
+ /** Component creation count when logicForce last ran (a mesh may have been attached since). */
65
+ private __settledComponentCreationCount;
50
66
  private _isVisible;
51
67
  private _isBillboard;
52
68
  private __aabbGizmo?;
@@ -55,6 +71,8 @@ export declare class SceneGraphComponent extends Component {
55
71
  private __rotationGizmo?;
56
72
  private __scaleGizmo?;
57
73
  private __jointGizmo?;
74
+ /** True when any gizmo of this node has been set up: skips the per-frame gizmo checks of plain nodes. */
75
+ private __hasGizmos;
58
76
  private __transformGizmoSpace;
59
77
  private __latestPrimitivePositionAccessorVersion;
60
78
  toMakeWorldMatrixTheSameAsLocalMatrix: boolean;
@@ -221,6 +239,10 @@ export declare class SceneGraphComponent extends Component {
221
239
  * @returns The hierarchy version counter
222
240
  */
223
241
  static get hierarchyVersion(): number;
242
+ /**
243
+ * Advances the hierarchy version after a parent-child relationship changed.
244
+ */
245
+ private static __bumpHierarchyVersion;
224
246
  static get componentTID(): 4;
225
247
  /**
226
248
  * Gets the component type identifier for this instance.
@@ -255,7 +277,12 @@ export declare class SceneGraphComponent extends Component {
255
277
  */
256
278
  setWorldMatrixDirtyRecursively(): void;
257
279
  /**
258
- * Recursively marks the world AABB as dirty up the parent hierarchy.
280
+ * Marks the world AABB of this node and all of its ancestors as dirty.
281
+ *
282
+ * The walk stops at the first node already marked in the current epoch: that node and all of its
283
+ * ancestors are known to be dirty. Many nodes of the same subtree changing in one frame (e.g. every
284
+ * joint of an animated skeleton) therefore cost O(number of distinct ancestors) in total instead of
285
+ * O(changed nodes * depth).
259
286
  */
260
287
  setWorldAABBDirtyParentRecursively(): void;
261
288
  /**
@@ -15,7 +15,14 @@ export declare class ComponentRepository {
15
15
  private __renderingComponentTIDs;
16
16
  static readonly invalidComponentSID = -1;
17
17
  private __engine;
18
+ private __componentCreationCount;
18
19
  constructor(engine: Engine);
20
+ /**
21
+ * Number of components created in this repository so far, of any type.
22
+ * Consumers compare it with a remembered value to detect that components were attached to entities.
23
+ * @internal
24
+ */
25
+ get _componentCreationCount(): number;
19
26
  /**
20
27
  * Registers a component class with the repository.
21
28
  * This method associates a component class with its unique ComponentTID for later instantiation.
@@ -30,6 +30,7 @@ type ConfigInitDescription = {
30
30
  clusteredForwardMinLocalLightNumber?: number;
31
31
  maxLightListLength?: number;
32
32
  lightAutoRangeThreshold?: number;
33
+ lightRangeScale?: number;
33
34
  };
34
35
  /**
35
36
  * Where the light clusters of Clustered Forward rendering are built.
@@ -174,6 +175,39 @@ export declare class Config {
174
175
  * updated next.
175
176
  */
176
177
  lightAutoRangeThreshold: number;
178
+ /**
179
+ * Scales the effective range of the point and spot lights, and raises their intensity to compensate.
180
+ * A shorter range reaches fewer clusters, so fewer fragments evaluate the light in Clustered Forward rendering.
181
+ *
182
+ * @remarks
183
+ * `1` (default) applies no adjustment. The measured presets are:
184
+ *
185
+ * | lightRangeScale | Intensity | GPU frame time (measured) |
186
+ * |-----------------|-----------|----------------------------|
187
+ * | 1 | x1 | 5.5-6.4 ms |
188
+ * | 0.9 | x1.16 | 4.2-4.5 ms (-20 to -24%) |
189
+ * | 0.8 | x1.35 | 3.1-3.2 ms (-43 to -50%) |
190
+ *
191
+ * The measurement is a Sponza scene with 1000 animated point lights (WebGPU, 1920x1080, clustered forward).
192
+ * Intermediate values interpolate the measured intensity factors: `1 -> 1`, `0.9 -> 1.16`, `0.8 -> 1.35`,
193
+ * and below 0.8 the last slope continues. A constant factor cannot compensate the range window exactly: with
194
+ * a shorter range the falloff `(1 - (d / range)^4)^4 / d^2` is slightly dimmer at mid distances, and the lights
195
+ * fade out closer to their centers. 0.9 changes only 0.1% of the pixels by more than 32/255; 0.8 changes about
196
+ * 7% of the pixels that much (the lit area of each light becomes smaller).
197
+ *
198
+ * The engine does not change this value by itself. An application that targets a frame budget can adjust it
199
+ * at runtime (for example, from the measured GPU time and the display refresh interval).
200
+ *
201
+ * Only point and spot lights with a positive effective range are adjusted. Directional lights and lights without
202
+ * a range limit are unchanged. The values of `LightComponent.range` and `LightComponent.intensity` themselves are
203
+ * not modified: only the values uploaded to the GPU (and read by the light clusters and the shaders) are scaled,
204
+ * so all rendering paths see the same light.
205
+ */
206
+ private __lightRangeScale;
207
+ /** See {@link Config.lightRangeScale}. */
208
+ get lightRangeScale(): number;
209
+ /** See {@link Config.lightRangeScale}. */
210
+ set lightRangeScale(value: number);
177
211
  /**
178
212
  * Number of instances of each material type to be placed consecutively in memory.
179
213
  * This is on the memory layout, and the number of material instances that can be generated is not limited by this setting.
@@ -26,6 +26,13 @@ export declare class Transform3D {
26
26
  private __scale;
27
27
  private __rotation;
28
28
  private __updateCount;
29
+ /** The local matrix composed from the current position, rotation and scale. */
30
+ private __matrix;
31
+ private __isMatrixUpToDate;
32
+ /** The position, rotation and scale the cached matrix was composed from (to detect direct inner mutations). */
33
+ private __matrixPosition;
34
+ private __matrixRotation;
35
+ private __matrixScale;
29
36
  private static __tmpMatrix44_0;
30
37
  private static __tmpVector3_0;
31
38
  private static __tmpVector3_1;
@@ -126,9 +133,15 @@ export declare class Transform3D {
126
133
  get rotationInner(): Quaternion;
127
134
  /**
128
135
  * Internal method to increment the update counter when transform changes.
136
+ *
137
+ * A position-only change updates the translation column of the cached matrix instead of invalidating it.
138
+ * Animations that move nodes (the common case with many lights) then avoid the quaternion-to-matrix
139
+ * composition every frame. A rotation or scale change invalidates the matrix.
140
+ *
141
+ * @param change - What changed: `'position'` or everything (`'all'`).
129
142
  * @private
130
143
  */
131
- __updateTransform(): void;
144
+ __updateTransform(change?: 'all' | 'position'): void;
132
145
  /**
133
146
  * Sets the transform from a 4x4 transformation matrix.
134
147
  * Decomposes the matrix into position, rotation, and scale components.
@@ -146,9 +159,20 @@ export declare class Transform3D {
146
159
  * @returns A MutableMatrix44 representing the composed transformation
147
160
  */
148
161
  get matrixInner(): MutableMatrix44;
162
+ /**
163
+ * Composes the local matrix from the current position, rotation and scale and stores it in the cache.
164
+ */
165
+ private __composeMatrix;
166
+ /**
167
+ * Brings the cached matrix up to date. Direct mutations of the inner vectors (positionInner and the like)
168
+ * bypass the setters, so they are detected here: a position-only change updates the translation column, and
169
+ * a rotation or scale change recomposes the matrix.
170
+ */
171
+ private __ensureMatrixUpToDate;
149
172
  /**
150
173
  * Efficiently computes the transformation matrix and stores it in the provided matrix.
151
- * This method avoids memory allocation by reusing an existing matrix object.
174
+ * The composed matrix is cached, so repeated reads (including animated translations) do not
175
+ * recompose the rotation and scale.
152
176
  * @param mat - The target matrix to store the result in
153
177
  */
154
178
  getMatrixInnerTo(mat: MutableMatrix44): void;
@@ -79,13 +79,19 @@ export declare function buildLightClustersOnCpu(dst: Float32Array, viewOffset: n
79
79
  */
80
80
  export declare function sphereIntersectsLightCluster(dst: Float32Array, viewOffset: number, layout: LightClusterViewLayout, x: number, y: number, z: number, cx: number, cy: number, cz: number, r: number): boolean;
81
81
  /**
82
- * The reference implementation of the cluster lookup of the shaders (`getLightList`).
82
+ * The reference implementation of the cluster lookup of the shaders (`getLightList` in opticalDefinition.glsl /
83
+ * .wgsl), used by the tests and by CPU-side code that needs the cluster of a position.
84
+ *
85
+ * It reads the same header rows as the shaders, so a change to one form must be made to the other.
83
86
  *
84
87
  * @returns The cluster index, or -1 when the position uses the all-light list (behind the eye plane or overflow).
85
88
  */
86
89
  export declare function computeLightClusterIndex(dst: Float32Array, viewOffset: number, px: number, py: number, pz: number): number;
87
90
  /**
88
91
  * Reads the light entries of a cluster built by `buildLightClustersOnCpu` (or by the compute shader).
92
+ *
93
+ * This follows the same two-level lookup as the shaders: the table entry gives the vec4 offset and the entry count
94
+ * of the cluster, and the entries themselves are read from the index list from that offset.
89
95
  */
90
96
  export declare function readLightClusterEntries(dst: Float32Array, viewOffset: number, layout: LightClusterViewLayout, clusterIndex: number): number[];
91
97
  /**
@@ -58,10 +58,17 @@ export declare const LightClusterLayout: {
58
58
  export declare function getLightListCapacity(maxLightListLength: number): number;
59
59
  /**
60
60
  * Returns the array length (in vec4) of the `clusteredLightData` global property.
61
+ *
62
+ * The light entries are read 4 at a time (`entries[n >> 2][n & 3]` in the shaders), so the list is rounded up to
63
+ * whole vec4s: the last vec4 can hold fewer than 4 lights.
61
64
  */
62
65
  export declare function getLightClusterGlobalPropertyLength(maxLightListLength: number): number;
63
66
  /**
64
67
  * Packs a light component SID and a shadow slot into a light entry.
68
+ *
69
+ * The SID is stored in the low 16 bits and `shadowSlot + 1` above them, so -1 (no shadow slot) is representable
70
+ * without a sign. The shaders unpack the same way: `(entry & 0xFFFF, (entry >> 16) - 1)`.
71
+ * The value stays below 2^24, so a float32 stores it exactly.
65
72
  */
66
73
  export declare function packLightEntry(lightComponentSid: number, shadowSlot: number): number;
67
74
  /**
@@ -92,6 +99,10 @@ export declare function getLightClusterViewLayout(gridSize: readonly [number, nu
92
99
  /**
93
100
  * Splits the byte range `[start, end)` into the parts outside the excluded ranges.
94
101
  *
102
+ * The rendering strategies use this to upload the whole GPU instance data in one call while leaving out the
103
+ * regions owned by the light cluster system: the cluster tables are large, are unchanged for many frames and
104
+ * may be written by compute shaders, so they are uploaded (or not uploaded) separately as dirty ranges.
105
+ *
95
106
  * @param excluded - Ranges `[start, end)` sorted by their start
96
107
  * @returns The remaining ranges `[start, end)` in ascending order
97
108
  */
@@ -37,6 +37,17 @@ export type LightClusterGpuBuildParams = {
37
37
  *
38
38
  * The data lives in the GPU instance data, so it is uploaded by the rendering strategy. `dataVersion` changes
39
39
  * whenever this system writes the data, and the strategies upload the data when it changes.
40
+ *
41
+ * ## Reading guide (the order of the code below)
42
+ * 1. `update()` is the frame entry point, called by `Engine` after the Logic stage.
43
+ * 2. `__collectLights()` turns the light components into the all-light list (`__entries`) and the light spheres
44
+ * (`__spheres`), and detects whether anything changed since the previous frame.
45
+ * 3. `__writeGlobalData()` publishes the all-light list in the `clusteredLightData` global property.
46
+ * 4. `__collectCameras()` / `__assignViews()` choose the cameras whose fragments use clusters, allocate their
47
+ * view regions (header + cluster table + light index list) and build them (`LightClusterBuilder.ts` on the CPU,
48
+ * `WebGpuLightClusterBuilder.ts` on the GPU).
49
+ * 5. The fragment shaders (`opticalDefinition.glsl` / `.wgsl`, `getLightList`) look up the cluster of a fragment
50
+ * and read its light list. The layout of both the list and the view region is in `LightClusterLayout.ts`.
40
51
  */
41
52
  export declare class LightClusterSystem {
42
53
  private __engine;
@@ -142,6 +153,13 @@ export declare class LightClusterSystem {
142
153
  * @returns true if the lists changed since the previous frame
143
154
  */
144
155
  private __collectLights;
156
+ /**
157
+ * Writes the all-light list into the `clusteredLightData` global property.
158
+ *
159
+ * The layout is documented in LightClusterLayout.ts: (allCount, globalCount, localCount, sphereBase) followed by
160
+ * the entries, 4 per vec4. The shaders read the counts from the header: `globalCount` is how many entries they
161
+ * read from the all-light list, and the rest of the list of a clustered fragment comes from the view region.
162
+ */
145
163
  private __writeGlobalData;
146
164
  /**
147
165
  * Lists the cameras of the render passes that may draw lit materials, in the order of the render passes.
@@ -166,6 +184,10 @@ export declare class LightClusterSystem {
166
184
  private __prepareViewBuild;
167
185
  /**
168
186
  * Allocates a region in the GPU instance data. Returns undefined (and disables the clusters) when it fails.
187
+ *
188
+ * The region is ordinary GPU instance data: the WebGL2 data texture / the WebGPU storage buffer. That is why the
189
+ * shaders can read the table with the same `fetchElement` / `get_clusteredLightData` accessor as any other data,
190
+ * and why the strategies have to skip it in the generic upload (see `_getExcludedByteRanges`).
169
191
  */
170
192
  private __allocate;
171
193
  }
@@ -193,10 +193,21 @@ export declare class Engine extends RnObject {
193
193
  * @remarks
194
194
  * Undefined until a result is available, or when {@link gpuTimerEnabled} is false or the environment does
195
195
  * not support GPU timer queries. GPU results arrive asynchronously, so the value lags behind by a few
196
- * frames. In WebGPU it is the sum of the durations of the render passes; in WebGL2 it is the time the GPU
197
- * spent on all the commands issued during process().
196
+ * frames. In WebGPU it is the sum of the durations of the render passes and the compute passes (such as
197
+ * the light cluster build); in WebGL2 it is the time the GPU spent on all the commands issued during
198
+ * process().
198
199
  */
199
200
  get gpuTimeMilliseconds(): number | undefined;
201
+ /**
202
+ * The GPU time of each pass of the latest measured process() call, in milliseconds, keyed by the pass label.
203
+ *
204
+ * @remarks
205
+ * WebGPU only. Undefined until a complete result is available, when {@link gpuTimerEnabled} is false, or
206
+ * when the GPU timer is not supported. The labels are the labels of the GPU passes: the unique names of the
207
+ * render passes, `DepthPrepass`, `LightClusterBuild`, and so on. Passes with the same label are summed.
208
+ * Like {@link gpuTimeMilliseconds}, the value lags behind by a few frames.
209
+ */
210
+ get gpuPassTimesMilliseconds(): ReadonlyMap<string, number> | undefined;
200
211
  private __getWebGLGpuTimer;
201
212
  private __beginGpuTimer;
202
213
  private __endGpuTimer;