rhodonite 0.20.0 → 0.20.1

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 (92) hide show
  1. package/VERSION-FILE +1 -1
  2. package/dist/esm/foundation/components/Animation/AnimationComponent.d.ts +18 -0
  3. package/dist/esm/foundation/components/Animation/AnimationOps.d.ts +20 -1
  4. package/dist/esm/foundation/components/Animation/AnimationStateRepository.d.ts +49 -0
  5. package/dist/esm/foundation/components/AnimationState/AnimationStateComponent.d.ts +5 -0
  6. package/dist/esm/foundation/components/BlendShape/BlendShapeComponent.d.ts +21 -0
  7. package/dist/esm/foundation/components/MeshRenderer/MeshRendererComponent.d.ts +61 -1
  8. package/dist/esm/foundation/components/SceneGraph/SceneGraphComponent.d.ts +50 -4
  9. package/dist/esm/foundation/components/Skeletal/SkeletalComponent.d.ts +45 -1
  10. package/dist/esm/foundation/components/Vrm/VrmComponent.d.ts +33 -3
  11. package/dist/esm/foundation/core/ComponentRepository.d.ts +17 -0
  12. package/dist/esm/foundation/geometry/Mesh.d.ts +27 -0
  13. package/dist/esm/foundation/gizmos/RotationGizmo.d.ts +2 -0
  14. package/dist/esm/foundation/gizmos/ScaleGizmo.d.ts +7 -0
  15. package/dist/esm/foundation/gizmos/TranslationGizmo.d.ts +7 -0
  16. package/dist/esm/foundation/helpers/MaterialHelper.d.ts +1 -1
  17. package/dist/esm/foundation/helpers/Shadow/ShadowSystem.d.ts +14 -0
  18. package/dist/esm/foundation/materials/contents/CustomMaterialContent.d.ts +4 -0
  19. package/dist/esm/foundation/materials/core/Material.d.ts +16 -0
  20. package/dist/esm/foundation/materials/core/MaterialRepository.d.ts +17 -0
  21. package/dist/esm/foundation/math/AnimatedQuaternion.d.ts +17 -1
  22. package/dist/esm/foundation/math/AnimatedScalar.d.ts +17 -1
  23. package/dist/esm/foundation/math/AnimatedValueEvaluationState.d.ts +56 -0
  24. package/dist/esm/foundation/math/AnimatedVector2.d.ts +17 -1
  25. package/dist/esm/foundation/math/AnimatedVector3.d.ts +17 -1
  26. package/dist/esm/foundation/math/AnimatedVector4.d.ts +17 -1
  27. package/dist/esm/foundation/math/AnimatedVectorN.d.ts +17 -1
  28. package/dist/esm/foundation/math/IAnimatedValue.d.ts +18 -0
  29. package/dist/esm/foundation/math/IMatrix.d.ts +12 -0
  30. package/dist/esm/foundation/math/IdentityMatrix44.d.ts +9 -0
  31. package/dist/esm/foundation/physics/Oimo/OimoPhysicsStrategy.d.ts +22 -0
  32. package/dist/esm/foundation/physics/PhysicsStrategy.d.ts +8 -0
  33. package/dist/esm/foundation/physics/Rapier/RapierCharacterControllerStrategy.d.ts +2 -0
  34. package/dist/esm/foundation/physics/Rapier/RapierPhysicsStrategy.d.ts +12 -0
  35. package/dist/esm/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +26 -26
  36. package/dist/esm/foundation/system/Engine.d.ts +31 -0
  37. package/dist/esm/foundation/textures/Sampler.d.ts +14 -0
  38. package/dist/esm/index.js +555 -555
  39. package/dist/esm/webgl/WebGLExtendedTypes.d.ts +2 -0
  40. package/dist/esm/webgl/WebGLGpuTimer.d.ts +32 -0
  41. package/dist/esm/webgl/WebGLResourceRepository.d.ts +21 -1
  42. package/dist/esm/webgl/WebGLStrategyDataTexture.d.ts +9 -0
  43. package/dist/esm/webgpu/RangeAllocator.d.ts +39 -0
  44. package/dist/esm/webgpu/WebGpuBufferArena.d.ts +60 -0
  45. package/dist/esm/webgpu/WebGpuGpuTimer.d.ts +49 -0
  46. package/dist/esm/webgpu/WebGpuResourceRepository.d.ts +212 -18
  47. package/dist/esmdev/foundation/components/Animation/AnimationComponent.d.ts +18 -0
  48. package/dist/esmdev/foundation/components/Animation/AnimationOps.d.ts +20 -1
  49. package/dist/esmdev/foundation/components/Animation/AnimationStateRepository.d.ts +49 -0
  50. package/dist/esmdev/foundation/components/AnimationState/AnimationStateComponent.d.ts +5 -0
  51. package/dist/esmdev/foundation/components/BlendShape/BlendShapeComponent.d.ts +21 -0
  52. package/dist/esmdev/foundation/components/MeshRenderer/MeshRendererComponent.d.ts +61 -1
  53. package/dist/esmdev/foundation/components/SceneGraph/SceneGraphComponent.d.ts +50 -4
  54. package/dist/esmdev/foundation/components/Skeletal/SkeletalComponent.d.ts +45 -1
  55. package/dist/esmdev/foundation/components/Vrm/VrmComponent.d.ts +33 -3
  56. package/dist/esmdev/foundation/core/ComponentRepository.d.ts +17 -0
  57. package/dist/esmdev/foundation/geometry/Mesh.d.ts +27 -0
  58. package/dist/esmdev/foundation/gizmos/RotationGizmo.d.ts +2 -0
  59. package/dist/esmdev/foundation/gizmos/ScaleGizmo.d.ts +7 -0
  60. package/dist/esmdev/foundation/gizmos/TranslationGizmo.d.ts +7 -0
  61. package/dist/esmdev/foundation/helpers/MaterialHelper.d.ts +1 -1
  62. package/dist/esmdev/foundation/helpers/Shadow/ShadowSystem.d.ts +14 -0
  63. package/dist/esmdev/foundation/materials/contents/CustomMaterialContent.d.ts +4 -0
  64. package/dist/esmdev/foundation/materials/core/Material.d.ts +16 -0
  65. package/dist/esmdev/foundation/materials/core/MaterialRepository.d.ts +17 -0
  66. package/dist/esmdev/foundation/math/AnimatedQuaternion.d.ts +17 -1
  67. package/dist/esmdev/foundation/math/AnimatedScalar.d.ts +17 -1
  68. package/dist/esmdev/foundation/math/AnimatedValueEvaluationState.d.ts +56 -0
  69. package/dist/esmdev/foundation/math/AnimatedVector2.d.ts +17 -1
  70. package/dist/esmdev/foundation/math/AnimatedVector3.d.ts +17 -1
  71. package/dist/esmdev/foundation/math/AnimatedVector4.d.ts +17 -1
  72. package/dist/esmdev/foundation/math/AnimatedVectorN.d.ts +17 -1
  73. package/dist/esmdev/foundation/math/IAnimatedValue.d.ts +18 -0
  74. package/dist/esmdev/foundation/math/IMatrix.d.ts +12 -0
  75. package/dist/esmdev/foundation/math/IdentityMatrix44.d.ts +9 -0
  76. package/dist/esmdev/foundation/physics/Oimo/OimoPhysicsStrategy.d.ts +22 -0
  77. package/dist/esmdev/foundation/physics/PhysicsStrategy.d.ts +8 -0
  78. package/dist/esmdev/foundation/physics/Rapier/RapierCharacterControllerStrategy.d.ts +2 -0
  79. package/dist/esmdev/foundation/physics/Rapier/RapierPhysicsStrategy.d.ts +12 -0
  80. package/dist/esmdev/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +26 -26
  81. package/dist/esmdev/foundation/system/Engine.d.ts +31 -0
  82. package/dist/esmdev/foundation/textures/Sampler.d.ts +14 -0
  83. package/dist/esmdev/index.js +6620 -4050
  84. package/dist/esmdev/webgl/WebGLExtendedTypes.d.ts +2 -0
  85. package/dist/esmdev/webgl/WebGLGpuTimer.d.ts +32 -0
  86. package/dist/esmdev/webgl/WebGLResourceRepository.d.ts +21 -1
  87. package/dist/esmdev/webgl/WebGLStrategyDataTexture.d.ts +9 -0
  88. package/dist/esmdev/webgpu/RangeAllocator.d.ts +39 -0
  89. package/dist/esmdev/webgpu/WebGpuBufferArena.d.ts +60 -0
  90. package/dist/esmdev/webgpu/WebGpuGpuTimer.d.ts +49 -0
  91. package/dist/esmdev/webgpu/WebGpuResourceRepository.d.ts +212 -18
  92. package/package.json +1 -1
@@ -13,6 +13,8 @@ export interface RnWebGLProgram extends WebGLProgram {
13
13
  __SPECTOR_rebuildProgram: unknown;
14
14
  _material: WeakRef<Material>;
15
15
  _primitive: WeakRef<Primitive>;
16
+ /** Texture unit last assigned to each sampler uniform of this program (uniform values persist per program). */
17
+ _textureUnitsOfSamplers?: Map<string, number>;
16
18
  }
17
19
  export interface RnWebGLTexture extends WebGLTexture {
18
20
  _resourceUid: number;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Measures the GPU time of each frame with EXT_disjoint_timer_query_webgl2.
3
+ *
4
+ * Results arrive a few frames later, so `lastGpuTimeMilliseconds` reports the latest frame whose result is
5
+ * available, not the current one. Results of a period in which the GPU reported a disjoint event (for
6
+ * example a power state change) are discarded because they are unreliable.
7
+ */
8
+ export declare class WebGLGpuTimer {
9
+ private __gl;
10
+ private __ext;
11
+ private __activeQuery?;
12
+ private __pendingQueries;
13
+ private __freeQueries;
14
+ private __lastGpuTimeMilliseconds?;
15
+ constructor(gl: WebGL2RenderingContext);
16
+ /** Whether the context supports GPU timer queries. */
17
+ get isSupported(): boolean;
18
+ /** The GPU time of the latest measured frame in milliseconds, or undefined if none is available yet. */
19
+ get lastGpuTimeMilliseconds(): number | undefined;
20
+ /**
21
+ * Starts measuring the GL commands issued until end().
22
+ * Only one measurement can be active at a time; nested calls are ignored.
23
+ */
24
+ begin(): void;
25
+ /**
26
+ * Ends the measurement started by begin() and collects the results that have become available.
27
+ */
28
+ end(): void;
29
+ private __collectResults;
30
+ /** Deletes the queries. The timer must not be used afterwards. */
31
+ destroy(): void;
32
+ }
@@ -121,6 +121,9 @@ export type WebGLResource = WebGLBuffer | WebGLFramebuffer | WebGLProgram | WebG
121
121
  export declare class WebGLResourceRepository extends CGAPIResourceRepository implements ICGAPIResourceRepository {
122
122
  private __webglContexts;
123
123
  private __glw?;
124
+ /** See __getCanvasContextAttributes(). */
125
+ private __canvasContextAttributes?;
126
+ private __canvasContextAttributesOwner?;
124
127
  private __resourceCounter;
125
128
  private __webglResources;
126
129
  private __samplerClampToEdgeLinearUid;
@@ -222,6 +225,17 @@ export declare class WebGLResourceRepository extends CGAPIResourceRepository imp
222
225
  * @throws Error if no WebGL context is available or VBO not found
223
226
  */
224
227
  updateVertexBuffer(accessor: Accessor, resourceHandle: number): void;
228
+ /**
229
+ * Overwrites the beginning of an existing vertex buffer with the given typed array.
230
+ *
231
+ * The vertex array binding is left untouched: the ARRAY_BUFFER binding is not part of the VAO state,
232
+ * so this can be called between draw calls without disturbing the bound VAO.
233
+ *
234
+ * @param resourceHandle - The handle of the vertex buffer to update
235
+ * @param typedArray - The data written from the beginning of the buffer
236
+ * @throws Error if no WebGL context is available or VBO not found
237
+ */
238
+ updateVertexBufferWithTypedArray(resourceHandle: WebGLResourceHandle, typedArray: TypedArray): void;
225
239
  /**
226
240
  * Creates a new vertex array object (VAO).
227
241
  *
@@ -893,7 +907,13 @@ export declare class WebGLResourceRepository extends CGAPIResourceRepository imp
893
907
  createTransformFeedback(): number;
894
908
  deleteTransformFeedback(transformFeedbackUid: WebGLResourceHandle): void;
895
909
  setViewport(engine: Engine, viewport?: Vector4): void;
896
- clearFrameBuffer(_engine: Engine, renderPass: RenderPass, _?: number): void;
910
+ clearFrameBuffer(engine: Engine, renderPass: RenderPass, _?: number): void;
911
+ /**
912
+ * Whether the canvas (default framebuffer) has a depth / stencil buffer. Cached because
913
+ * getContextAttributes() allocates a new object on every call. While the context is lost the
914
+ * attributes are unknown, so both are reported as present and nothing is skipped.
915
+ */
916
+ private __getCanvasContextAttributes;
897
917
  deleteVertexDataResources(vertexHandles: VertexHandles): void;
898
918
  deleteVertexArray(vaoHandle: WebGLResourceHandle): void;
899
919
  deleteVertexBuffer(vboUid: WebGLResourceHandle): void;
@@ -32,6 +32,9 @@ export declare class WebGLStrategyDataTexture implements CGAPIStrategy, WebGLStr
32
32
  private __lastRenderPassTickCount;
33
33
  private __lightComponents?;
34
34
  private __currentComponentSIDs?;
35
+ /** Program and values of the last currentComponentSIDs upload, used to skip redundant uploads. */
36
+ private __lastComponentSIDsProgram?;
37
+ private __lastUploadedComponentSIDs?;
35
38
  _totalSizeOfGPUShaderDataStorageExceptMorphData: number;
36
39
  private static __isDebugOperationToDataTextureBufferDone;
37
40
  private __uniformMorphOffsetsTypedArray?;
@@ -424,6 +427,12 @@ export declare class WebGLStrategyDataTexture implements CGAPIStrategy, WebGLStr
424
427
  * between draw calls and only updating GPU state when necessary.
425
428
  */
426
429
  private __renderInner;
430
+ /**
431
+ * Uploads the currentComponentSIDs uniform unless the same values were already uploaded to the
432
+ * same program by the previous upload. Uniform values persist in the program object, so
433
+ * consecutive draws of the same material (e.g. a shadow pass) do not need to upload again.
434
+ */
435
+ private __uploadCurrentComponentSIDs;
427
436
  /**
428
437
  * Binds the data texture to the WebGL context for shader access.
429
438
  * This method sets up the texture binding and sampler configuration
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A first-fit allocator of byte ranges within a fixed-size region.
3
+ *
4
+ * Free ranges are kept sorted by offset and merged with their neighbors on release, so the region does
5
+ * not fragment into unusable pieces when ranges are allocated and released repeatedly.
6
+ * It does not touch any GPU resource; WebGpuBufferArena uses it to sub-allocate large GPU buffers.
7
+ */
8
+ export declare class RangeAllocator {
9
+ private readonly __capacity;
10
+ /** Sorted, non-overlapping, non-adjacent free ranges. */
11
+ private __freeOffsets;
12
+ private __freeSizes;
13
+ private __usedSize;
14
+ /**
15
+ * @param capacity - The size of the region in bytes
16
+ */
17
+ constructor(capacity: number);
18
+ /** The size of the region in bytes. */
19
+ get capacity(): number;
20
+ /** The total size of the allocated ranges in bytes. */
21
+ get usedSize(): number;
22
+ /** Whether no range is allocated. */
23
+ get isEmpty(): boolean;
24
+ /**
25
+ * Allocates a range.
26
+ * @param size - The size in bytes
27
+ * @param alignment - The alignment of the returned offset in bytes
28
+ * @returns The offset of the range, or -1 if no free range is large enough
29
+ */
30
+ allocate(size: number, alignment: number): number;
31
+ /**
32
+ * Releases a range returned by allocate().
33
+ * @param offset - The offset of the range
34
+ * @param size - The size of the range in bytes
35
+ */
36
+ release(offset: number, size: number): void;
37
+ /** The free ranges as [offset, size] pairs, for tests and debugging. */
38
+ getFreeRanges(): [number, number][];
39
+ }
@@ -0,0 +1,60 @@
1
+ import { RangeAllocator } from './RangeAllocator';
2
+ /** A range of a GPU buffer owned by WebGpuBufferArena. */
3
+ export type WebGpuBufferRange = {
4
+ buffer: GPUBuffer;
5
+ offset: number;
6
+ /** The size of the data in bytes, as passed to setVertexBuffer()/setIndexBuffer(). */
7
+ size: number;
8
+ /** The allocated size in bytes (the data size rounded up to the write alignment). */
9
+ allocatedSize: number;
10
+ chunk: WebGpuBufferArenaChunk;
11
+ };
12
+ type WebGpuBufferArenaChunk = {
13
+ buffer: GPUBuffer;
14
+ allocator: RangeAllocator;
15
+ };
16
+ /**
17
+ * Sub-allocates vertex and index data from a few large GPU buffers.
18
+ *
19
+ * A frame that references tens of thousands of separate vertex and index buffers makes the browser's
20
+ * GPU process (and the driver) track each of them, which dominated the frame time of scenes with many
21
+ * meshes. Packing the data into a few buffers and binding ranges with offsets avoids that cost.
22
+ */
23
+ export declare class WebGpuBufferArena {
24
+ private __device;
25
+ private __usage;
26
+ private __chunkSize;
27
+ private __chunks;
28
+ private __scratch;
29
+ /**
30
+ * @param device - The GPU device
31
+ * @param usage - The usage of the chunk buffers. COPY_DST is added for uploads.
32
+ * @param chunkSize - The size of a chunk in bytes. Larger data gets a dedicated chunk.
33
+ */
34
+ constructor(device: GPUDevice, usage: GPUBufferUsageFlags, chunkSize?: number);
35
+ /** The number of GPU buffers owned by the arena. */
36
+ get chunkCount(): number;
37
+ /**
38
+ * Allocates a range and uploads the data into it.
39
+ * @param data - The data to upload
40
+ * @returns The allocated range
41
+ */
42
+ allocate(data: Uint8Array): WebGpuBufferRange;
43
+ /**
44
+ * Uploads data into a range. Data larger than the range is truncated.
45
+ * @param range - The range returned by allocate()
46
+ * @param data - The data to upload
47
+ */
48
+ write(range: WebGpuBufferRange, data: Uint8Array): void;
49
+ /**
50
+ * Releases a range. A chunk without any range left is destroyed, except the last one, which is kept
51
+ * so that repeatedly creating and deleting a small mesh does not reallocate a whole chunk.
52
+ * Writes to the queue are ordered after the commands submitted before, so a released range can be
53
+ * reused for new data even if a submitted command still reads it.
54
+ * @param range - The range returned by allocate()
55
+ */
56
+ release(range: WebGpuBufferRange): void;
57
+ /** Destroys all the chunks. */
58
+ destroy(): void;
59
+ }
60
+ export {};
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Measures the GPU time of each frame with the `timestamp-query` feature.
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
6
+ * encoder is submitted and read back asynchronously, so `lastGpuTimeMilliseconds` reports the latest
7
+ * frame whose results have arrived, not the current one.
8
+ *
9
+ * Browsers may quantize timestamps (e.g. to 100µs) unless developer features are enabled.
10
+ */
11
+ export declare class WebGpuGpuTimer {
12
+ private __device;
13
+ private __querySet?;
14
+ private __resolveBuffer?;
15
+ private __freeReadbackBuffers;
16
+ private __readbackBufferCount;
17
+ /** Timestamps written by passes recorded into the current command encoder. */
18
+ private __timestampCount;
19
+ /** The frame the timestamps of the current command encoder belong to. */
20
+ private __encoderFrame?;
21
+ private __currentFrame?;
22
+ private __readbacksToMap;
23
+ private __lastGpuTimeMilliseconds?;
24
+ constructor(device: GPUDevice);
25
+ /** Whether the device supports timestamp queries. */
26
+ get isSupported(): boolean;
27
+ /** The GPU time of the latest measured frame in milliseconds, or undefined if none is available yet. */
28
+ get lastGpuTimeMilliseconds(): number | undefined;
29
+ /** Starts measuring the render passes begun from now on. */
30
+ beginFrame(): void;
31
+ /** Stops measuring. The frame's time is published once all of its timestamps have been read back. */
32
+ endFrame(): void;
33
+ /**
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).
36
+ */
37
+ getTimestampWrites(): GPURenderPassTimestampWrites | undefined;
38
+ /**
39
+ * Encodes the resolve of the timestamps written by the passes of `encoder`.
40
+ * Call this before finishing the encoder, and call afterSubmit() after submitting it.
41
+ */
42
+ encodeResolve(encoder: GPUCommandEncoder): void;
43
+ /** Starts reading back the timestamps resolved by the encoder that has just been submitted. */
44
+ afterSubmit(): void;
45
+ private __readBack;
46
+ private __tryPublish;
47
+ /** Destroys the GPU resources. The timer must not be used afterwards. */
48
+ destroy(): void;
49
+ }
@@ -14,16 +14,15 @@ import { CGAPIResourceRepository, type DirectTextureData, type ICGAPIResourceRep
14
14
  import type { FrameBuffer } from '../foundation/renderer/FrameBuffer';
15
15
  import type { RenderPass } from '../foundation/renderer/RenderPass';
16
16
  import type { Engine } from '../foundation/system/Engine';
17
- import { CubeTexture } from '../foundation/textures/CubeTexture';
18
17
  import type { IRenderable } from '../foundation/textures/IRenderable';
19
- import { RenderTargetTextureCube } from '../foundation/textures/RenderTargetTextureCube';
20
18
  import { Sampler } from '../foundation/textures/Sampler';
21
19
  import type { BasisFile } from '../types/BasisTexture';
22
20
  import type { Count, Index, Size, TypedArray, WebGLResourceHandle, WebGPUResourceHandle } from '../types/CommonTypes';
23
21
  import type { TextureData, VertexHandles } from '../webgl/WebGLResourceRepository';
22
+ import { type WebGpuBufferRange } from './WebGpuBufferArena';
24
23
  import type { WebGpuDeviceWrapper } from './WebGpuDeviceWrapper';
24
+ import { WebGpuGpuTimer } from './WebGpuGpuTimer';
25
25
  export type WebGpuResource = GPUTexture | GPUBuffer | GPUSampler | GPUTextureView | GPUBufferBinding | GPURenderPipeline | GPUComputePipeline | GPUBindGroupLayout | GPUBindGroup | GPUShaderModule | GPUCommandEncoder | GPUComputePassEncoder | GPURenderPassEncoder | GPUComputePipeline | GPURenderPipeline | GPUQuerySet | object;
26
- type DRAW_PARAMETERS_IDENTIFIER = string;
27
26
  /**
28
27
  * WebGPU Resource Repository that manages WebGPU resources and provides rendering functionality.
29
28
  * This class serves as a central hub for creating, managing, and utilizing WebGPU resources
@@ -38,18 +37,60 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
38
37
  private __webGpuDeviceWrapper?;
39
38
  private __storageBuffer?;
40
39
  private __storageBlendShapeBuffer?;
40
+ /** Group 0: the storage buffer, the blend shape buffer and the morph uniform buffers. */
41
41
  private __bindGroupStorageBuffer?;
42
42
  private __bindGroupLayoutStorageBuffer?;
43
+ private __bindGroupLayoutKeyStorageBuffer;
44
+ /** The buffers bound by `__bindGroupStorageBuffer`, used to detect when it must be recreated. */
45
+ private __storageBindGroupBuffers;
46
+ /** Bound to the blend shape slot of group 0 when there is no blend shape buffer. */
47
+ private __dummyBlendShapeBuffer?;
43
48
  private __webGpuRenderPipelineMap;
44
49
  private __materialStateVersionMap;
45
- private __bindGroupTextureMap;
46
- private __bindGroupLayoutTextureMap;
47
- private __bindGroupSamplerMap;
48
- private __bindGroupLayoutSamplerMap;
49
- private __bindGroupsUniformDrawParameters;
50
+ private __bindGroupLayoutCache;
51
+ private __pipelineLayoutCache;
52
+ /** Group 1 (textures), keyed by layout and bound texture views. */
53
+ private __textureBindGroupCache;
54
+ /** Group 2 (samplers), keyed by layout and bound samplers. */
55
+ private __samplerBindGroupCache;
56
+ /** Group 3 (draw parameters), keyed by the parameter values. The uniform buffers are immutable. */
57
+ private __drawParametersBindGroupCache;
58
+ /**
59
+ * Uniform buffers holding the draw parameters. Each buffer holds many entries at the uniform offset
60
+ * alignment: the browser's GPU process and the driver track every distinct buffer referenced by a
61
+ * frame, so one small buffer per entry costs much more than offsets into a few large buffers.
62
+ */
63
+ private __drawParametersBuffers;
64
+ private __drawParametersEntryCountInLastBuffer;
65
+ private static readonly __drawParametersEntriesPerBuffer;
66
+ private static __drawParametersValues;
50
67
  private __bindGroupLayoutUniformDrawParameters?;
51
- private __uniformDrawParametersBuffers;
68
+ /** The group 3 bind group selected by setDrawParameters() for the next draw(). */
69
+ private __currentDrawParametersBindGroup?;
70
+ /** Views created for dummy textures when a texture has no view yet, by texture and dimension. */
71
+ private __dummyTextureViews;
72
+ /** Identifiers of GPU objects used to build cache keys. */
73
+ private __gpuObjectIds;
74
+ private __gpuObjectIdCount;
75
+ private __textureSamplerBindings;
76
+ private __drawBindGroups;
77
+ /** State last recorded into the current render bundle encoder, used to skip redundant commands. */
78
+ private __bundlePipeline?;
79
+ private __bundleBindGroups;
80
+ private __bundleVertexBuffers;
81
+ private __bundleIndexBuffer?;
82
+ /**
83
+ * Vertex and index data of all primitives (and the per-mesh instance buffers), packed into a few
84
+ * large GPU buffers. Each handle maps to a range of one of them.
85
+ */
86
+ private __vertexBufferArena?;
87
+ private __vertexBufferRanges;
88
+ /** Measures the GPU time of frames; created on first use (see Engine.gpuTimerEnabled). */
89
+ private __gpuTimer?;
90
+ private __bundleIndexFormat?;
52
91
  private __commandEncoder?;
92
+ /** Cached `gpuDevice.queue` ([SameObject]), read on every frame by flush(). */
93
+ private __gpuQueue?;
53
94
  private __renderBundles;
54
95
  private __renderBundleEncoder?;
55
96
  private __renderBundleEncoderKey?;
@@ -58,13 +99,38 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
58
99
  private __uniformMorphOffsetsBuffer?;
59
100
  private __uniformMorphWeightsBuffer?;
60
101
  private __renderPassEncoder?;
102
+ /**
103
+ * The render pass encoder is kept open after a render pass has been recorded so that following
104
+ * render passes drawing into the same attachments (without clearing) can be merged into it.
105
+ * Every beginRenderPass/end pair is a comparatively expensive native call, and on tile-based GPUs
106
+ * each extra pass also costs a load/store of the attachments.
107
+ * These fields describe the currently open encoder.
108
+ */
109
+ private __renderPassEncoderOwner?;
110
+ private __renderPassEncoderDisplayIdx;
111
+ private __renderPassEncoderTargetKind;
112
+ private __renderPassEncoderTargetViews;
113
+ /** Scratch array swapped with `__renderPassEncoderTargetViews` to avoid per-pass allocations. */
114
+ private __candidateRenderPassTargetViews;
115
+ /** Render bundles waiting to be executed in the open render pass. See __executeRenderBundle(). */
116
+ private __pendingRenderBundles;
117
+ /**
118
+ * The clear of a render pass that draws nothing, not encoded yet. See clearFrameBuffer().
119
+ * The object is reused to keep the per-frame path free of allocations.
120
+ */
121
+ private __pendingClear;
122
+ /** A depth clear of the system depth texture deferred to the next render pass attaching it. See flush(). */
123
+ private __deferredSystemDepthClearValue;
124
+ /** The render pass (and display) the pending render bundle encoder is recording for. */
125
+ private __renderBundleEncoderOwner?;
126
+ private __renderBundleEncoderDisplayIdx;
61
127
  private __generateMipmapsShaderModule?;
62
128
  private __generateMipmapsPipeline?;
63
129
  private __generateMipmapsFormat?;
64
130
  private __generateMipmapsSampler?;
65
131
  private __generateMipmapsBindGroupLayout?;
66
132
  private __contextCurrentTextureView?;
67
- private __lastMaterialsUpdateCount;
133
+ private __lastBindingStateVersion;
68
134
  private __lastCurrentCameraComponentSid;
69
135
  private __lastEntityRepositoryUpdateCount;
70
136
  private __lastPrimitivesMaterialVariantUpdateCount;
@@ -72,7 +138,6 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
72
138
  private __srcTextureViewsForGeneratingMipmaps;
73
139
  private __dstTextureViewsForGeneratingMipmaps;
74
140
  private __bindGroupsForGeneratingMipmaps;
75
- private static __drawParametersUint32Array;
76
141
  private constructor();
77
142
  private static __assertArrayBufferView;
78
143
  /**
@@ -274,9 +339,25 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
274
339
  * @returns Handle to the created index buffer resource
275
340
  */
276
341
  createIndexBuffer(accessor: Accessor): WebGPUResourceHandle;
342
+ /**
343
+ * Returns the index data of an accessor in a format WebGPU accepts.
344
+ * WebGPU does not support 8-bit indices, so they are widened to 16 bits.
345
+ */
346
+ private static __getIndexData;
347
+ private __getVertexBufferArena;
348
+ /**
349
+ * Uploads vertex or index data into the shared vertex buffer arena and returns a handle to the range.
350
+ */
351
+ private __allocateVertexBufferRange;
352
+ /**
353
+ * Returns the buffer range of a vertex or index buffer handle.
354
+ * @internal
355
+ */
356
+ _getVertexBufferRange(resourceHandle: WebGPUResourceHandle): WebGpuBufferRange | undefined;
357
+ private __releaseVertexBufferRange;
277
358
  /**
278
359
  * Updates the data in an existing vertex buffer with new data from an accessor.
279
- * This method maps the buffer for writing and uploads the new data.
360
+ * The data must not be larger than the data the buffer was created with.
280
361
  *
281
362
  * @param accessor - Accessor containing the new vertex data
282
363
  * @param resourceHandle - Handle to the existing vertex buffer to update
@@ -293,8 +374,7 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
293
374
  */
294
375
  updateIndexBuffer(accessor: Accessor, resourceHandle: WebGPUResourceHandle): void;
295
376
  /**
296
- * Deletes a vertex buffer and removes it from the resource registry.
297
- * This destroys the GPU buffer and frees its memory.
377
+ * Deletes a vertex buffer and releases its range of the vertex buffer arena.
298
378
  *
299
379
  * @param resourceHandle - Handle to the vertex buffer to delete
300
380
  * @throws Error if the vertex buffer is not found
@@ -397,6 +477,11 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
397
477
  };
398
478
  getOrCreateRenderPassEncoderForEffekseerExternalRendering(engine: Engine, renderPass: RenderPass, displayIdx: number): GPURenderPassEncoder | undefined;
399
479
  createRenderBundleEncoder(engine: Engine, renderPass: RenderPass, displayIdx: number): void;
480
+ /**
481
+ * Forgets the state recorded into the render bundle encoder. A new encoder starts without any
482
+ * pipeline, bind group or buffer set.
483
+ */
484
+ private __resetBundleEncoderState;
400
485
  /**
401
486
  * Creates a render pass encoder for immediate rendering commands.
402
487
  * This encoder is used for recording rendering commands that will be executed immediately.
@@ -406,6 +491,69 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
406
491
  * @param displayIdx - The display index for stereo rendering (0 for left eye, 1 for right eye)
407
492
  */
408
493
  private createRenderPassEncoder;
494
+ /**
495
+ * Collects the attachment views `__beginRenderPassEncoder` would use for the render pass.
496
+ * Must be kept in sync with the attachment selection in `__beginRenderPassEncoder`.
497
+ *
498
+ * @returns The kind of the target, or `RENDER_PASS_TARGET_KIND_NONE` if the render pass must not be merged.
499
+ */
500
+ private __collectRenderPassTargetViews;
501
+ /**
502
+ * Returns the attachment for the current canvas texture of this frame.
503
+ *
504
+ * When the browser accepts a GPUTexture where a GPUTextureView is expected (the texture's default
505
+ * view is used), the texture itself is returned. This saves a `createView()` call per frame.
506
+ */
507
+ private __getContextCurrentTextureView;
508
+ private static __textureAsAttachmentViewSupport;
509
+ /**
510
+ * Detects once whether a GPUTexture can be passed as a render pass attachment view.
511
+ * Browsers that do not support it throw a TypeError while converting the descriptor.
512
+ */
513
+ private static __isTextureAsAttachmentViewSupported;
514
+ /**
515
+ * Begins a render pass on the frame's command encoder. A deferred clear of the system depth
516
+ * texture (see flush()) is applied here to the first render pass that attaches it.
517
+ */
518
+ private __beginRenderPass;
519
+ /** Lets the GPU timer measure the render pass while a frame is being measured. */
520
+ private __addTimestampWrites;
521
+ /**
522
+ * Returns the GPU timer, creating it on first use.
523
+ * @internal Use Engine.gpuTimerEnabled and Engine.gpuTimeMilliseconds instead.
524
+ */
525
+ _getGpuTimer(): WebGpuGpuTimer;
526
+ /**
527
+ * Encodes the pending clear (see clearFrameBuffer) as a render pass of its own.
528
+ * Anything recorded in the open render pass happened before the clear, so it is ended first.
529
+ */
530
+ private __encodePendingClear;
531
+ private __resetPendingClear;
532
+ /**
533
+ * Ends the open render pass (if any) and encodes a pending clear, so that commands can be recorded
534
+ * directly on the command encoder (copies, mipmap generation, external rendering, submission).
535
+ */
536
+ private __flushRenderPassWork;
537
+ /**
538
+ * Executes a render bundle in the open render pass. Bundles are batched and executed with a
539
+ * single executeBundles() call when the pass is ended or handed out for direct drawing.
540
+ */
541
+ private __executeRenderBundle;
542
+ private __executePendingRenderBundles;
543
+ private static __isSameTargetViews;
544
+ /**
545
+ * Ends the open render pass encoder, if any.
546
+ *
547
+ * A pending render bundle encoder is executed into the pass only when it was recorded for the
548
+ * same render pass. Otherwise it belongs to a render pass that is still being recorded (the open
549
+ * encoder is just being kept for merging) and must stay pending.
550
+ */
551
+ private __endRenderPassEncoder;
552
+ private __clearRenderBundleEncoder;
553
+ /**
554
+ * Begins a new render pass encoder for the render pass. The caller must have ended any open encoder.
555
+ */
556
+ private __beginRenderPassEncoder;
409
557
  private __toClearRenderBundles;
410
558
  renderWithRenderBundle(engine: Engine, renderPass: RenderPass, displayIdx: number): boolean;
411
559
  renderWithRenderBundleAndKeepRenderPass(engine: Engine, renderPass: RenderPass, displayIdx: number): GPURenderPassEncoder | undefined;
@@ -413,7 +561,7 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
413
561
  finishRenderBundleEncoderAndKeepRenderPass(engine: Engine, renderPass: RenderPass, displayIdx: number): GPURenderPassEncoder | undefined;
414
562
  getOrCreateRenderPassEncoderForExternalRendering(engine: Engine, renderPass: RenderPass, displayIdx: number): GPURenderPassEncoder | undefined;
415
563
  endRenderPassEncoderForExternalRendering(): void;
416
- getOrCreateRenderPipeline(renderPipelineId: string, bindGroupId: string, primitive: Primitive, material: Material, renderPass: RenderPass, zWrite: boolean, _diffuseCubeMap?: CubeTexture | RenderTargetTextureCube, _specularCubeMap?: CubeTexture | RenderTargetTextureCube, _sheenCubeMap?: CubeTexture | RenderTargetTextureCube): [GPURenderPipeline, boolean];
564
+ getOrCreateRenderPipeline(renderPipelineId: string, pipelineLayoutKey: string, pipelineLayout: GPUPipelineLayout, primitive: Primitive, material: Material, renderPass: RenderPass, zWrite: boolean): [GPURenderPipeline, boolean];
417
565
  /**
418
566
  * Submits all recorded commands to the GPU queue and resets the command encoder.
419
567
  * This method must be called to execute any recorded rendering commands.
@@ -488,13 +636,60 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
488
636
  deleteStorageBlendShapeBuffer(storageBufferHandle: WebGPUResourceHandle): void;
489
637
  updateStorageBlendShapeBuffer(storageBufferHandle: WebGPUResourceHandle, inputArray: Float32Array, updateComponentSize: Count): void;
490
638
  createBindGroupLayoutForDrawParameters(): void;
491
- updateUniformBufferForDrawParameters(identifier: DRAW_PARAMETERS_IDENTIFIER, materialSid: Index, cameraSID: Index, currentPrimitiveIdx: Index, morphTargetNumber: Count): void;
639
+ /**
640
+ * Selects the draw parameters (group 3) for the next draw().
641
+ *
642
+ * The parameters are stored in an immutable uniform buffer shared by every draw with the same values,
643
+ * so consecutive draws of the same material and camera keep the same bind group.
644
+ *
645
+ * @param materialSid - The material SID
646
+ * @param cameraSID - The camera component SID
647
+ * @param currentPrimitiveIdx - The index of the primitive among the primitives with morph targets
648
+ * @param morphTargetNumber - The number of morph targets of the primitive
649
+ */
650
+ setDrawParameters(materialSid: Index, cameraSID: Index, currentPrimitiveIdx: Index, morphTargetNumber: Count): void;
492
651
  createUniformMorphOffsetsBuffer(sizeInByte: Count): number;
493
652
  updateUniformMorphOffsetsBuffer(inputArray: Uint32Array, elementNum: Count): void;
494
653
  createUniformMorphWeightsBuffer(sizeInByte: Count): number;
495
654
  updateUniformMorphWeightsBuffer(inputArray: Float32Array, elementNum: Count): void;
496
655
  deleteUniformBuffer(uniformBufferHandle: WebGPUResourceHandle): void;
497
- private __createBindGroup;
656
+ /**
657
+ * Returns a stable identifier of a GPU object for cache keys.
658
+ */
659
+ private __getGpuObjectId;
660
+ /**
661
+ * Returns the bind group layout for the given descriptor, shared by every bind group and pipeline
662
+ * layout with the same descriptor.
663
+ */
664
+ private __getOrCreateBindGroupLayout;
665
+ /**
666
+ * Returns the view of a dummy texture with the given dimension. The view is created once per texture.
667
+ */
668
+ private __getDummyTextureView;
669
+ /**
670
+ * Returns the group 0 bind group (storage buffer, blend shape buffer and morph uniform buffers).
671
+ * It is recreated only when one of those buffers is replaced.
672
+ */
673
+ private __getStorageBindGroup;
674
+ /**
675
+ * Appends a texture binding and its sampler to `__textureSamplerBindings`.
676
+ */
677
+ private __pushTextureSamplerBinding;
678
+ /**
679
+ * Collects the textures and samplers bound by a material into `__textureSamplerBindings`.
680
+ * The IBL cube maps come from the mesh renderer component, not from the material.
681
+ */
682
+ private __collectTextureSamplerBindings;
683
+ /**
684
+ * Returns the bind groups and the pipeline layout for drawing with a material.
685
+ *
686
+ * The texture (group 1) and sampler (group 2) bind groups are looked up by the resources they bind,
687
+ * so materials binding the same textures and samplers share them. They do not depend on the render
688
+ * pipeline, so a pipeline can be recreated without recreating bind groups and vice versa.
689
+ */
690
+ private __getDrawBindGroups;
691
+ private __getTextureBindGroupLayout;
692
+ private __getSamplerBindGroupLayout;
498
693
  /**
499
694
  * create a Texture
500
695
  * @param imageData
@@ -750,4 +945,3 @@ export declare class WebGpuResourceRepository extends CGAPIResourceRepository im
750
945
  */
751
946
  isSupportMultiViewVRRendering(): boolean;
752
947
  }
753
- export {};
@@ -20,6 +20,10 @@ export declare class AnimationComponent extends Component {
20
20
  /** Map to store animation global info per Engine instance for multi-engine support */
21
21
  private static __animationGlobalInfoMap;
22
22
  private __isEffekseerState;
23
+ /** Reused map for VRM expression weights to avoid a per-frame allocation. */
24
+ private __vrmExpressionWeights;
25
+ /** Cache of the leaf parameter name of `material/...` animation paths. */
26
+ private __materialParameterNameCache;
23
27
  private __isAnimating;
24
28
  isLoop: boolean;
25
29
  useGlobalTime: boolean;
@@ -80,11 +84,25 @@ export declare class AnimationComponent extends Component {
80
84
  private __applyAnimation;
81
85
  private __applyChannelAnimation;
82
86
  private __applyTransformAnimation;
87
+ /**
88
+ * Returns true when the animated value differs from the value already stored in the transform.
89
+ *
90
+ * Writing an identical value would still increment the transform update count and invalidate the
91
+ * world matrix and skinning caches downstream, so identical writes are skipped. The comparison is
92
+ * against the target value (not the last applied value), so external transform edits are still
93
+ * overwritten by the animation on the next frame.
94
+ *
95
+ * Physics subtrees set `canSkipIdenticalTransformWrite` to false: their setters also notify the
96
+ * physics strategies with the parent world transform, which must keep running even when the local
97
+ * value is unchanged.
98
+ */
99
+ private __shouldWriteTransformValue;
83
100
  private __applyBlendShapeAnimation;
84
101
  private __applyVisibilityAnimation;
85
102
  private __applyEffectiveVisibility;
86
103
  private __getLocalVisibility;
87
104
  private __applyMaterialAnimation;
105
+ private __getMaterialParameterName;
88
106
  private __applyLightAnimation;
89
107
  private __applyCameraAnimation;
90
108
  private __applyEffekseerAnimation;
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { AnimationSampler } from '../../../types/AnimationTypes';
7
7
  import type { Index } from '../../../types/CommonTypes';
8
+ import type { KeyframeCursor } from '../../math/AnimatedValueEvaluationState';
8
9
  /**
9
10
  * Extracts the output value at a specific keyframe from the animation sampler data.
10
11
  * Handles different interpolation methods and component counts appropriately.
@@ -15,6 +16,23 @@ import type { Index } from '../../../types/CommonTypes';
15
16
  * @returns The extracted value as an array of numbers
16
17
  */
17
18
  export declare function __getOutputValue(keyFrameId: Index, sampler: AnimationSampler, array_: Float32Array | number[]): number[];
19
+ /**
20
+ * A mutable array-like target for interpolation results (number[], Float32Array, Float64Array).
21
+ */
22
+ export type WritableNumberArray = {
23
+ [index: number]: number;
24
+ };
25
+ /**
26
+ * Interpolates animation values at a specific time and writes them into an existing array.
27
+ * This is the allocation-free path used by the Animated* value classes every frame.
28
+ *
29
+ * @param sampler - Animation sampler containing input/output data and interpolation settings
30
+ * @param currentTime - Time value to interpolate at
31
+ * @param animationAttributeIndex - Type of animation attribute being interpolated
32
+ * @param out - Destination array (length must be at least `sampler.outputComponentN`)
33
+ * @param cursor - Optional memoized keyframe segment index
34
+ */
35
+ export declare function __interpolateTo(sampler: AnimationSampler, currentTime: number, animationAttributeIndex: Index, out: WritableNumberArray, cursor?: KeyframeCursor): void;
18
36
  /**
19
37
  * Interpolates animation values at a specific time using the specified interpolation method.
20
38
  * Supports linear, step, and cubic spline interpolation methods according to glTF 2.0 specification.
@@ -22,6 +40,7 @@ export declare function __getOutputValue(keyFrameId: Index, sampler: AnimationSa
22
40
  * @param sampler - Animation sampler containing input/output data and interpolation settings
23
41
  * @param currentTime - Time value to interpolate at
24
42
  * @param animationAttributeIndex - Type of animation attribute being interpolated
43
+ * @param cursor - Optional memoized keyframe segment index
25
44
  * @returns Interpolated animation values as an array
26
45
  */
27
- export declare function __interpolate(sampler: AnimationSampler, currentTime: number, animationAttributeIndex: Index): Array<number>;
46
+ export declare function __interpolate(sampler: AnimationSampler, currentTime: number, animationAttributeIndex: Index, cursor?: KeyframeCursor): Array<number>;