super-three 0.172.0 → 0.173.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 (180) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +439 -380
  3. package/build/three.core.js +413 -41
  4. package/build/three.core.min.js +2 -2
  5. package/build/three.module.js +28 -344
  6. package/build/three.module.min.js +2 -2
  7. package/build/three.tsl.js +11 -3
  8. package/build/three.tsl.min.js +2 -2
  9. package/build/three.webgpu.js +7550 -1798
  10. package/build/three.webgpu.min.js +2 -2
  11. package/build/three.webgpu.nodes.js +7551 -1798
  12. package/build/three.webgpu.nodes.min.js +2 -2
  13. package/examples/jsm/animation/CCDIKSolver.js +6 -5
  14. package/examples/jsm/capabilities/WebGPU.js +1 -1
  15. package/examples/jsm/controls/ArcballControls.js +23 -21
  16. package/examples/jsm/exporters/GLTFExporter.js +26 -25
  17. package/examples/jsm/geometries/TextGeometry.js +1 -12
  18. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  19. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  20. package/examples/jsm/loaders/GCodeLoader.js +3 -1
  21. package/examples/jsm/loaders/GLTFLoader.js +0 -2
  22. package/examples/jsm/loaders/TDSLoader.js +0 -1
  23. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  24. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  25. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  26. package/examples/jsm/misc/ProgressiveLightMapGPU.js +4 -3
  27. package/examples/jsm/misc/Volume.js +7 -5
  28. package/examples/jsm/misc/VolumeSlice.js +5 -3
  29. package/examples/jsm/objects/WaterMesh.js +25 -20
  30. package/examples/jsm/physics/JoltPhysics.js +7 -7
  31. package/examples/jsm/physics/RapierPhysics.js +4 -4
  32. package/examples/jsm/postprocessing/EffectComposer.js +23 -2
  33. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  34. package/examples/jsm/postprocessing/Pass.js +6 -1
  35. package/examples/jsm/shaders/OutputShader.js +5 -1
  36. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  37. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  38. package/package.json +1 -1
  39. package/src/Three.Core.js +2 -0
  40. package/src/Three.TSL.js +9 -1
  41. package/src/cameras/ArrayCamera.js +1 -0
  42. package/src/constants.js +6 -1
  43. package/src/core/BufferAttribute.js +4 -0
  44. package/src/core/EventDispatcher.js +8 -6
  45. package/src/extras/ImageUtils.js +1 -11
  46. package/src/loaders/nodes/NodeObjectLoader.js +1 -1
  47. package/src/materials/nodes/MeshBasicNodeMaterial.js +1 -1
  48. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +1 -1
  49. package/src/materials/nodes/NodeMaterial.js +5 -5
  50. package/src/materials/nodes/NodeMaterials.js +0 -1
  51. package/src/materials/nodes/PointsNodeMaterial.js +109 -7
  52. package/src/materials/nodes/SpriteNodeMaterial.js +1 -1
  53. package/src/materials/nodes/VolumeNodeMaterial.js +3 -3
  54. package/src/materials/nodes/manager/NodeMaterialObserver.js +8 -0
  55. package/src/nodes/Nodes.js +4 -0
  56. package/src/nodes/TSL.js +4 -0
  57. package/src/nodes/accessors/Arrays.js +30 -8
  58. package/src/nodes/accessors/BatchNode.js +3 -3
  59. package/src/nodes/accessors/BufferAttributeNode.js +1 -1
  60. package/src/nodes/accessors/Camera.js +64 -3
  61. package/src/nodes/accessors/InstanceNode.js +1 -1
  62. package/src/nodes/accessors/MaterialNode.js +9 -9
  63. package/src/nodes/accessors/ModelViewProjectionNode.js +1 -1
  64. package/src/nodes/accessors/Normal.js +6 -2
  65. package/src/nodes/accessors/Object3DNode.js +0 -1
  66. package/src/nodes/accessors/Position.js +6 -6
  67. package/src/nodes/accessors/ReferenceBaseNode.js +2 -4
  68. package/src/nodes/accessors/ReferenceNode.js +2 -3
  69. package/src/nodes/accessors/StorageBufferNode.js +42 -5
  70. package/src/nodes/accessors/Tangent.js +2 -2
  71. package/src/nodes/accessors/Texture3DNode.js +1 -1
  72. package/src/nodes/accessors/TextureNode.js +12 -5
  73. package/src/nodes/accessors/UniformArrayNode.js +9 -3
  74. package/src/nodes/accessors/VelocityNode.js +0 -2
  75. package/src/nodes/code/ScriptableNode.js +3 -3
  76. package/src/nodes/core/ArrayNode.js +125 -0
  77. package/src/nodes/core/ConstNode.js +8 -0
  78. package/src/nodes/core/Node.js +14 -1
  79. package/src/nodes/core/NodeBuilder.js +229 -19
  80. package/src/nodes/core/NodeUtils.js +11 -1
  81. package/src/nodes/core/NodeVar.js +17 -1
  82. package/src/nodes/core/OutputStructNode.js +19 -9
  83. package/src/nodes/core/StackNode.js +20 -1
  84. package/src/nodes/core/StructNode.js +121 -0
  85. package/src/nodes/core/StructType.js +13 -0
  86. package/src/nodes/core/StructTypeNode.js +82 -21
  87. package/src/nodes/core/TempNode.js +1 -1
  88. package/src/nodes/core/VarNode.js +94 -7
  89. package/src/nodes/core/VaryingNode.js +19 -3
  90. package/src/nodes/display/BlendModes.js +88 -1
  91. package/src/nodes/display/BumpMapNode.js +6 -6
  92. package/src/nodes/display/NormalMapNode.js +6 -6
  93. package/src/nodes/display/PassNode.js +3 -1
  94. package/src/nodes/display/ScreenNode.js +9 -0
  95. package/src/nodes/fog/Fog.js +17 -0
  96. package/src/nodes/gpgpu/AtomicFunctionNode.js +20 -4
  97. package/src/nodes/gpgpu/ComputeBuiltinNode.js +8 -0
  98. package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
  99. package/src/nodes/lighting/ShadowNode.js +1 -1
  100. package/src/nodes/math/ConditionalNode.js +8 -1
  101. package/src/nodes/math/MathNode.js +14 -1
  102. package/src/nodes/math/OperatorNode.js +96 -18
  103. package/src/nodes/pmrem/PMREMUtils.js +1 -1
  104. package/src/nodes/shapes/Shapes.js +33 -0
  105. package/src/nodes/tsl/TSLBase.js +1 -0
  106. package/src/nodes/tsl/TSLCore.js +22 -2
  107. package/src/nodes/utils/ArrayElementNode.js +1 -1
  108. package/src/nodes/utils/LoopNode.js +8 -1
  109. package/src/nodes/utils/MemberNode.js +68 -0
  110. package/src/nodes/utils/StorageArrayElementNode.js +14 -0
  111. package/src/nodes/utils/Timer.js +21 -0
  112. package/src/objects/BatchedMesh.js +1 -1
  113. package/src/objects/Line.js +6 -6
  114. package/src/renderers/WebGLRenderer.js +7 -0
  115. package/src/renderers/common/Animation.js +23 -1
  116. package/src/renderers/common/Backend.js +58 -15
  117. package/src/renderers/common/Background.js +14 -0
  118. package/src/renderers/common/Binding.js +1 -1
  119. package/src/renderers/common/BufferUtils.js +1 -1
  120. package/src/renderers/common/BundleGroup.js +1 -1
  121. package/src/renderers/common/ChainMap.js +9 -7
  122. package/src/renderers/common/ClippingContext.js +1 -1
  123. package/src/renderers/common/Color4.js +7 -3
  124. package/src/renderers/common/Geometries.js +2 -23
  125. package/src/renderers/common/Info.js +1 -45
  126. package/src/renderers/common/Lighting.js +8 -6
  127. package/src/renderers/common/Pipelines.js +3 -3
  128. package/src/renderers/common/PostProcessing.js +24 -8
  129. package/src/renderers/common/QuadMesh.js +1 -1
  130. package/src/renderers/common/RenderBundles.js +9 -3
  131. package/src/renderers/common/RenderContext.js +37 -3
  132. package/src/renderers/common/RenderContexts.js +30 -17
  133. package/src/renderers/common/RenderList.js +2 -2
  134. package/src/renderers/common/RenderLists.js +9 -3
  135. package/src/renderers/common/RenderObject.js +76 -17
  136. package/src/renderers/common/RenderObjects.js +9 -7
  137. package/src/renderers/common/Renderer.js +86 -67
  138. package/src/renderers/common/SampledTexture.js +0 -1
  139. package/src/renderers/common/StorageBufferAttribute.js +1 -1
  140. package/src/renderers/common/StorageInstancedBufferAttribute.js +1 -1
  141. package/src/renderers/common/StorageTexture.js +1 -1
  142. package/src/renderers/common/Textures.js +14 -7
  143. package/src/renderers/common/TimestampQueryPool.js +39 -0
  144. package/src/renderers/common/Uniform.js +37 -1
  145. package/src/renderers/common/UniformsGroup.js +2 -0
  146. package/src/renderers/common/XRManager.js +1193 -0
  147. package/src/renderers/common/XRRenderTarget.js +74 -0
  148. package/src/renderers/common/extras/PMREMGenerator.js +53 -8
  149. package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
  150. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  151. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -1
  152. package/src/renderers/common/nodes/NodeUniform.js +54 -2
  153. package/src/renderers/common/nodes/Nodes.js +25 -18
  154. package/src/renderers/webgl/WebGLBackground.js +4 -0
  155. package/src/renderers/webgl-fallback/WebGLBackend.js +295 -110
  156. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -17
  157. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +57 -0
  158. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  159. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  160. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  161. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +167 -21
  162. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  163. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  164. package/src/renderers/webgpu/WebGPUBackend.js +132 -149
  165. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +6 -4
  166. package/src/renderers/webgpu/WebGPURenderer.js +5 -4
  167. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +615 -41
  168. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +85 -6
  169. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +85 -0
  170. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  171. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  172. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +257 -9
  173. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  174. package/src/renderers/webgpu/utils/WebGPUUtils.js +86 -4
  175. package/src/renderers/webxr/WebXRManager.js +13 -2
  176. package/src/textures/VideoFrameTexture.js +35 -0
  177. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  178. package/examples/jsm/objects/InstancedPoints.js +0 -19
  179. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -209
  180. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -37
@@ -24,14 +24,35 @@ const typeArraysToVertexFormatPrefixForItemSize1 = new Map( [
24
24
  [ Float32Array, 'float32' ]
25
25
  ] );
26
26
 
27
+ /**
28
+ * A WebGPU backend utility module for managing shader attributes.
29
+ *
30
+ * @private
31
+ */
27
32
  class WebGPUAttributeUtils {
28
33
 
34
+ /**
35
+ * Constructs a new utility object.
36
+ *
37
+ * @param {WebGPUBackend} backend - The WebGPU backend.
38
+ */
29
39
  constructor( backend ) {
30
40
 
41
+ /**
42
+ * A reference to the WebGPU backend.
43
+ *
44
+ * @type {WebGPUBackend}
45
+ */
31
46
  this.backend = backend;
32
47
 
33
48
  }
34
49
 
50
+ /**
51
+ * Creates the GPU buffer for the given buffer attribute.
52
+ *
53
+ * @param {BufferAttribute} attribute - The buffer attribute.
54
+ * @param {GPUBufferUsage} usage - A flag that indicates how the buffer may be used after its creation.
55
+ */
35
56
  createAttribute( attribute, usage ) {
36
57
 
37
58
  const bufferAttribute = this._getBufferAttribute( attribute );
@@ -48,16 +69,27 @@ class WebGPUAttributeUtils {
48
69
  let array = bufferAttribute.array;
49
70
 
50
71
  // patch for INT16 and UINT16
51
- if ( attribute.normalized === false && ( array.constructor === Int16Array || array.constructor === Uint16Array ) ) {
72
+ if ( attribute.normalized === false ) {
52
73
 
53
- const tempArray = new Uint32Array( array.length );
54
- for ( let i = 0; i < array.length; i ++ ) {
74
+ if ( array.constructor === Int16Array ) {
55
75
 
56
- tempArray[ i ] = array[ i ];
76
+ array = new Int32Array( array );
57
77
 
58
- }
78
+ } else if ( array.constructor === Uint16Array ) {
79
+
80
+ array = new Uint32Array( array );
81
+
82
+ if ( usage & GPUBufferUsage.INDEX ) {
83
+
84
+ for ( let i = 0; i < array.length; i ++ ) {
59
85
 
60
- array = tempArray;
86
+ if ( array[ i ] === 0xffff ) array[ i ] = 0xffffffff; // use correct primitive restart index
87
+
88
+ }
89
+
90
+ }
91
+
92
+ }
61
93
 
62
94
  }
63
95
 
@@ -98,6 +130,11 @@ class WebGPUAttributeUtils {
98
130
 
99
131
  }
100
132
 
133
+ /**
134
+ * Updates the GPU buffer of the given buffer attribute.
135
+ *
136
+ * @param {BufferAttribute} attribute - The buffer attribute.
137
+ */
101
138
  updateAttribute( attribute ) {
102
139
 
103
140
  const bufferAttribute = this._getBufferAttribute( attribute );
@@ -149,6 +186,13 @@ class WebGPUAttributeUtils {
149
186
 
150
187
  }
151
188
 
189
+ /**
190
+ * This method creates the vertex buffer layout data which are
191
+ * require when creating a render pipeline for the given render object.
192
+ *
193
+ * @param {RenderObject} renderObject - The render object.
194
+ * @return {Array<Object>} An array holding objects which describe the vertex buffer layout.
195
+ */
152
196
  createShaderVertexBuffers( renderObject ) {
153
197
 
154
198
  const attributes = renderObject.getAttributes();
@@ -210,6 +254,11 @@ class WebGPUAttributeUtils {
210
254
 
211
255
  }
212
256
 
257
+ /**
258
+ * Destroys the GPU buffer of the given buffer attribute.
259
+ *
260
+ * @param {BufferAttribute} attribute - The buffer attribute.
261
+ */
213
262
  destroyAttribute( attribute ) {
214
263
 
215
264
  const backend = this.backend;
@@ -221,6 +270,14 @@ class WebGPUAttributeUtils {
221
270
 
222
271
  }
223
272
 
273
+ /**
274
+ * This method performs a readback operation by moving buffer data from
275
+ * a storage buffer attribute from the GPU to the CPU.
276
+ *
277
+ * @async
278
+ * @param {StorageBufferAttribute} attribute - The storage buffer attribute.
279
+ * @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
280
+ */
224
281
  async getArrayBufferAsync( attribute ) {
225
282
 
226
283
  const backend = this.backend;
@@ -263,6 +320,13 @@ class WebGPUAttributeUtils {
263
320
 
264
321
  }
265
322
 
323
+ /**
324
+ * Returns the vertex format of the given buffer attribute.
325
+ *
326
+ * @private
327
+ * @param {BufferAttribute} geometryAttribute - The buffer attribute.
328
+ * @return {String} The vertex format (e.g. 'float32x3').
329
+ */
266
330
  _getVertexFormat( geometryAttribute ) {
267
331
 
268
332
  const { itemSize, normalized } = geometryAttribute;
@@ -308,12 +372,27 @@ class WebGPUAttributeUtils {
308
372
 
309
373
  }
310
374
 
375
+ /**
376
+ * Returns `true` if the given array is a typed array.
377
+ *
378
+ * @private
379
+ * @param {Any} array - The array.
380
+ * @return {Boolean} Whether the given array is a typed array or not.
381
+ */
311
382
  _isTypedArray( array ) {
312
383
 
313
384
  return ArrayBuffer.isView( array ) && ! ( array instanceof DataView );
314
385
 
315
386
  }
316
387
 
388
+ /**
389
+ * Utility method for handling interleaved buffer attributes correctly.
390
+ * To process them, their `InterleavedBuffer` is returned.
391
+ *
392
+ * @private
393
+ * @param {BufferAttribute} attribute - The attribute.
394
+ * @return {BufferAttribute|InterleavedBuffer}
395
+ */
317
396
  _getBufferAttribute( attribute ) {
318
397
 
319
398
  if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
@@ -5,15 +5,47 @@ import {
5
5
  import { FloatType, IntType, UnsignedIntType } from '../../../constants.js';
6
6
  import { NodeAccess } from '../../../nodes/core/constants.js';
7
7
 
8
+ /**
9
+ * A WebGPU backend utility module for managing bindings.
10
+ *
11
+ * When reading the documentation it's helpful to keep in mind that
12
+ * all class definitions starting with 'GPU*' are modules from the
13
+ * WebGPU API. So for example `BindGroup` is a class from the engine
14
+ * whereas `GPUBindGroup` is a class from WebGPU.
15
+ *
16
+ * @private
17
+ */
8
18
  class WebGPUBindingUtils {
9
19
 
20
+ /**
21
+ * Constructs a new utility object.
22
+ *
23
+ * @param {WebGPUBackend} backend - The WebGPU backend.
24
+ */
10
25
  constructor( backend ) {
11
26
 
27
+ /**
28
+ * A reference to the WebGPU backend.
29
+ *
30
+ * @type {WebGPUBackend}
31
+ */
12
32
  this.backend = backend;
33
+
34
+ /**
35
+ * A cache for managing bind group layouts.
36
+ *
37
+ * @type {WeakMap<Array<Binding>,GPUBindGroupLayout>}
38
+ */
13
39
  this.bindGroupLayoutCache = new WeakMap();
14
40
 
15
41
  }
16
42
 
43
+ /**
44
+ * Creates a GPU bind group layout for the given bind group.
45
+ *
46
+ * @param {BindGroup} bindGroup - The bind group.
47
+ * @return {GPUBindGroupLayout} The GPU bind group layout.
48
+ */
17
49
  createBindingsLayout( bindGroup ) {
18
50
 
19
51
  const backend = this.backend;
@@ -183,6 +215,14 @@ class WebGPUBindingUtils {
183
215
 
184
216
  }
185
217
 
218
+ /**
219
+ * Creates bindings from the given bind group definition.
220
+ *
221
+ * @param {BindGroup} bindGroup - The bind group.
222
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
223
+ * @param {Number} cacheIndex - The cache index.
224
+ * @param {Number} version - The version.
225
+ */
186
226
  createBindings( bindGroup, bindings, cacheIndex, version = 0 ) {
187
227
 
188
228
  const { backend, bindGroupLayoutCache } = this;
@@ -236,6 +276,11 @@ class WebGPUBindingUtils {
236
276
 
237
277
  }
238
278
 
279
+ /**
280
+ * Updates a buffer binding.
281
+ *
282
+ * @param {Buffer} binding - The buffer binding to update.
283
+ */
239
284
  updateBinding( binding ) {
240
285
 
241
286
  const backend = this.backend;
@@ -248,6 +293,46 @@ class WebGPUBindingUtils {
248
293
 
249
294
  }
250
295
 
296
+ /**
297
+ * Creates a GPU bind group for the camera index.
298
+ *
299
+ * @param {Uint32Array} data - The index data.
300
+ * @param {GPUBindGroupLayout} layout - The GPU bind group layout.
301
+ * @return {GPUBindGroup} The GPU bind group.
302
+ */
303
+ createBindGroupIndex( data, layout ) {
304
+
305
+ const backend = this.backend;
306
+ const device = backend.device;
307
+
308
+ const usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;
309
+ const index = data[ 0 ];
310
+
311
+ const buffer = device.createBuffer( {
312
+ label: 'bindingCameraIndex_' + index,
313
+ size: 16, // uint(4) * 4
314
+ usage: usage
315
+ } );
316
+
317
+ device.queue.writeBuffer( buffer, 0, data, 0 );
318
+
319
+ const entries = [ { binding: 0, resource: { buffer } } ];
320
+
321
+ return device.createBindGroup( {
322
+ label: 'bindGroupCameraIndex_' + index,
323
+ layout,
324
+ entries
325
+ } );
326
+
327
+ }
328
+
329
+ /**
330
+ * Creates a GPU bind group for the given bind group and GPU layout.
331
+ *
332
+ * @param {BindGroup} bindGroup - The bind group.
333
+ * @param {GPUBindGroupLayout} layoutGPU - The GPU bind group layout.
334
+ * @return {GPUBindGroup} The GPU bind group.
335
+ */
251
336
  createBindGroup( bindGroup, layoutGPU ) {
252
337
 
253
338
  const backend = this.backend;
@@ -15,20 +15,48 @@ import {
15
15
  NeverStencilFunc, AlwaysStencilFunc, LessStencilFunc, LessEqualStencilFunc, EqualStencilFunc, GreaterEqualStencilFunc, GreaterStencilFunc, NotEqualStencilFunc
16
16
  } from '../../../constants.js';
17
17
 
18
+ /**
19
+ * A WebGPU backend utility module for managing pipelines.
20
+ *
21
+ * @private
22
+ */
18
23
  class WebGPUPipelineUtils {
19
24
 
25
+ /**
26
+ * Constructs a new utility object.
27
+ *
28
+ * @param {WebGPUBackend} backend - The WebGPU backend.
29
+ */
20
30
  constructor( backend ) {
21
31
 
32
+ /**
33
+ * A reference to the WebGPU backend.
34
+ *
35
+ * @type {WebGPUBackend}
36
+ */
22
37
  this.backend = backend;
23
38
 
24
39
  }
25
40
 
26
- _getSampleCount( renderObjectContext ) {
41
+ /**
42
+ * Returns the sample count derived from the given render context.
43
+ *
44
+ * @private
45
+ * @param {RenderContext} renderContext - The render context.
46
+ * @return {Number} The sample count.
47
+ */
48
+ _getSampleCount( renderContext ) {
27
49
 
28
- return this.backend.utils.getSampleCountRenderContext( renderObjectContext );
50
+ return this.backend.utils.getSampleCountRenderContext( renderContext );
29
51
 
30
52
  }
31
53
 
54
+ /**
55
+ * Creates a render pipeline for the given render object.
56
+ *
57
+ * @param {RenderObject} renderObject - The render object.
58
+ * @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
59
+ */
32
60
  createRenderPipeline( renderObject, promises ) {
33
61
 
34
62
  const { object, material, geometry, pipeline } = renderObject;
@@ -188,6 +216,12 @@ class WebGPUPipelineUtils {
188
216
 
189
217
  }
190
218
 
219
+ /**
220
+ * Creates GPU render bundle encoder for the given render context.
221
+ *
222
+ * @param {RenderContext} renderContext - The render context.
223
+ * @return {GPURenderBundleEncoder} The GPU render bundle encoder.
224
+ */
191
225
  createBundleEncoder( renderContext ) {
192
226
 
193
227
  const backend = this.backend;
@@ -208,6 +242,12 @@ class WebGPUPipelineUtils {
208
242
 
209
243
  }
210
244
 
245
+ /**
246
+ * Creates a compute pipeline for the given compute node.
247
+ *
248
+ * @param {ComputePipeline} pipeline - The compute pipeline.
249
+ * @param {Array<BindGroup>} bindings - The bindings.
250
+ */
211
251
  createComputePipeline( pipeline, bindings ) {
212
252
 
213
253
  const backend = this.backend;
@@ -238,6 +278,14 @@ class WebGPUPipelineUtils {
238
278
 
239
279
  }
240
280
 
281
+ /**
282
+ * Returns the blending state as a descriptor object required
283
+ * for the pipeline creation.
284
+ *
285
+ * @private
286
+ * @param {Material} material - The material.
287
+ * @return {Object} The blending state.
288
+ */
241
289
  _getBlending( material ) {
242
290
 
243
291
  let color, alpha;
@@ -345,7 +393,13 @@ class WebGPUPipelineUtils {
345
393
  }
346
394
 
347
395
  }
348
-
396
+ /**
397
+ * Returns the GPU blend factor which is required for the pipeline creation.
398
+ *
399
+ * @private
400
+ * @param {Number} blend - The blend factor as a three.js constant.
401
+ * @return {String} The GPU blend factor.
402
+ */
349
403
  _getBlendFactor( blend ) {
350
404
 
351
405
  let blendFactor;
@@ -413,6 +467,13 @@ class WebGPUPipelineUtils {
413
467
 
414
468
  }
415
469
 
470
+ /**
471
+ * Returns the GPU stencil compare function which is required for the pipeline creation.
472
+ *
473
+ * @private
474
+ * @param {Material} material - The material.
475
+ * @return {String} The GPU stencil compare function.
476
+ */
416
477
  _getStencilCompare( material ) {
417
478
 
418
479
  let stencilCompare;
@@ -462,6 +523,13 @@ class WebGPUPipelineUtils {
462
523
 
463
524
  }
464
525
 
526
+ /**
527
+ * Returns the GPU stencil operation which is required for the pipeline creation.
528
+ *
529
+ * @private
530
+ * @param {Number} op - A three.js constant defining the stencil operation.
531
+ * @return {String} The GPU stencil operation.
532
+ */
465
533
  _getStencilOperation( op ) {
466
534
 
467
535
  let stencilOperation;
@@ -509,6 +577,13 @@ class WebGPUPipelineUtils {
509
577
 
510
578
  }
511
579
 
580
+ /**
581
+ * Returns the GPU blend operation which is required for the pipeline creation.
582
+ *
583
+ * @private
584
+ * @param {Number} blendEquation - A three.js constant defining the blend equation.
585
+ * @return {String} The GPU blend operation.
586
+ */
512
587
  _getBlendOperation( blendEquation ) {
513
588
 
514
589
  let blendOperation;
@@ -544,6 +619,16 @@ class WebGPUPipelineUtils {
544
619
 
545
620
  }
546
621
 
622
+ /**
623
+ * Returns the primitive state as a descriptor object required
624
+ * for the pipeline creation.
625
+ *
626
+ * @private
627
+ * @param {Object3D} object - The 3D object.
628
+ * @param {BufferGeometry} geometry - The geometry.
629
+ * @param {Material} material - The material.
630
+ * @return {Object} The primitive state.
631
+ */
547
632
  _getPrimitiveState( object, geometry, material ) {
548
633
 
549
634
  const descriptor = {};
@@ -584,12 +669,26 @@ class WebGPUPipelineUtils {
584
669
 
585
670
  }
586
671
 
672
+ /**
673
+ * Returns the GPU color write mask which is required for the pipeline creation.
674
+ *
675
+ * @private
676
+ * @param {Material} material - The material.
677
+ * @return {String} The GPU color write mask.
678
+ */
587
679
  _getColorWriteMask( material ) {
588
680
 
589
681
  return ( material.colorWrite === true ) ? GPUColorWriteFlags.All : GPUColorWriteFlags.None;
590
682
 
591
683
  }
592
684
 
685
+ /**
686
+ * Returns the GPU depth compare function which is required for the pipeline creation.
687
+ *
688
+ * @private
689
+ * @param {Material} material - The material.
690
+ * @return {String} The GPU depth compare function.
691
+ */
593
692
  _getDepthCompare( material ) {
594
693
 
595
694
  let depthCompare;
@@ -1,12 +1,27 @@
1
1
  import DataMap from '../../common/DataMap.js';
2
2
  import { GPUTextureViewDimension, GPUIndexFormat, GPUFilterMode, GPUPrimitiveTopology, GPULoadOp, GPUStoreOp } from './WebGPUConstants.js';
3
3
 
4
+ /**
5
+ * A WebGPU backend utility module used by {@link WebGPUTextureUtils}.
6
+ *
7
+ * @private
8
+ */
4
9
  class WebGPUTexturePassUtils extends DataMap {
5
10
 
11
+ /**
12
+ * Constructs a new utility object.
13
+ *
14
+ * @param {GPUDevice} device - The WebGPU device.
15
+ */
6
16
  constructor( device ) {
7
17
 
8
18
  super();
9
19
 
20
+ /**
21
+ * The WebGPU device.
22
+ *
23
+ * @type {GPUDevice}
24
+ */
10
25
  this.device = device;
11
26
 
12
27
  const mipmapVertexSource = `
@@ -71,23 +86,62 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
71
86
 
72
87
  }
73
88
  `;
89
+
90
+ /**
91
+ * The mipmap GPU sampler.
92
+ *
93
+ * @type {GPUSampler}
94
+ */
74
95
  this.mipmapSampler = device.createSampler( { minFilter: GPUFilterMode.Linear } );
96
+
97
+ /**
98
+ * The flipY GPU sampler.
99
+ *
100
+ * @type {GPUSampler}
101
+ */
75
102
  this.flipYSampler = device.createSampler( { minFilter: GPUFilterMode.Nearest } ); //@TODO?: Consider using textureLoad()
76
103
 
77
- // We'll need a new pipeline for every texture format used.
104
+ /**
105
+ * A cache for GPU render pipelines used for copy/transfer passes.
106
+ * Every texture format requires a unique pipeline.
107
+ *
108
+ * @type {Object<String,GPURenderPipeline>}
109
+ */
78
110
  this.transferPipelines = {};
111
+
112
+ /**
113
+ * A cache for GPU render pipelines used for flipY passes.
114
+ * Every texture format requires a unique pipeline.
115
+ *
116
+ * @type {Object<String,GPURenderPipeline>}
117
+ */
79
118
  this.flipYPipelines = {};
80
119
 
120
+ /**
121
+ * The mipmap vertex shader module.
122
+ *
123
+ * @type {GPUShaderModule}
124
+ */
81
125
  this.mipmapVertexShaderModule = device.createShaderModule( {
82
126
  label: 'mipmapVertex',
83
127
  code: mipmapVertexSource
84
128
  } );
85
129
 
130
+ /**
131
+ * The mipmap fragment shader module.
132
+ *
133
+ * @type {GPUShaderModule}
134
+ */
86
135
  this.mipmapFragmentShaderModule = device.createShaderModule( {
87
136
  label: 'mipmapFragment',
88
137
  code: mipmapFragmentSource
89
138
  } );
90
139
 
140
+ /**
141
+ * The flipY fragment shader module.
142
+ *
143
+ * @type {GPUShaderModule}
144
+ */
91
145
  this.flipYFragmentShaderModule = device.createShaderModule( {
92
146
  label: 'flipYFragment',
93
147
  code: flipYFragmentSource
@@ -95,6 +149,13 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
95
149
 
96
150
  }
97
151
 
152
+ /**
153
+ * Returns a render pipeline for the internal copy render pass. The pass
154
+ * requires a unique render pipeline for each texture format.
155
+ *
156
+ * @param {String} format - The GPU texture format
157
+ * @return {GPURenderPipeline} The GPU render pipeline.
158
+ */
98
159
  getTransferPipeline( format ) {
99
160
 
100
161
  let pipeline = this.transferPipelines[ format ];
@@ -127,6 +188,13 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
127
188
 
128
189
  }
129
190
 
191
+ /**
192
+ * Returns a render pipeline for the flipY render pass. The pass
193
+ * requires a unique render pipeline for each texture format.
194
+ *
195
+ * @param {String} format - The GPU texture format
196
+ * @return {GPURenderPipeline} The GPU render pipeline.
197
+ */
130
198
  getFlipYPipeline( format ) {
131
199
 
132
200
  let pipeline = this.flipYPipelines[ format ];
@@ -159,6 +227,13 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
159
227
 
160
228
  }
161
229
 
230
+ /**
231
+ * Flip the contents of the given GPU texture along its vertical axis.
232
+ *
233
+ * @param {GPUTexture} textureGPU - The GPU texture object.
234
+ * @param {Object} textureGPUDescriptor - The texture descriptor.
235
+ * @param {Number} [baseArrayLayer=0] - The index of the first array layer accessible to the texture view.
236
+ */
162
237
  flipY( textureGPU, textureGPUDescriptor, baseArrayLayer = 0 ) {
163
238
 
164
239
  const format = textureGPUDescriptor.format;
@@ -229,6 +304,13 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
229
304
 
230
305
  }
231
306
 
307
+ /**
308
+ * Generates mipmaps for the given GPU texture.
309
+ *
310
+ * @param {GPUTexture} textureGPU - The GPU texture object.
311
+ * @param {Object} textureGPUDescriptor - The texture descriptor.
312
+ * @param {Number} [baseArrayLayer=0] - The index of the first array layer accessible to the texture view.
313
+ */
232
314
  generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer = 0 ) {
233
315
 
234
316
  const textureData = this.get( textureGPU );
@@ -254,6 +336,15 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
254
336
 
255
337
  }
256
338
 
339
+ /**
340
+ * Since multiple copy render passes are required to generate mipmaps, the passes
341
+ * are managed as render bundles to improve performance.
342
+ *
343
+ * @param {GPUTexture} textureGPU - The GPU texture object.
344
+ * @param {Object} textureGPUDescriptor - The texture descriptor.
345
+ * @param {Number} baseArrayLayer - The index of the first array layer accessible to the texture view.
346
+ * @return {Array} An array of render bundles.
347
+ */
257
348
  _mipmapCreateBundles( textureGPU, textureGPUDescriptor, baseArrayLayer ) {
258
349
 
259
350
  const pipeline = this.getTransferPipeline( textureGPUDescriptor.format );
@@ -319,6 +410,12 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
319
410
 
320
411
  }
321
412
 
413
+ /**
414
+ * Executes the render bundles.
415
+ *
416
+ * @param {GPUCommandEncoder} commandEncoder - The GPU command encoder.
417
+ * @param {Array} passes - An array of render bundles.
418
+ */
322
419
  _mipmapRunBundles( commandEncoder, passes ) {
323
420
 
324
421
  const levels = passes.length;