@onerjs/core 9.0.2 → 9.0.4

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 (476) hide show
  1. package/Buffers/buffer.pure.js +4 -0
  2. package/Buffers/buffer.pure.js.map +1 -1
  3. package/Cameras/camera.pure.d.ts +14 -0
  4. package/Cameras/camera.pure.js +15 -0
  5. package/Cameras/camera.pure.js.map +1 -1
  6. package/Compute/computeShader.pure.d.ts +2 -1
  7. package/Compute/computeShader.pure.js +29 -10
  8. package/Compute/computeShader.pure.js.map +1 -1
  9. package/Culling/ray.core.js +22 -9
  10. package/Culling/ray.core.js.map +1 -1
  11. package/Engines/IDrawContext.d.ts +2 -0
  12. package/Engines/IDrawContext.js.map +1 -1
  13. package/Engines/Native/nativeInterfaces.d.ts +55 -4
  14. package/Engines/Native/nativeInterfaces.js.map +1 -1
  15. package/Engines/Native/nativeRenderTargetWrapper.d.ts +1 -0
  16. package/Engines/Native/nativeRenderTargetWrapper.js +5 -1
  17. package/Engines/Native/nativeRenderTargetWrapper.js.map +1 -1
  18. package/Engines/Processors/shaderCodeInliner.d.ts +2 -0
  19. package/Engines/Processors/shaderCodeInliner.js +251 -6
  20. package/Engines/Processors/shaderCodeInliner.js.map +1 -1
  21. package/Engines/Processors/shaderProcessor.js +10 -1
  22. package/Engines/Processors/shaderProcessor.js.map +1 -1
  23. package/Engines/WebGPU/Extensions/engine.debugging.pure.js +12 -0
  24. package/Engines/WebGPU/Extensions/engine.debugging.pure.js.map +1 -1
  25. package/Engines/WebGPU/Extensions/engine.multiRender.pure.js +0 -1
  26. package/Engines/WebGPU/Extensions/engine.multiRender.pure.js.map +1 -1
  27. package/Engines/WebGPU/Extensions/engine.query.pure.js +5 -0
  28. package/Engines/WebGPU/Extensions/engine.query.pure.js.map +1 -1
  29. package/Engines/WebGPU/webgpuBufferManager.js +7 -0
  30. package/Engines/WebGPU/webgpuBufferManager.js.map +1 -1
  31. package/Engines/WebGPU/webgpuCacheTextureView.d.ts +1 -1
  32. package/Engines/WebGPU/webgpuCacheTextureView.js +20 -8
  33. package/Engines/WebGPU/webgpuCacheTextureView.js.map +1 -1
  34. package/Engines/WebGPU/webgpuDrawContext.d.ts +2 -0
  35. package/Engines/WebGPU/webgpuDrawContext.js +6 -0
  36. package/Engines/WebGPU/webgpuDrawContext.js.map +1 -1
  37. package/Engines/WebGPU/webgpuQuerySet.d.ts +3 -3
  38. package/Engines/WebGPU/webgpuQuerySet.js +23 -9
  39. package/Engines/WebGPU/webgpuQuerySet.js.map +1 -1
  40. package/Engines/WebGPU/webgpuRenderPassCommandStream.d.ts +156 -0
  41. package/Engines/WebGPU/webgpuRenderPassCommandStream.js +323 -0
  42. package/Engines/WebGPU/webgpuRenderPassCommandStream.js.map +1 -0
  43. package/Engines/WebGPU/webgpuTextureManager.d.ts +1 -1
  44. package/Engines/WebGPU/webgpuTextureManager.js +4 -3
  45. package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
  46. package/Engines/WebGPU/webgpuTimestampQuery.d.ts +3 -1
  47. package/Engines/WebGPU/webgpuTimestampQuery.js +9 -6
  48. package/Engines/WebGPU/webgpuTimestampQuery.js.map +1 -1
  49. package/Engines/abstractEngine.pure.d.ts +2 -0
  50. package/Engines/abstractEngine.pure.js +14 -5
  51. package/Engines/abstractEngine.pure.js.map +1 -1
  52. package/Engines/constants.d.ts +6 -0
  53. package/Engines/constants.js +6 -0
  54. package/Engines/constants.js.map +1 -1
  55. package/Engines/engine.d.ts +198 -24
  56. package/Engines/pure.d.ts +1 -0
  57. package/Engines/pure.js +1 -0
  58. package/Engines/pure.js.map +1 -1
  59. package/Engines/renderCommandBatcher.pure.d.ts +16 -0
  60. package/Engines/renderCommandBatcher.pure.js +24 -0
  61. package/Engines/renderCommandBatcher.pure.js.map +1 -0
  62. package/Engines/thinEngine.functions.js +3 -2
  63. package/Engines/thinEngine.functions.js.map +1 -1
  64. package/Engines/thinEngine.pure.js +18 -2
  65. package/Engines/thinEngine.pure.js.map +1 -1
  66. package/Engines/thinNativeEngine.pure.d.ts +10 -7
  67. package/Engines/thinNativeEngine.pure.js +117 -46
  68. package/Engines/thinNativeEngine.pure.js.map +1 -1
  69. package/Engines/thinWebGPUEngine.d.ts +8 -0
  70. package/Engines/thinWebGPUEngine.js +11 -0
  71. package/Engines/thinWebGPUEngine.js.map +1 -1
  72. package/Engines/webgpuEngine.pure.d.ts +60 -1
  73. package/Engines/webgpuEngine.pure.js +238 -42
  74. package/Engines/webgpuEngine.pure.js.map +1 -1
  75. package/FlowGraph/Blocks/Data/Audio/flowGraphGetSoundVolumeBlock.pure.d.ts +3 -3
  76. package/FlowGraph/Blocks/Data/Audio/flowGraphGetSoundVolumeBlock.pure.js +2 -1
  77. package/FlowGraph/Blocks/Data/Audio/flowGraphGetSoundVolumeBlock.pure.js.map +1 -1
  78. package/FlowGraph/Blocks/Data/Audio/flowGraphIsSoundPlayingBlock.pure.d.ts +3 -3
  79. package/FlowGraph/Blocks/Data/Audio/flowGraphIsSoundPlayingBlock.pure.js +2 -1
  80. package/FlowGraph/Blocks/Data/Audio/flowGraphIsSoundPlayingBlock.pure.js.map +1 -1
  81. package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.d.ts +5 -0
  82. package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.js +8 -0
  83. package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.js.map +1 -0
  84. package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.pure.d.ts +77 -0
  85. package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.pure.js +141 -0
  86. package/FlowGraph/Blocks/Event/flowGraphMeshIntersectionEventBlock.pure.js.map +1 -0
  87. package/FlowGraph/Blocks/Event/flowGraphSoundEndedEventBlock.pure.d.ts +5 -3
  88. package/FlowGraph/Blocks/Event/flowGraphSoundEndedEventBlock.pure.js +38 -7
  89. package/FlowGraph/Blocks/Event/flowGraphSoundEndedEventBlock.pure.js.map +1 -1
  90. package/FlowGraph/Blocks/Event/index.d.ts +1 -0
  91. package/FlowGraph/Blocks/Event/index.js +1 -0
  92. package/FlowGraph/Blocks/Event/index.js.map +1 -1
  93. package/FlowGraph/Blocks/Event/pure.d.ts +1 -0
  94. package/FlowGraph/Blocks/Event/pure.js +1 -0
  95. package/FlowGraph/Blocks/Event/pure.js.map +1 -1
  96. package/FlowGraph/Blocks/Execution/Audio/flowGraphPauseSoundBlock.pure.d.ts +3 -3
  97. package/FlowGraph/Blocks/Execution/Audio/flowGraphPauseSoundBlock.pure.js +2 -1
  98. package/FlowGraph/Blocks/Execution/Audio/flowGraphPauseSoundBlock.pure.js.map +1 -1
  99. package/FlowGraph/Blocks/Execution/Audio/flowGraphPlaySoundBlock.pure.d.ts +3 -3
  100. package/FlowGraph/Blocks/Execution/Audio/flowGraphPlaySoundBlock.pure.js +2 -1
  101. package/FlowGraph/Blocks/Execution/Audio/flowGraphPlaySoundBlock.pure.js.map +1 -1
  102. package/FlowGraph/Blocks/Execution/Audio/flowGraphSetSoundVolumeBlock.pure.d.ts +3 -3
  103. package/FlowGraph/Blocks/Execution/Audio/flowGraphSetSoundVolumeBlock.pure.js +2 -1
  104. package/FlowGraph/Blocks/Execution/Audio/flowGraphSetSoundVolumeBlock.pure.js.map +1 -1
  105. package/FlowGraph/Blocks/Execution/Audio/flowGraphStopSoundBlock.pure.d.ts +3 -3
  106. package/FlowGraph/Blocks/Execution/Audio/flowGraphStopSoundBlock.pure.js +2 -1
  107. package/FlowGraph/Blocks/Execution/Audio/flowGraphStopSoundBlock.pure.js.map +1 -1
  108. package/FlowGraph/Blocks/allBlocks.pure.js +2 -0
  109. package/FlowGraph/Blocks/allBlocks.pure.js.map +1 -1
  110. package/FlowGraph/Blocks/flowGraphBlockFactory.js +2 -0
  111. package/FlowGraph/Blocks/flowGraphBlockFactory.js.map +1 -1
  112. package/FlowGraph/Blocks/flowGraphBlockNames.d.ts +1 -0
  113. package/FlowGraph/Blocks/flowGraphBlockNames.js +1 -0
  114. package/FlowGraph/Blocks/flowGraphBlockNames.js.map +1 -1
  115. package/FlowGraph/flowGraph.d.ts +12 -1
  116. package/FlowGraph/flowGraph.js +38 -0
  117. package/FlowGraph/flowGraph.js.map +1 -1
  118. package/FlowGraph/flowGraphCoordinator.d.ts +44 -0
  119. package/FlowGraph/flowGraphCoordinator.js +141 -0
  120. package/FlowGraph/flowGraphCoordinator.js.map +1 -1
  121. package/FlowGraph/flowGraphDataConnection.pure.js +41 -14
  122. package/FlowGraph/flowGraphDataConnection.pure.js.map +1 -1
  123. package/FlowGraph/flowGraphParser.js +105 -5
  124. package/FlowGraph/flowGraphParser.js.map +1 -1
  125. package/FlowGraph/flowGraphSoundAssets.d.ts +40 -0
  126. package/FlowGraph/flowGraphSoundAssets.js +33 -0
  127. package/FlowGraph/flowGraphSoundAssets.js.map +1 -0
  128. package/FlowGraph/index.d.ts +1 -0
  129. package/FlowGraph/index.js +1 -0
  130. package/FlowGraph/index.js.map +1 -1
  131. package/FlowGraph/pure.d.ts +1 -0
  132. package/FlowGraph/pure.js +1 -0
  133. package/FlowGraph/pure.js.map +1 -1
  134. package/FlowGraph/serialization.d.ts +8 -0
  135. package/FlowGraph/serialization.js +31 -12
  136. package/FlowGraph/serialization.js.map +1 -1
  137. package/FlowGraph/typeDefinitions.d.ts +25 -0
  138. package/FlowGraph/typeDefinitions.js.map +1 -1
  139. package/FrameGraph/Tasks/PostProcesses/taaTask.js +2 -0
  140. package/FrameGraph/Tasks/PostProcesses/taaTask.js.map +1 -1
  141. package/Instrumentation/engineInstrumentation.d.ts +1 -0
  142. package/Instrumentation/engineInstrumentation.js +25 -6
  143. package/Instrumentation/engineInstrumentation.js.map +1 -1
  144. package/Lights/Clustered/clusteredLightContainer.pure.js +2 -0
  145. package/Lights/Clustered/clusteredLightContainer.pure.js.map +1 -1
  146. package/Lights/Shadows/cascadedShadowGenerator.pure.d.ts +36 -1
  147. package/Lights/Shadows/cascadedShadowGenerator.pure.js +202 -27
  148. package/Lights/Shadows/cascadedShadowGenerator.pure.js.map +1 -1
  149. package/Lights/directionalLight.pure.d.ts +24 -10
  150. package/Lights/directionalLight.pure.js +29 -11
  151. package/Lights/directionalLight.pure.js.map +1 -1
  152. package/Loading/sceneLoader.d.ts +1 -1
  153. package/Loading/sceneLoader.js +1 -1
  154. package/Loading/sceneLoader.js.map +1 -1
  155. package/Materials/GaussianSplatting/gaussianSplattingMaterial.pure.js +4 -4
  156. package/Materials/GaussianSplatting/gaussianSplattingMaterial.pure.js.map +1 -1
  157. package/Materials/Node/Blocks/Dual/lightBlock.pure.js +1 -1
  158. package/Materials/Node/Blocks/Dual/lightBlock.pure.js.map +1 -1
  159. package/Materials/Node/Blocks/Input/inputBlock.pure.js +4 -0
  160. package/Materials/Node/Blocks/Input/inputBlock.pure.js.map +1 -1
  161. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.d.ts +9 -0
  162. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js +23 -3
  163. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js.map +1 -1
  164. package/Materials/PBR/openpbrMaterial.pure.js +1 -1
  165. package/Materials/PBR/openpbrMaterial.pure.js.map +1 -1
  166. package/Materials/PBR/pbrBaseMaterial.pure.d.ts +9 -0
  167. package/Materials/PBR/pbrBaseMaterial.pure.js +60 -1
  168. package/Materials/PBR/pbrBaseMaterial.pure.js.map +1 -1
  169. package/Materials/PBR/pbrBaseSimpleMaterial.d.ts +11 -0
  170. package/Materials/PBR/pbrBaseSimpleMaterial.js +21 -2
  171. package/Materials/PBR/pbrBaseSimpleMaterial.js.map +1 -1
  172. package/Materials/PBR/pbrMaterial.pure.d.ts +12 -0
  173. package/Materials/PBR/pbrMaterial.pure.js +23 -3
  174. package/Materials/PBR/pbrMaterial.pure.js.map +1 -1
  175. package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +1 -0
  176. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +10 -0
  177. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -1
  178. package/Materials/Textures/HTML/htmlInCanvasPolyfill.d.ts +5 -0
  179. package/Materials/Textures/HTML/htmlInCanvasPolyfill.js +7 -0
  180. package/Materials/Textures/HTML/htmlInCanvasPolyfill.js.map +1 -1
  181. package/Materials/Textures/HTML/htmlInteractionManager.d.ts +9 -3
  182. package/Materials/Textures/HTML/htmlInteractionManager.js +64 -5
  183. package/Materials/Textures/HTML/htmlInteractionManager.js.map +1 -1
  184. package/Materials/Textures/HTML/htmlTexture.d.ts +11 -11
  185. package/Materials/Textures/HTML/htmlTexture.js +106 -65
  186. package/Materials/Textures/HTML/htmlTexture.js.map +1 -1
  187. package/Materials/Textures/Loaders/internalTextureLoader.d.ts +2 -1
  188. package/Materials/Textures/Loaders/internalTextureLoader.js.map +1 -1
  189. package/Materials/Textures/Loaders/ktxTextureLoader.d.ts +2 -1
  190. package/Materials/Textures/Loaders/ktxTextureLoader.js +4 -50
  191. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  192. package/Materials/Textures/Procedurals/proceduralTexture.pure.js +10 -0
  193. package/Materials/Textures/Procedurals/proceduralTexture.pure.js.map +1 -1
  194. package/Materials/Textures/dynamicTexture.pure.js +6 -0
  195. package/Materials/Textures/dynamicTexture.pure.js.map +1 -1
  196. package/Materials/Textures/ktx2encoderTypes.d.ts +51 -0
  197. package/Materials/Textures/ktx2encoderTypes.js +2 -0
  198. package/Materials/Textures/ktx2encoderTypes.js.map +1 -0
  199. package/Materials/Textures/renderTargetTexture.pure.js +10 -2
  200. package/Materials/Textures/renderTargetTexture.pure.js.map +1 -1
  201. package/Materials/Textures/textureMerger.d.ts +11 -0
  202. package/Materials/Textures/textureMerger.js +34 -19
  203. package/Materials/Textures/textureMerger.js.map +1 -1
  204. package/Materials/Textures/textureProcessor.d.ts +145 -0
  205. package/Materials/Textures/textureProcessor.js +445 -45
  206. package/Materials/Textures/textureProcessor.js.map +1 -1
  207. package/Materials/Textures/textureSampling.functions.d.ts +41 -0
  208. package/Materials/Textures/textureSampling.functions.js +82 -0
  209. package/Materials/Textures/textureSampling.functions.js.map +1 -0
  210. package/Materials/drawWrapper.d.ts +8 -0
  211. package/Materials/drawWrapper.js +19 -0
  212. package/Materials/drawWrapper.js.map +1 -1
  213. package/Materials/effect.pure.d.ts +6 -0
  214. package/Materials/effect.pure.js +28 -6
  215. package/Materials/effect.pure.js.map +1 -1
  216. package/Materials/effect.webgl.functions.pure.js +1 -1
  217. package/Materials/effect.webgl.functions.pure.js.map +1 -1
  218. package/Materials/material.pure.d.ts +5 -0
  219. package/Materials/material.pure.js +9 -2
  220. package/Materials/material.pure.js.map +1 -1
  221. package/Materials/materialFlags.d.ts +6 -0
  222. package/Materials/materialFlags.js +14 -0
  223. package/Materials/materialFlags.js.map +1 -1
  224. package/Materials/materialHelper.functions.d.ts +2 -1
  225. package/Materials/materialHelper.functions.js +36 -2
  226. package/Materials/materialHelper.functions.js.map +1 -1
  227. package/Materials/materialHelper.geometryrendering.js +19 -16
  228. package/Materials/materialHelper.geometryrendering.js.map +1 -1
  229. package/Materials/materialPluginManager.pure.js +12 -8
  230. package/Materials/materialPluginManager.pure.js.map +1 -1
  231. package/Materials/prePassConfiguration.js +19 -16
  232. package/Materials/prePassConfiguration.js.map +1 -1
  233. package/Materials/shaderMaterial.pure.js +19 -6
  234. package/Materials/shaderMaterial.pure.js.map +1 -1
  235. package/Materials/shadowDepthWrapper.d.ts +6 -0
  236. package/Materials/shadowDepthWrapper.js +17 -0
  237. package/Materials/shadowDepthWrapper.js.map +1 -1
  238. package/Meshes/Compression/dracoCodec.d.ts +14 -0
  239. package/Meshes/Compression/dracoCodec.js +22 -0
  240. package/Meshes/Compression/dracoCodec.js.map +1 -1
  241. package/Meshes/Compression/dracoDecoder.d.ts +1 -0
  242. package/Meshes/Compression/dracoDecoder.js +27 -0
  243. package/Meshes/Compression/dracoDecoder.js.map +1 -1
  244. package/Meshes/Compression/dracoEncoder.d.ts +1 -0
  245. package/Meshes/Compression/dracoEncoder.js +8 -0
  246. package/Meshes/Compression/dracoEncoder.js.map +1 -1
  247. package/Meshes/Compression/meshoptCompression.d.ts +1 -0
  248. package/Meshes/Compression/meshoptCompression.js +9 -0
  249. package/Meshes/Compression/meshoptCompression.js.map +1 -1
  250. package/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.d.ts +415 -0
  251. package/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.js +912 -0
  252. package/Meshes/GaussianSplatting/gaussianSplattingGpuSorter.js.map +1 -0
  253. package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.d.ts +3 -0
  254. package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js +40 -9
  255. package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js.map +1 -1
  256. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.d.ts +112 -8
  257. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js +696 -74
  258. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js.map +1 -1
  259. package/Meshes/abstractMesh.pure.js +12 -4
  260. package/Meshes/abstractMesh.pure.js.map +1 -1
  261. package/Meshes/geometry.d.ts +5 -0
  262. package/Meshes/geometry.js +25 -0
  263. package/Meshes/geometry.js.map +1 -1
  264. package/Meshes/index.d.ts +1 -0
  265. package/Meshes/index.js +1 -0
  266. package/Meshes/index.js.map +1 -1
  267. package/Meshes/mesh.pure.d.ts +7 -0
  268. package/Meshes/mesh.pure.js +18 -13
  269. package/Meshes/mesh.pure.js.map +1 -1
  270. package/Meshes/pure.d.ts +1 -0
  271. package/Meshes/pure.js +1 -0
  272. package/Meshes/pure.js.map +1 -1
  273. package/Meshes/subMesh.pure.d.ts +3 -0
  274. package/Meshes/subMesh.pure.js +26 -0
  275. package/Meshes/subMesh.pure.js.map +1 -1
  276. package/Meshes/thinInstanceMesh.pure.js +5 -3
  277. package/Meshes/thinInstanceMesh.pure.js.map +1 -1
  278. package/Misc/index.d.ts +1 -0
  279. package/Misc/index.js +1 -0
  280. package/Misc/index.js.map +1 -1
  281. package/Misc/khronosTextureContainer2.d.ts +3 -2
  282. package/Misc/khronosTextureContainer2.js +24 -6
  283. package/Misc/khronosTextureContainer2.js.map +1 -1
  284. package/Misc/khronosTextureContainer2Encoder.d.ts +166 -0
  285. package/Misc/khronosTextureContainer2Encoder.js +556 -0
  286. package/Misc/khronosTextureContainer2Encoder.js.map +1 -0
  287. package/Misc/khronosTextureContainer2EncoderWorker.d.ts +61 -0
  288. package/Misc/khronosTextureContainer2EncoderWorker.js +55 -0
  289. package/Misc/khronosTextureContainer2EncoderWorker.js.map +1 -0
  290. package/Misc/pure.d.ts +1 -0
  291. package/Misc/pure.js +1 -0
  292. package/Misc/pure.js.map +1 -1
  293. package/Misc/textureFormat.functions.d.ts +6 -0
  294. package/Misc/textureFormat.functions.js +54 -0
  295. package/Misc/textureFormat.functions.js.map +1 -0
  296. package/Misc/textureTools.d.ts +6 -2
  297. package/Misc/textureTools.js +100 -42
  298. package/Misc/textureTools.js.map +1 -1
  299. package/Misc/tools.pure.js +1 -1
  300. package/Misc/tools.pure.js.map +1 -1
  301. package/Particles/Node/Blocks/systemBlock.pure.d.ts +1 -1
  302. package/Particles/Node/Blocks/systemBlock.pure.js +6 -3
  303. package/Particles/Node/Blocks/systemBlock.pure.js.map +1 -1
  304. package/Particles/computeShaderParticleSystem.pure.js +5 -0
  305. package/Particles/computeShaderParticleSystem.pure.js.map +1 -1
  306. package/Particles/gpuParticleSystem.pure.d.ts +2 -0
  307. package/Particles/gpuParticleSystem.pure.js +25 -1
  308. package/Particles/gpuParticleSystem.pure.js.map +1 -1
  309. package/Particles/solidParticle.d.ts +5 -0
  310. package/Particles/solidParticle.js +5 -0
  311. package/Particles/solidParticle.js.map +1 -1
  312. package/Particles/solidParticleSystem.d.ts +10 -0
  313. package/Particles/solidParticleSystem.js +72 -13
  314. package/Particles/solidParticleSystem.js.map +1 -1
  315. package/Particles/thinParticleSystem.pure.js +4 -0
  316. package/Particles/thinParticleSystem.pure.js.map +1 -1
  317. package/PostProcesses/RenderPipeline/Pipelines/taaMaterialManager.pure.d.ts +27 -6
  318. package/PostProcesses/RenderPipeline/Pipelines/taaMaterialManager.pure.js +60 -5
  319. package/PostProcesses/RenderPipeline/Pipelines/taaMaterialManager.pure.js.map +1 -1
  320. package/PostProcesses/thinTAAPostProcess.d.ts +1 -0
  321. package/PostProcesses/thinTAAPostProcess.js +17 -1
  322. package/PostProcesses/thinTAAPostProcess.js.map +1 -1
  323. package/PostProcesses/volumetricLightScatteringPostProcess.pure.d.ts +2 -1
  324. package/PostProcesses/volumetricLightScatteringPostProcess.pure.js +6 -5
  325. package/PostProcesses/volumetricLightScatteringPostProcess.pure.js.map +1 -1
  326. package/Rendering/boundingBoxRenderer.pure.js +2 -3
  327. package/Rendering/boundingBoxRenderer.pure.js.map +1 -1
  328. package/Rendering/geometryBufferRenderer.pure.js +8 -2
  329. package/Rendering/geometryBufferRenderer.pure.js.map +1 -1
  330. package/Rendering/objectRenderer.d.ts +1 -0
  331. package/Rendering/objectRenderer.js +14 -0
  332. package/Rendering/objectRenderer.js.map +1 -1
  333. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js +2 -2
  334. package/Shaders/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
  335. package/Shaders/ShadersInclude/bumpVertex.js +1 -1
  336. package/Shaders/ShadersInclude/bumpVertex.js.map +1 -1
  337. package/Shaders/ShadersInclude/bumpVertexDeclaration.js +1 -1
  338. package/Shaders/ShadersInclude/bumpVertexDeclaration.js.map +1 -1
  339. package/Shaders/ShadersInclude/hdrFilteringFunctions.js +5 -1
  340. package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  341. package/Shaders/ShadersInclude/helperFunctions.js +2 -2
  342. package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
  343. package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js +1 -1
  344. package/Shaders/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -1
  345. package/Shaders/ShadersInclude/openpbrVertexDeclaration.js +6 -0
  346. package/Shaders/ShadersInclude/openpbrVertexDeclaration.js.map +1 -1
  347. package/Shaders/ShadersInclude/pbrBlockFinalLitComponents.js +11 -1
  348. package/Shaders/ShadersInclude/pbrBlockFinalLitComponents.js.map +1 -1
  349. package/Shaders/ShadersInclude/pbrBlockNormalFinal.js +9 -0
  350. package/Shaders/ShadersInclude/pbrBlockNormalFinal.js.map +1 -1
  351. package/Shaders/ShadersInclude/pbrBlockReflectance.js +1 -1
  352. package/Shaders/ShadersInclude/pbrBlockReflectance.js.map +1 -1
  353. package/Shaders/ShadersInclude/pbrClusteredLightingFunctions.js +1 -1
  354. package/Shaders/ShadersInclude/pbrClusteredLightingFunctions.js.map +1 -1
  355. package/Shaders/ShadersInclude/pbrFragmentDeclaration.js +7 -1
  356. package/Shaders/ShadersInclude/pbrFragmentDeclaration.js.map +1 -1
  357. package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -0
  358. package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
  359. package/Shaders/ShadersInclude/pbrIBLFunctions.js +12 -0
  360. package/Shaders/ShadersInclude/pbrIBLFunctions.js.map +1 -1
  361. package/Shaders/ShadersInclude/pbrUboDeclaration.js +1 -1
  362. package/Shaders/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  363. package/Shaders/ShadersInclude/pbrVertexDeclaration.js +3 -0
  364. package/Shaders/ShadersInclude/pbrVertexDeclaration.js.map +1 -1
  365. package/Shaders/geometry.vertex.js +6 -6
  366. package/Shaders/geometry.vertex.js.map +1 -1
  367. package/Shaders/gpuUpdateParticles.vertex.js +1 -1
  368. package/Shaders/gpuUpdateParticles.vertex.js.map +1 -1
  369. package/Shaders/lod.fragment.js +15 -2
  370. package/Shaders/lod.fragment.js.map +1 -1
  371. package/Shaders/lod3D.fragment.js +15 -2
  372. package/Shaders/lod3D.fragment.js.map +1 -1
  373. package/Shaders/lodCube.fragment.js +15 -2
  374. package/Shaders/lodCube.fragment.js.map +1 -1
  375. package/Shaders/openpbr.vertex.js +2 -0
  376. package/Shaders/openpbr.vertex.js.map +1 -1
  377. package/Shaders/pbr.fragment.js +12 -1
  378. package/Shaders/pbr.fragment.js.map +1 -1
  379. package/Shaders/pbr.vertex.js +2 -0
  380. package/Shaders/pbr.vertex.js.map +1 -1
  381. package/Shaders/textureMerger.fragment.js +28 -0
  382. package/Shaders/textureMerger.fragment.js.map +1 -1
  383. package/Shaders/textureProcessor.fragment.js +26 -4
  384. package/Shaders/textureProcessor.fragment.js.map +1 -1
  385. package/Shaders/volumetricLightScattering.fragment.js +1 -1
  386. package/Shaders/volumetricLightScattering.fragment.js.map +1 -1
  387. package/ShadersWGSL/ShadersInclude/bumpFragmentMainFunctions.js +2 -2
  388. package/ShadersWGSL/ShadersInclude/bumpFragmentMainFunctions.js.map +1 -1
  389. package/ShadersWGSL/ShadersInclude/bumpVertex.js +1 -1
  390. package/ShadersWGSL/ShadersInclude/bumpVertex.js.map +1 -1
  391. package/ShadersWGSL/ShadersInclude/bumpVertexDeclaration.js +1 -1
  392. package/ShadersWGSL/ShadersInclude/bumpVertexDeclaration.js.map +1 -1
  393. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js +1 -1
  394. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  395. package/ShadersWGSL/ShadersInclude/helperFunctions.js +2 -2
  396. package/ShadersWGSL/ShadersInclude/helperFunctions.js.map +1 -1
  397. package/ShadersWGSL/ShadersInclude/lightFragment.js +44 -2
  398. package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
  399. package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js +17 -3
  400. package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js.map +1 -1
  401. package/ShadersWGSL/ShadersInclude/lightVxUboDeclaration.js +12 -1
  402. package/ShadersWGSL/ShadersInclude/lightVxUboDeclaration.js.map +1 -1
  403. package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js +1 -1
  404. package/ShadersWGSL/ShadersInclude/openpbrBackgroundTransmission.js.map +1 -1
  405. package/ShadersWGSL/ShadersInclude/pbrBlockFinalLitComponents.js +11 -1
  406. package/ShadersWGSL/ShadersInclude/pbrBlockFinalLitComponents.js.map +1 -1
  407. package/ShadersWGSL/ShadersInclude/pbrBlockNormalFinal.js +9 -0
  408. package/ShadersWGSL/ShadersInclude/pbrBlockNormalFinal.js.map +1 -1
  409. package/ShadersWGSL/ShadersInclude/pbrBlockReflectance.js +1 -1
  410. package/ShadersWGSL/ShadersInclude/pbrBlockReflectance.js.map +1 -1
  411. package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js +1 -1
  412. package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js.map +1 -1
  413. package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js +1 -1
  414. package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js.map +1 -1
  415. package/ShadersWGSL/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -0
  416. package/ShadersWGSL/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
  417. package/ShadersWGSL/ShadersInclude/pbrIBLFunctions.js +8 -0
  418. package/ShadersWGSL/ShadersInclude/pbrIBLFunctions.js.map +1 -1
  419. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js +1 -1
  420. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  421. package/ShadersWGSL/ShadersInclude/prePassVertex.js +2 -2
  422. package/ShadersWGSL/ShadersInclude/prePassVertex.js.map +1 -1
  423. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js +1 -1
  424. package/ShadersWGSL/ShadersInclude/prePassVertexDeclaration.js.map +1 -1
  425. package/ShadersWGSL/ShadersInclude/sceneUboDeclaration.js +3 -1
  426. package/ShadersWGSL/ShadersInclude/sceneUboDeclaration.js.map +1 -1
  427. package/ShadersWGSL/ShadersInclude/shadowsVertex.js +16 -0
  428. package/ShadersWGSL/ShadersInclude/shadowsVertex.js.map +1 -1
  429. package/ShadersWGSL/default.fragment.js +4 -4
  430. package/ShadersWGSL/default.fragment.js.map +1 -1
  431. package/ShadersWGSL/default.vertex.js +1 -1
  432. package/ShadersWGSL/default.vertex.js.map +1 -1
  433. package/ShadersWGSL/gaussianSplatting.vertex.js +3 -3
  434. package/ShadersWGSL/gaussianSplatting.vertex.js.map +1 -1
  435. package/ShadersWGSL/gpuUpdateParticles.compute.js +1 -1
  436. package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
  437. package/ShadersWGSL/gsSortCount.compute.d.ts +5 -0
  438. package/ShadersWGSL/gsSortCount.compute.js +19 -0
  439. package/ShadersWGSL/gsSortCount.compute.js.map +1 -0
  440. package/ShadersWGSL/gsSortKeys.compute.d.ts +5 -0
  441. package/ShadersWGSL/gsSortKeys.compute.js +49 -0
  442. package/ShadersWGSL/gsSortKeys.compute.js.map +1 -0
  443. package/ShadersWGSL/gsSortOutput.compute.d.ts +5 -0
  444. package/ShadersWGSL/gsSortOutput.compute.js +28 -0
  445. package/ShadersWGSL/gsSortOutput.compute.js.map +1 -0
  446. package/ShadersWGSL/gsSortScanLocal.compute.d.ts +5 -0
  447. package/ShadersWGSL/gsSortScanLocal.compute.js +23 -0
  448. package/ShadersWGSL/gsSortScanLocal.compute.js.map +1 -0
  449. package/ShadersWGSL/gsSortScanSums.compute.d.ts +5 -0
  450. package/ShadersWGSL/gsSortScanSums.compute.js +19 -0
  451. package/ShadersWGSL/gsSortScanSums.compute.js.map +1 -0
  452. package/ShadersWGSL/gsSortScatter.compute.d.ts +5 -0
  453. package/ShadersWGSL/gsSortScatter.compute.js +33 -0
  454. package/ShadersWGSL/gsSortScatter.compute.js.map +1 -0
  455. package/ShadersWGSL/lod.fragment.js +14 -2
  456. package/ShadersWGSL/lod.fragment.js.map +1 -1
  457. package/ShadersWGSL/lod3D.fragment.js +14 -2
  458. package/ShadersWGSL/lod3D.fragment.js.map +1 -1
  459. package/ShadersWGSL/lodCube.fragment.js +14 -2
  460. package/ShadersWGSL/lodCube.fragment.js.map +1 -1
  461. package/ShadersWGSL/openpbr.vertex.js +3 -1
  462. package/ShadersWGSL/openpbr.vertex.js.map +1 -1
  463. package/ShadersWGSL/pbr.fragment.js +11 -0
  464. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  465. package/ShadersWGSL/pbr.vertex.js +3 -1
  466. package/ShadersWGSL/pbr.vertex.js.map +1 -1
  467. package/ShadersWGSL/textureMerger.fragment.js +40 -4
  468. package/ShadersWGSL/textureMerger.fragment.js.map +1 -1
  469. package/ShadersWGSL/textureProcessor.fragment.js +26 -4
  470. package/ShadersWGSL/textureProcessor.fragment.js.map +1 -1
  471. package/Sprites/spriteRenderer.js +15 -5
  472. package/Sprites/spriteRenderer.js.map +1 -1
  473. package/package.json +1 -1
  474. package/scene.pure.d.ts +23 -1
  475. package/scene.pure.js +83 -1
  476. package/scene.pure.js.map +1 -1
@@ -46,7 +46,9 @@ import { PerfCounter } from "../Misc/perfCounter.js";
46
46
  import { resetCachedPipeline } from "../Materials/effect.functions.js";
47
47
  import { RegisterAbstractEngineDom } from "./AbstractEngine/abstractEngine.dom.pure.js";
48
48
  import { RegisterAbstractEngineRenderPass } from "./AbstractEngine/abstractEngine.renderPass.pure.js";
49
+ import { RenderCommandBatcher } from "./renderCommandBatcher.pure.js";
49
50
  import { WebGPUExternalTexture } from "./WebGPU/webgpuExternalTexture.js";
51
+ import { ApplyWebGPURenderPassDrawCommand, CreateWebGPURenderPassIndexedDrawCommand, CreateWebGPURenderPassNonIndexedDrawCommand, WebGPURenderPassCommandStream, WebGPURenderPassDrawKind, } from "./WebGPU/webgpuRenderPassCommandStream.js";
50
52
  const ViewDescriptorSwapChainAntialiasing = {
51
53
  label: `TextureView_SwapChain_ResolveTarget`,
52
54
  dimension: "2d" /* WebGPUConstants.TextureDimension.E2d */,
@@ -68,6 +70,34 @@ const TempColor4SignedInteger = /*#__PURE__*/ new Color4();
68
70
  * @since 5.0.0
69
71
  */
70
72
  export class WebGPUEngine extends ThinWebGPUEngine {
73
+ /**
74
+ * Gets or sets the provider that lets the host lower render-pass draw submission into a batched
75
+ * command stream (see IWebGPURenderPassCommandRecorderProvider). Hosts such as BabylonNative,
76
+ * where every render-pass encoder call crosses the JS/native boundary, install a provider to
77
+ * amortize that cost across many draws — the same pattern the bgfx-based NativeEngine uses with
78
+ * its CommandBufferEncoder. When no provider is set (the default, and always the case in
79
+ * browsers), draws are submitted directly through the standard WebGPU encoder calls without
80
+ * constructing batched draw commands. Command-stream storage is allocated only when a provider
81
+ * is first installed.
82
+ */
83
+ get renderPassCommandRecorderProvider() {
84
+ return this._renderPassCommandRecorderProvider;
85
+ }
86
+ set renderPassCommandRecorderProvider(provider) {
87
+ // Record anything batched under the previous provider before swapping contracts.
88
+ this._flushRenderPassCommands();
89
+ this._renderPassCommandRecorderProvider = provider;
90
+ if (provider && !this._renderPassCommandBatching) {
91
+ const lowering = new WebGPURenderPassCommandStream({
92
+ getProvider: () => this._renderPassCommandRecorderProvider,
93
+ });
94
+ this._renderPassCommandBatching = {
95
+ batcher: new RenderCommandBatcher(lowering, ApplyWebGPURenderPassDrawCommand),
96
+ indexedDrawCommand: CreateWebGPURenderPassIndexedDrawCommand(),
97
+ nonIndexedDrawCommand: CreateWebGPURenderPassNonIndexedDrawCommand(),
98
+ };
99
+ }
100
+ }
71
101
  /**
72
102
  * Gets or sets the snapshot rendering mode
73
103
  */
@@ -302,6 +332,8 @@ export class WebGPUEngine extends ThinWebGPUEngine {
302
332
  /** @internal */
303
333
  this._virtualScenes = new Array();
304
334
  this._commandBuffers = [null, null];
335
+ this._submitted = null;
336
+ this._resolveSubmitted = null;
305
337
  // Frame Buffer Life Cycle (recreated for each render target pass)
306
338
  this._mainRenderPassWrapper = {
307
339
  renderPassDescriptor: null,
@@ -322,6 +354,8 @@ export class WebGPUEngine extends ThinWebGPUEngine {
322
354
  this._currentVertexBuffers = {};
323
355
  this._currentOverrideVertexBuffers = null;
324
356
  this._currentIndexBuffer = null;
357
+ this._renderPassCommandRecorderProvider = null;
358
+ this._renderPassCommandBatching = null;
325
359
  this._colorWriteLocal = true;
326
360
  this._forceEnableEffect = false;
327
361
  this._internalFrameCounter = 0;
@@ -356,6 +390,16 @@ export class WebGPUEngine extends ThinWebGPUEngine {
356
390
  this._stencilRefsCurrent = -1;
357
391
  this._blendColorsCurrent = [null, null, null, null];
358
392
  this._performanceMonitor = new PerformanceMonitor();
393
+ /**
394
+ * The most frames the GPU may have in flight when a frame starts, that frame included (0, the default: no limit).
395
+ * A frame over the limit is not started, and the render loop asks again at the next animation frame. With 2, a frame starts
396
+ * once the GPU has finished every frame but the previous one. Without a limit, a page whose GPU work takes longer than its
397
+ * frame can queue that work far ahead of the GPU, and the screen then shows frames that far behind
398
+ */
399
+ this.maxFramesInFlight = 0;
400
+ this._framesInFlight = 0;
401
+ this._framesInFlightDevice = null;
402
+ this._framesInFlightDone = null;
359
403
  this._name = "WebGPU";
360
404
  this._drawCalls = new PerfCounter();
361
405
  options.deviceDescriptor = options.deviceDescriptor || {};
@@ -478,6 +522,8 @@ export class WebGPUEngine extends ThinWebGPUEngine {
478
522
  return;
479
523
  }
480
524
  this._contextWasLost = true;
525
+ // the commands of the lost device will not be submitted: their readbacks go on, and fail as lost
526
+ this._notifySubmitted();
481
527
  Logger.Warn("WebGPU context lost. " + info);
482
528
  this.onContextLostObservable.notifyObservers(this);
483
529
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
@@ -859,6 +905,15 @@ export class WebGPUEngine extends ThinWebGPUEngine {
859
905
  ExitPointerlock();
860
906
  }
861
907
  _rebuildBuffers() {
908
+ // Index / Vertex (WebGPUEngine does not extend Engine, so it must do what Engine._rebuildBuffers does)
909
+ for (const scene of this.scenes) {
910
+ scene.resetCachedMaterial();
911
+ scene._rebuildGeometries();
912
+ }
913
+ for (const scene of this._virtualScenes) {
914
+ scene.resetCachedMaterial();
915
+ scene._rebuildGeometries();
916
+ }
862
917
  super._rebuildBuffers();
863
918
  for (const storageBuffer of this._storageBuffers) {
864
919
  // The buffer can already be rebuilt by the call to _rebuildGeometries(), which recreates the storage buffers for the ComputeShaderParticleSystem
@@ -961,6 +1016,10 @@ export class WebGPUEngine extends ThinWebGPUEngine {
961
1016
  _getCurrentRenderPassWrapper() {
962
1017
  return this._currentRenderTarget ? this._rttRenderPassWrapper : this._mainRenderPassWrapper;
963
1018
  }
1019
+ /** @internal */
1020
+ _flushRenderPassCommands() {
1021
+ this._renderPassCommandBatching?.batcher.flush();
1022
+ }
964
1023
  //------------------------------------------------------------------------------
965
1024
  // Static Pipeline WebGPU States
966
1025
  //------------------------------------------------------------------------------
@@ -1036,6 +1095,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
1036
1095
  bundleList.addItem(new WebGPURenderItemViewport(x, y, w, h));
1037
1096
  }
1038
1097
  else {
1098
+ this._flushRenderPassCommands();
1039
1099
  this._getCurrentRenderPass().setViewport(x, y, w, h, 0, 1);
1040
1100
  }
1041
1101
  }
@@ -1065,6 +1125,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
1065
1125
  bundleList.addItem(new WebGPURenderItemScissor(this._scissorCached.x, y, this._scissorCached.z, this._scissorCached.w));
1066
1126
  }
1067
1127
  else {
1128
+ this._flushRenderPassCommands();
1068
1129
  this._getCurrentRenderPass().setScissorRect(this._scissorCached.x, y, this._scissorCached.z, this._scissorCached.w);
1069
1130
  }
1070
1131
  }
@@ -1103,6 +1164,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
1103
1164
  bundleList.addItem(new WebGPURenderItemStencilRef(this._stencilStateComposer.funcRef ?? 0));
1104
1165
  }
1105
1166
  else {
1167
+ this._flushRenderPassCommands();
1106
1168
  this._getCurrentRenderPass().setStencilReference(this._stencilStateComposer.funcRef ?? 0);
1107
1169
  }
1108
1170
  }
@@ -1125,6 +1187,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
1125
1187
  bundleList.addItem(new WebGPURenderItemBlendColor(this._alphaState._blendConstants.slice()));
1126
1188
  }
1127
1189
  else {
1190
+ this._flushRenderPassCommands();
1128
1191
  this._getCurrentRenderPass().setBlendConstant(this._alphaState._blendConstants);
1129
1192
  }
1130
1193
  }
@@ -1189,6 +1252,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
1189
1252
  }
1190
1253
  }
1191
1254
  _clearFullQuad(clearColor, clearDepth, clearStencil) {
1255
+ this._flushRenderPassCommands();
1192
1256
  const renderPass = !this.compatibilityMode ? null : this._getCurrentRenderPass();
1193
1257
  this._clearQuad.setColorFormat(this._colorFormat);
1194
1258
  this._clearQuad.setDepthStencilFormat(this._depthTextureFormat);
@@ -2338,6 +2402,14 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2338
2402
  get performanceMonitor() {
2339
2403
  return this._performanceMonitor;
2340
2404
  }
2405
+ _processFrame(timestamp) {
2406
+ if (this.maxFramesInFlight > 0 && this._framesInFlightDevice === this._device && this._framesInFlight >= this.maxFramesInFlight) {
2407
+ // nothing of the frame has started and maxFPS has not counted it
2408
+ this._frameHandler = 0;
2409
+ return;
2410
+ }
2411
+ super._processFrame(timestamp);
2412
+ }
2341
2413
  /**
2342
2414
  * Begin a new frame
2343
2415
  */
@@ -2355,6 +2427,9 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2355
2427
  this._timestampIndex = 0;
2356
2428
  this._internalFrameCounter = 0;
2357
2429
  this.flushFramebuffer(true);
2430
+ if (this.maxFramesInFlight > 0) {
2431
+ this._countFrameInFlight();
2432
+ }
2358
2433
  this._textureHelper.destroyDeferredTextures();
2359
2434
  this._bufferManager.destroyDeferredBuffers();
2360
2435
  this.countersLastFrame.numEnableEffects = this._counters.numEnableEffects;
@@ -2369,10 +2444,51 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2369
2444
  this._cacheBindGroups.endFrame();
2370
2445
  super.endFrame();
2371
2446
  }
2447
+ // The frame is on the GPU until the GPU has done all the work submitted so far: its intermediate flushes too
2448
+ _countFrameInFlight() {
2449
+ const device = this._device;
2450
+ if (this._framesInFlightDevice !== device) {
2451
+ // a new device: the frames of the lost one are not on it
2452
+ this._framesInFlightDevice = device;
2453
+ this._framesInFlight = 0;
2454
+ // one handler for all the frames of the device
2455
+ this._framesInFlightDone = () => {
2456
+ if (this._framesInFlightDevice === device) {
2457
+ this._framesInFlight--;
2458
+ }
2459
+ };
2460
+ }
2461
+ this._framesInFlight++;
2462
+ const done = this._framesInFlightDone;
2463
+ // eslint-disable-next-line github/no-then
2464
+ device.queue.onSubmittedWorkDone().then(done, done);
2465
+ }
2372
2466
  /**Gets driver info if available */
2373
2467
  extractDriverInfo() {
2374
2468
  return "";
2375
2469
  }
2470
+ /**
2471
+ * @internal Resolves once the commands recorded until now are submitted, by the next flushFramebuffer (from endFrame or not),
2472
+ * or once the device is lost or the engine disposed. The waits of one submission share one promise.
2473
+ * @returns a promise resolved after the next submission
2474
+ */
2475
+ // eslint-disable-next-line no-restricted-syntax, @typescript-eslint/promise-function-async -- every wait of a submission shares this one promise, where an async method would make one per wait
2476
+ _whenSubmittedAsync() {
2477
+ if (!this._submitted) {
2478
+ this._submitted = new Promise((resolve) => {
2479
+ this._resolveSubmitted = resolve;
2480
+ });
2481
+ }
2482
+ return this._submitted;
2483
+ }
2484
+ _notifySubmitted() {
2485
+ const resolve = this._resolveSubmitted;
2486
+ if (resolve) {
2487
+ this._submitted = null;
2488
+ this._resolveSubmitted = null;
2489
+ resolve();
2490
+ }
2491
+ }
2376
2492
  /**
2377
2493
  * Force a WebGPU flush (ie. a flush of all waiting commands)
2378
2494
  * @internal @param _fromEndFrame defines whether the flush is triggered from endFrame or not (default: false)
@@ -2384,6 +2500,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2384
2500
  this._commandBuffers[0] = this._uploadEncoder.finish();
2385
2501
  this._commandBuffers[1] = this._renderEncoder.finish();
2386
2502
  this._device.queue.submit(this._commandBuffers);
2503
+ this._notifySubmitted();
2387
2504
  const frameCounter = this._internalFrameCounter++;
2388
2505
  // If flushFramebuffer is called from endFrame, it means the encoders are created for the next frame, but because frameId is not yet incremented at the time of the call, we use frameId + 1
2389
2506
  this._uploadEncoderDescriptor.label = `[${_fromEndFrame ? this.frameId + 1 : this.frameId}|${frameCounter}] - UploadEncoder`;
@@ -2821,6 +2938,39 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2821
2938
  this._depthCullingState.cullFace = cullFace;
2822
2939
  }
2823
2940
  }
2941
+ // The front face of a draw in the current pass (1 = CCW, 2 = CW), for draws whose side is reversed or not (see setState).
2942
+ // Render targets are drawn Y-flipped (see the InternalsUBO yFactor in _draw), so their triangle
2943
+ // winding is reversed here to compensate and keep the same faces visible. XR projection-layer targets
2944
+ // opt out of that flip (_disableEngineYFlip) because the compositor presents them directly, so they
2945
+ // keep the main-framebuffer winding.
2946
+ _getFrontFace(reverseSide) {
2947
+ const invertYRenderTarget = !!this._currentRenderTarget && !this._currentRenderTarget._disableEngineYFlip;
2948
+ return reverseSide ? (invertYRenderTarget ? 1 : 2) : invertYRenderTarget ? 2 : 1;
2949
+ }
2950
+ // The front face of the draws of a mesh with an effect in the current pass, wound as setState does. They go through the sub mesh given,
2951
+ // or else the one drawn with that effect, or else the first one, with the material the draw uses (SubMesh.getMaterial: the scene's default one, a render pass's,
2952
+ // a multi-material's), and the side orientation Mesh.render gives Material._preBind: from the source mesh of an instance, and from the
2953
+ // world matrix of the mesh itself, which the next frame computes (the last one computed can predate a change of its transform). An
2954
+ // instance mirrored against its source is drawn on its own, the others in their source's draw: either way its own determinant's sign
2955
+ // gives the winding
2956
+ _getMeshFrontFace(mesh, effect, subMesh) {
2957
+ const subMeshes = mesh.subMeshes;
2958
+ if (!subMesh && subMeshes) {
2959
+ subMesh = subMeshes[0];
2960
+ for (const candidate of subMeshes) {
2961
+ if (candidate.effect === effect) {
2962
+ subMesh = candidate;
2963
+ break;
2964
+ }
2965
+ }
2966
+ }
2967
+ const material = subMesh?.getMaterial();
2968
+ if (!subMesh || !material) {
2969
+ return this._getFrontFace(false);
2970
+ }
2971
+ mesh.computeWorldMatrix(true);
2972
+ return this._getFrontFace(material._isReverseSide(subMesh.getRenderingMesh()._getDrawSideOrientation(material, mesh)));
2973
+ }
2824
2974
  /**
2825
2975
  * Set various states to the webGL context
2826
2976
  * @param culling defines culling state: true to enable culling, false to disable it
@@ -2842,24 +2992,24 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2842
2992
  this.setZOffset(zOffset);
2843
2993
  this.setZOffsetUnits(zOffsetUnits);
2844
2994
  // Front face
2845
- // Render targets are drawn Y-flipped (see the InternalsUBO yFactor in _draw), so their triangle
2846
- // winding is reversed here to compensate and keep the same faces visible. XR projection-layer targets
2847
- // opt out of that flip (_disableEngineYFlip) because the compositor presents them directly, so they
2848
- // keep the main-framebuffer winding.
2849
- const invertYRenderTarget = !!this._currentRenderTarget && !this._currentRenderTarget._disableEngineYFlip;
2850
- const frontFace = reverseSide ? (invertYRenderTarget ? 1 : 2) : invertYRenderTarget ? 2 : 1;
2995
+ const frontFace = this._getFrontFace(reverseSide);
2851
2996
  if (this._depthCullingState.frontFace !== frontFace || force) {
2852
2997
  this._depthCullingState.frontFace = frontFace;
2853
2998
  }
2854
2999
  this._stencilStateComposer.stencilMaterial = stencil;
2855
3000
  }
2856
3001
  _applyRenderPassChanges(bundleList) {
3002
+ const mustUpdateViewport = this._mustUpdateViewport();
3003
+ const mustUpdateScissor = this._mustUpdateScissor();
2857
3004
  const mustUpdateStencilRef = !this._stencilStateComposer.enabled ? false : this._mustUpdateStencilRef();
2858
3005
  const mustUpdateBlendColor = !this._alphaState.alphaBlend ? false : this._mustUpdateBlendColor();
2859
- if (this._mustUpdateViewport()) {
3006
+ if (mustUpdateViewport || mustUpdateScissor || mustUpdateStencilRef || mustUpdateBlendColor) {
3007
+ this._flushRenderPassCommands();
3008
+ }
3009
+ if (mustUpdateViewport) {
2860
3010
  this._applyViewport(bundleList);
2861
3011
  }
2862
- if (this._mustUpdateScissor()) {
3012
+ if (mustUpdateScissor) {
2863
3013
  this._applyScissor(bundleList);
2864
3014
  }
2865
3015
  if (mustUpdateStencilRef) {
@@ -2869,7 +3019,25 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2869
3019
  this._applyBlendColor(bundleList);
2870
3020
  }
2871
3021
  }
2872
- _draw(drawType, fillMode, start, count, instancesCount) {
3022
+ // A bit for each texture of the shader that is a depth texture, or a float texture the device can't filter linearly: a draw that binds
3023
+ // one uses a pipeline of its own (see WebGPUMaterialContext.textureState). The draws and createRenderPipelineAsync both derive it here.
3024
+ _getTextureState(webgpuPipelineContext, materialContext) {
3025
+ let textureState = 0;
3026
+ if (materialContext.hasFloatOrDepthTextures) {
3027
+ let bitVal = 1;
3028
+ for (let i = 0; i < webgpuPipelineContext.shaderProcessingContext.textureNames.length; ++i) {
3029
+ const textureName = webgpuPipelineContext.shaderProcessingContext.textureNames[i];
3030
+ const texture = materialContext.textures[textureName]?.texture;
3031
+ const textureIsDepth = texture && texture.format >= 13 && texture.format <= 18;
3032
+ if ((texture?.type === 1 && !this._caps.textureFloatLinearFiltering) || textureIsDepth) {
3033
+ textureState |= bitVal;
3034
+ }
3035
+ bitVal = bitVal << 1;
3036
+ }
3037
+ }
3038
+ return textureState;
3039
+ }
3040
+ _draw(drawKind, fillMode, start, count, instancesCount) {
2873
3041
  const renderPass = this._getCurrentRenderPass();
2874
3042
  const bundleList = this._bundleList;
2875
3043
  this.applyStates();
@@ -2914,22 +3082,11 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2914
3082
  renderPass2 = bundleList.getBundleEncoder(this._cacheRenderPipeline.colorFormats, this._depthTextureFormat, this.currentSampleCount); // for snapshot recording mode
2915
3083
  bundleList.numDrawCalls++;
2916
3084
  }
2917
- let textureState = 0;
2918
- if (this._currentMaterialContext.hasFloatOrDepthTextures) {
2919
- let bitVal = 1;
2920
- for (let i = 0; i < webgpuPipelineContext.shaderProcessingContext.textureNames.length; ++i) {
2921
- const textureName = webgpuPipelineContext.shaderProcessingContext.textureNames[i];
2922
- const texture = this._currentMaterialContext.textures[textureName]?.texture;
2923
- const textureIsDepth = texture && texture.format >= 13 && texture.format <= 18;
2924
- if ((texture?.type === 1 && !this._caps.textureFloatLinearFiltering) || textureIsDepth) {
2925
- textureState |= bitVal;
2926
- }
2927
- bitVal = bitVal << 1;
2928
- }
2929
- }
3085
+ const textureState = this._getTextureState(webgpuPipelineContext, this._currentMaterialContext);
2930
3086
  this._currentMaterialContext.textureState = textureState;
2931
3087
  const pipeline = this._cacheRenderPipeline.getRenderPipeline(fillMode, this._currentEffect, this.currentSampleCount, textureState);
2932
3088
  const bindGroups = this._cacheBindGroups.getBindGroups(webgpuPipelineContext, this._currentDrawContext, this._currentMaterialContext);
3089
+ const vertexBuffers = this._cacheRenderPipeline.vertexBuffers;
2933
3090
  if (!this._snapshotRendering.record) {
2934
3091
  this._applyRenderPassChanges(!this.compatibilityMode ? bundleList : null);
2935
3092
  if (!this.compatibilityMode) {
@@ -2941,13 +3098,45 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2941
3098
  });
2942
3099
  }
2943
3100
  }
2944
- // bind pipeline
3101
+ const nonCompatMode = !this.compatibilityMode && !this._snapshotRendering.record;
3102
+ const indirectDrawBuffer = (nonCompatMode || this._currentDrawContext._enableIndirectDrawInCompatMode) && this._currentDrawContext.indirectDrawBuffer
3103
+ ? this._currentDrawContext.indirectDrawBuffer
3104
+ : null;
3105
+ if (indirectDrawBuffer) {
3106
+ this._currentDrawContext.setIndirectData(count, instancesCount || 1, start);
3107
+ }
3108
+ const commandBatching = this._renderPassCommandRecorderProvider && this._renderPassCommandBatching;
3109
+ if (commandBatching && this.compatibilityMode && !this._snapshotRendering.record) {
3110
+ let drawCommand;
3111
+ if (drawKind === WebGPURenderPassDrawKind.INDEXED) {
3112
+ const indexedDrawCommand = commandBatching.indexedDrawCommand;
3113
+ indexedDrawCommand.indexBuffer = this._currentIndexBuffer;
3114
+ indexedDrawCommand.indexFormat = this._currentIndexBuffer.is32Bits ? "uint32" /* WebGPUConstants.IndexFormat.Uint32 */ : "uint16" /* WebGPUConstants.IndexFormat.Uint16 */;
3115
+ drawCommand = indexedDrawCommand;
3116
+ }
3117
+ else {
3118
+ drawCommand = commandBatching.nonIndexedDrawCommand;
3119
+ }
3120
+ drawCommand.renderPass = renderPass2;
3121
+ drawCommand.pipeline = pipeline;
3122
+ drawCommand.bindGroups = bindGroups;
3123
+ drawCommand.vertexBuffers = vertexBuffers;
3124
+ drawCommand.count = count;
3125
+ drawCommand.instancesCount = instancesCount;
3126
+ drawCommand.start = start;
3127
+ drawCommand.indirectDrawBuffer = indirectDrawBuffer;
3128
+ commandBatching.batcher.submit(drawCommand);
3129
+ this._reportDrawCall();
3130
+ return;
3131
+ }
3132
+ // A provider can have pending compatibility-mode draws when switching to bundle recording.
3133
+ if (commandBatching) {
3134
+ commandBatching.batcher.flush();
3135
+ }
2945
3136
  renderPass2.setPipeline(pipeline);
2946
- // bind index/vertex buffers
2947
3137
  if (this._currentIndexBuffer) {
2948
3138
  renderPass2.setIndexBuffer(this._currentIndexBuffer.underlyingResource, this._currentIndexBuffer.is32Bits ? "uint32" /* WebGPUConstants.IndexFormat.Uint32 */ : "uint16" /* WebGPUConstants.IndexFormat.Uint16 */, 0);
2949
3139
  }
2950
- const vertexBuffers = this._cacheRenderPipeline.vertexBuffers;
2951
3140
  for (let index = 0; index < vertexBuffers.length; index++) {
2952
3141
  const vertexBuffer = vertexBuffers[index];
2953
3142
  const buffer = vertexBuffer.effectiveBuffer;
@@ -2955,22 +3144,18 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2955
3144
  renderPass2.setVertexBuffer(index, buffer.underlyingResource, vertexBuffer._validOffsetRange ? 0 : vertexBuffer.byteOffset);
2956
3145
  }
2957
3146
  }
2958
- // bind bind groups
2959
3147
  for (let i = 0; i < bindGroups.length; i++) {
2960
3148
  renderPass2.setBindGroup(i, bindGroups[i]);
2961
3149
  }
2962
- // draw
2963
- const nonCompatMode = !this.compatibilityMode && !this._snapshotRendering.record;
2964
- if ((nonCompatMode || this._currentDrawContext._enableIndirectDrawInCompatMode) && this._currentDrawContext.indirectDrawBuffer) {
2965
- this._currentDrawContext.setIndirectData(count, instancesCount || 1, start);
2966
- if (drawType === 0) {
2967
- renderPass2.drawIndexedIndirect(this._currentDrawContext.indirectDrawBuffer, 0);
3150
+ if (indirectDrawBuffer) {
3151
+ if (drawKind === WebGPURenderPassDrawKind.INDEXED) {
3152
+ renderPass2.drawIndexedIndirect(indirectDrawBuffer, 0);
2968
3153
  }
2969
3154
  else {
2970
- renderPass2.drawIndirect(this._currentDrawContext.indirectDrawBuffer, 0);
3155
+ renderPass2.drawIndirect(indirectDrawBuffer, 0);
2971
3156
  }
2972
3157
  }
2973
- else if (drawType === 0) {
3158
+ else if (drawKind === WebGPURenderPassDrawKind.INDEXED) {
2974
3159
  renderPass2.drawIndexed(count, instancesCount || 1, start, 0, 0);
2975
3160
  }
2976
3161
  else {
@@ -2990,7 +3175,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
2990
3175
  * @param instancesCount defines the number of instances to draw (if instantiation is enabled)
2991
3176
  */
2992
3177
  drawElementsType(fillMode, indexStart, indexCount, instancesCount = 1) {
2993
- this._draw(0, fillMode, indexStart, indexCount, instancesCount);
3178
+ this._draw(WebGPURenderPassDrawKind.INDEXED, fillMode, indexStart, indexCount, instancesCount);
2994
3179
  }
2995
3180
  /**
2996
3181
  * Draw a list of unindexed primitives
@@ -3001,7 +3186,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
3001
3186
  */
3002
3187
  drawArraysType(fillMode, verticesStart, verticesCount, instancesCount = 1) {
3003
3188
  this._currentIndexBuffer = null;
3004
- this._draw(1, fillMode, verticesStart, verticesCount, instancesCount);
3189
+ this._draw(WebGPURenderPassDrawKind.NON_INDEXED, fillMode, verticesStart, verticesCount, instancesCount);
3005
3190
  }
3006
3191
  //------------------------------------------------------------------------------
3007
3192
  // Async Pipeline Pre-Warming
@@ -3059,14 +3244,23 @@ export class WebGPUEngine extends ThinWebGPUEngine {
3059
3244
  // Rasterization state
3060
3245
  cache.setCullEnabled(entry.cullEnabled ?? true);
3061
3246
  cache.setCullFace(entry.cullFace ?? 1);
3062
- cache.setFrontFace(entry.frontFace ?? 2);
3247
+ cache.setFrontFace(entry.frontFace ?? this._getMeshFrontFace(entry.mesh, entry.effect, entry.subMesh));
3063
3248
  // Write mask
3064
3249
  cache.setWriteMask(entry.writeMask ?? 0xf);
3065
3250
  // Stencil
3066
3251
  cache.setStencilEnabled(entry.stencilEnabled ?? false);
3067
3252
  const fillMode = entry.fillMode ?? 0;
3068
3253
  const sampleCount = entry.sampleCount ?? this.currentSampleCount;
3069
- const promise = cache.preWarmPipeline(fillMode, entry.effect, sampleCount, 0);
3254
+ // the texture state a draw gets from the same textures
3255
+ let textureState = 0;
3256
+ if (entry.textures) {
3257
+ const materialContext = new WebGPUMaterialContext();
3258
+ for (const name in entry.textures) {
3259
+ materialContext.setTexture(name, entry.textures[name]);
3260
+ }
3261
+ textureState = this._getTextureState(entry.effect._pipelineContext, materialContext);
3262
+ }
3263
+ const promise = cache.preWarmPipeline(fillMode, entry.effect, sampleCount, textureState);
3070
3264
  if (promise) {
3071
3265
  promises.push(promise);
3072
3266
  }
@@ -3090,13 +3284,15 @@ export class WebGPUEngine extends ThinWebGPUEngine {
3090
3284
  */
3091
3285
  dispose() {
3092
3286
  this._isDisposed = true;
3287
+ // the commands not submitted yet never will be: their readbacks go on, and return nothing
3288
+ this._resolveSubmitted?.();
3093
3289
  this.hideLoadingUI?.();
3094
- this._timestampQuery.dispose();
3290
+ this._timestampQuery?.dispose();
3095
3291
  this._mainTexture?.destroy();
3096
3292
  this._depthTexture?.destroy();
3097
- this._textureHelper.destroyDeferredTextures();
3098
- this._bufferManager.destroyDeferredBuffers();
3099
- this._device.destroy();
3293
+ this._textureHelper?.destroyDeferredTextures();
3294
+ this._bufferManager?.destroyDeferredBuffers();
3295
+ this._device?.destroy();
3100
3296
  _CommonDispose(this, this._renderingCanvas);
3101
3297
  super.dispose();
3102
3298
  // If this was the last WebGPU engine, reset the static caches shared by all WebGPU engines