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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhodonite",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "keywords": [
5
5
  "rhodonite",
6
6
  "webgl",