@babylonjs/core 6.29.0 → 6.29.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/Actions/abstractActionManager.js +1 -1
  2. package/Actions/abstractActionManager.js.map +1 -1
  3. package/Actions/actionManager.js +3 -3
  4. package/Actions/actionManager.js.map +1 -1
  5. package/Animations/animatable.js +1 -1
  6. package/Animations/animatable.js.map +1 -1
  7. package/Animations/animation.js +2 -2
  8. package/Animations/animation.js.map +1 -1
  9. package/Animations/pathCursor.js +1 -1
  10. package/Animations/pathCursor.js.map +1 -1
  11. package/Audio/audioSceneComponent.js +2 -2
  12. package/Audio/audioSceneComponent.js.map +1 -1
  13. package/Audio/soundTrack.js +1 -1
  14. package/Audio/soundTrack.js.map +1 -1
  15. package/Behaviors/Meshes/fadeInOutBehavior.js +1 -2
  16. package/Behaviors/Meshes/fadeInOutBehavior.js.map +1 -1
  17. package/Bones/bone.js +2 -2
  18. package/Bones/bone.js.map +1 -1
  19. package/Bones/skeleton.js +2 -2
  20. package/Bones/skeleton.js.map +1 -1
  21. package/Cameras/arcRotateCamera.js +13 -37
  22. package/Cameras/arcRotateCamera.js.map +1 -1
  23. package/Cameras/camera.d.ts +0 -21
  24. package/Cameras/camera.js +1 -36
  25. package/Cameras/camera.js.map +1 -1
  26. package/Cameras/targetCamera.js +30 -51
  27. package/Cameras/targetCamera.js.map +1 -1
  28. package/Culling/Octrees/octree.js +1 -1
  29. package/Culling/Octrees/octree.js.map +1 -1
  30. package/Culling/Octrees/octreeBlock.js +1 -1
  31. package/Culling/Octrees/octreeBlock.js.map +1 -1
  32. package/Culling/ray.js +1 -1
  33. package/Culling/ray.js.map +1 -1
  34. package/Debug/axesViewer.d.ts +3 -1
  35. package/Debug/axesViewer.js +14 -11
  36. package/Debug/axesViewer.js.map +1 -1
  37. package/Engines/Extensions/engine.multiRender.js +8 -8
  38. package/Engines/Extensions/engine.multiRender.js.map +1 -1
  39. package/Engines/Extensions/engine.textureSelector.js +1 -1
  40. package/Engines/Extensions/engine.textureSelector.js.map +1 -1
  41. package/Engines/Processors/shaderCodeInliner.js +1 -1
  42. package/Engines/Processors/shaderCodeInliner.js.map +1 -1
  43. package/Engines/WebGPU/Extensions/engine.computeShader.js +2 -10
  44. package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
  45. package/Engines/WebGPU/Extensions/engine.debugging.js +3 -6
  46. package/Engines/WebGPU/Extensions/engine.debugging.js.map +1 -1
  47. package/Engines/WebGPU/Extensions/engine.dynamicTexture.js +1 -1
  48. package/Engines/WebGPU/Extensions/engine.dynamicTexture.js.map +1 -1
  49. package/Engines/WebGPU/Extensions/engine.multiRender.js +9 -14
  50. package/Engines/WebGPU/Extensions/engine.multiRender.js.map +1 -1
  51. package/Engines/WebGPU/Extensions/engine.query.js +2 -6
  52. package/Engines/WebGPU/Extensions/engine.query.js.map +1 -1
  53. package/Engines/WebGPU/Extensions/engine.renderTarget.js +6 -10
  54. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  55. package/Engines/WebGPU/Extensions/engine.storageBuffer.js +1 -1
  56. package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +1 -1
  57. package/Engines/WebGPU/Extensions/engine.videoTexture.js +2 -2
  58. package/Engines/WebGPU/Extensions/engine.videoTexture.js.map +1 -1
  59. package/Engines/WebGPU/webgpuBundleList.js +2 -1
  60. package/Engines/WebGPU/webgpuBundleList.js.map +1 -1
  61. package/Engines/WebGPU/webgpuCacheBindGroups.js +1 -1
  62. package/Engines/WebGPU/webgpuCacheBindGroups.js.map +1 -1
  63. package/Engines/WebGPU/webgpuCacheRenderPipeline.d.ts +1 -1
  64. package/Engines/WebGPU/webgpuCacheRenderPipeline.js +4 -7
  65. package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
  66. package/Engines/WebGPU/webgpuCacheRenderPipelineTree.d.ts +1 -1
  67. package/Engines/WebGPU/webgpuCacheRenderPipelineTree.js +2 -2
  68. package/Engines/WebGPU/webgpuCacheRenderPipelineTree.js.map +1 -1
  69. package/Engines/WebGPU/webgpuCacheSampler.d.ts +1 -1
  70. package/Engines/WebGPU/webgpuCacheSampler.js +5 -5
  71. package/Engines/WebGPU/webgpuCacheSampler.js.map +1 -1
  72. package/Engines/WebGPU/webgpuClearQuad.js +2 -2
  73. package/Engines/WebGPU/webgpuClearQuad.js.map +1 -1
  74. package/Engines/WebGPU/webgpuHardwareTexture.d.ts +0 -12
  75. package/Engines/WebGPU/webgpuHardwareTexture.js.map +1 -1
  76. package/Engines/WebGPU/webgpuMaterialContext.d.ts +3 -3
  77. package/Engines/WebGPU/webgpuMaterialContext.js +14 -10
  78. package/Engines/WebGPU/webgpuMaterialContext.js.map +1 -1
  79. package/Engines/WebGPU/webgpuOcclusionQuery.js +1 -12
  80. package/Engines/WebGPU/webgpuOcclusionQuery.js.map +1 -1
  81. package/Engines/WebGPU/webgpuSnapshotRendering.d.ts +5 -8
  82. package/Engines/WebGPU/webgpuSnapshotRendering.js +24 -33
  83. package/Engines/WebGPU/webgpuSnapshotRendering.js.map +1 -1
  84. package/Engines/WebGPU/webgpuTextureHelper.d.ts +2 -1
  85. package/Engines/WebGPU/webgpuTextureHelper.js +11 -16
  86. package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
  87. package/Engines/constants.d.ts +2 -2
  88. package/Engines/constants.js +2 -2
  89. package/Engines/constants.js.map +1 -1
  90. package/Engines/engine.js +2 -2
  91. package/Engines/engine.js.map +1 -1
  92. package/Engines/engineCapabilities.d.ts +2 -0
  93. package/Engines/engineCapabilities.js.map +1 -1
  94. package/Engines/engineStore.js +1 -1
  95. package/Engines/engineStore.js.map +1 -1
  96. package/Engines/nativeEngine.js +1 -0
  97. package/Engines/nativeEngine.js.map +1 -1
  98. package/Engines/nullEngine.js +1 -0
  99. package/Engines/nullEngine.js.map +1 -1
  100. package/Engines/thinEngine.js +6 -2
  101. package/Engines/thinEngine.js.map +1 -1
  102. package/Engines/webgpuEngine.d.ts +27 -32
  103. package/Engines/webgpuEngine.js +237 -317
  104. package/Engines/webgpuEngine.js.map +1 -1
  105. package/Gizmos/boundingBoxGizmo.js +1 -1
  106. package/Gizmos/boundingBoxGizmo.js.map +1 -1
  107. package/Gizmos/cameraGizmo.d.ts +3 -1
  108. package/Gizmos/cameraGizmo.js +11 -8
  109. package/Gizmos/cameraGizmo.js.map +1 -1
  110. package/Layers/effectLayerSceneComponent.js +2 -2
  111. package/Layers/effectLayerSceneComponent.js.map +1 -1
  112. package/Layers/layerSceneComponent.js +1 -1
  113. package/Layers/layerSceneComponent.js.map +1 -1
  114. package/LensFlares/lensFlareSystem.js +1 -1
  115. package/LensFlares/lensFlareSystem.js.map +1 -1
  116. package/LensFlares/lensFlareSystemSceneComponent.js +2 -2
  117. package/LensFlares/lensFlareSystemSceneComponent.js.map +1 -1
  118. package/Lights/Shadows/shadowGenerator.js +1 -1
  119. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  120. package/Lights/light.js +2 -2
  121. package/Lights/light.js.map +1 -1
  122. package/Loading/Plugins/babylonFileLoader.js +1 -1
  123. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  124. package/Loading/sceneLoader.js +3 -3
  125. package/Loading/sceneLoader.js.map +1 -1
  126. package/Materials/GreasedLine/greasedLineMaterialDefaults.d.ts +2 -2
  127. package/Materials/GreasedLine/greasedLineMaterialDefaults.js.map +1 -1
  128. package/Materials/GreasedLine/greasedLineSimpleMaterial.js +4 -1
  129. package/Materials/GreasedLine/greasedLineSimpleMaterial.js.map +1 -1
  130. package/Materials/Node/Blocks/Dual/lightBlock.js +1 -1
  131. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  132. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +1 -1
  133. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  134. package/Materials/Node/nodeMaterial.js +1 -1
  135. package/Materials/Node/nodeMaterial.js.map +1 -1
  136. package/Materials/Node/nodeMaterialBlockConnectionPoint.js +2 -2
  137. package/Materials/Node/nodeMaterialBlockConnectionPoint.js.map +1 -1
  138. package/Materials/Node/nodeMaterialBuildState.js +4 -4
  139. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  140. package/Materials/Node/nodeMaterialBuildStateSharedData.js +12 -12
  141. package/Materials/Node/nodeMaterialBuildStateSharedData.js.map +1 -1
  142. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.js +1 -1
  143. package/Materials/Textures/Procedurals/proceduralTextureSceneComponent.js.map +1 -1
  144. package/Materials/Textures/baseTexture.js +1 -1
  145. package/Materials/Textures/baseTexture.js.map +1 -1
  146. package/Materials/Textures/dynamicTexture.d.ts +4 -3
  147. package/Materials/Textures/dynamicTexture.js +10 -6
  148. package/Materials/Textures/dynamicTexture.js.map +1 -1
  149. package/Materials/Textures/externalTexture.d.ts +4 -0
  150. package/Materials/Textures/externalTexture.js +4 -0
  151. package/Materials/Textures/externalTexture.js.map +1 -1
  152. package/Materials/Textures/internalTexture.d.ts +0 -4
  153. package/Materials/Textures/internalTexture.js.map +1 -1
  154. package/Materials/Textures/renderTargetTexture.js +1 -1
  155. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  156. package/Materials/Textures/textureSampler.d.ts +4 -0
  157. package/Materials/Textures/textureSampler.js.map +1 -1
  158. package/Materials/material.js +1 -1
  159. package/Materials/material.js.map +1 -1
  160. package/Materials/multiMaterial.js +1 -1
  161. package/Materials/multiMaterial.js.map +1 -1
  162. package/Materials/shaderMaterial.js +1 -1
  163. package/Materials/shaderMaterial.js.map +1 -1
  164. package/Maths/math.path.d.ts +9 -1
  165. package/Maths/math.path.js +23 -7
  166. package/Maths/math.path.js.map +1 -1
  167. package/Maths/math.vector.d.ts +93 -0
  168. package/Maths/math.vector.js +157 -26
  169. package/Maths/math.vector.js.map +1 -1
  170. package/Meshes/Builders/cylinderBuilder.js +5 -5
  171. package/Meshes/Builders/cylinderBuilder.js.map +1 -1
  172. package/Meshes/Builders/decalBuilder.js +1 -1
  173. package/Meshes/Builders/decalBuilder.js.map +1 -1
  174. package/Meshes/Builders/discBuilder.js +4 -4
  175. package/Meshes/Builders/discBuilder.js.map +1 -1
  176. package/Meshes/Builders/goldbergBuilder.js +4 -4
  177. package/Meshes/Builders/goldbergBuilder.js.map +1 -1
  178. package/Meshes/Builders/groundBuilder.js +4 -4
  179. package/Meshes/Builders/groundBuilder.js.map +1 -1
  180. package/Meshes/Builders/icoSphereBuilder.js +4 -4
  181. package/Meshes/Builders/icoSphereBuilder.js.map +1 -1
  182. package/Meshes/Builders/latheBuilder.js +1 -1
  183. package/Meshes/Builders/latheBuilder.js.map +1 -1
  184. package/Meshes/Builders/linesBuilder.js +2 -2
  185. package/Meshes/Builders/linesBuilder.js.map +1 -1
  186. package/Meshes/Builders/polyhedronBuilder.js +6 -6
  187. package/Meshes/Builders/polyhedronBuilder.js.map +1 -1
  188. package/Meshes/Builders/shapeBuilder.js +1 -1
  189. package/Meshes/Builders/shapeBuilder.js.map +1 -1
  190. package/Meshes/Builders/textBuilder.js +13 -5
  191. package/Meshes/Builders/textBuilder.js.map +1 -1
  192. package/Meshes/Builders/torusKnotBuilder.js +4 -4
  193. package/Meshes/Builders/torusKnotBuilder.js.map +1 -1
  194. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js +1 -1
  195. package/Meshes/Node/Blocks/Instances/instantiateOnVerticesBlock.js.map +1 -1
  196. package/Meshes/Node/Blocks/Sources/boxBlock.js +1 -0
  197. package/Meshes/Node/Blocks/Sources/boxBlock.js.map +1 -1
  198. package/Meshes/Node/Blocks/Sources/capsuleBlock.js +1 -0
  199. package/Meshes/Node/Blocks/Sources/capsuleBlock.js.map +1 -1
  200. package/Meshes/Node/Blocks/Sources/cylinderBlock.js +1 -0
  201. package/Meshes/Node/Blocks/Sources/cylinderBlock.js.map +1 -1
  202. package/Meshes/Node/Blocks/Sources/discBlock.js +1 -0
  203. package/Meshes/Node/Blocks/Sources/discBlock.js.map +1 -1
  204. package/Meshes/Node/Blocks/Sources/gridBlock.js +1 -0
  205. package/Meshes/Node/Blocks/Sources/gridBlock.js.map +1 -1
  206. package/Meshes/Node/Blocks/Sources/icoSphereBlock.js +1 -0
  207. package/Meshes/Node/Blocks/Sources/icoSphereBlock.js.map +1 -1
  208. package/Meshes/Node/Blocks/Sources/planeBlock.js +1 -0
  209. package/Meshes/Node/Blocks/Sources/planeBlock.js.map +1 -1
  210. package/Meshes/Node/Blocks/Sources/sphereBlock.js +1 -0
  211. package/Meshes/Node/Blocks/Sources/sphereBlock.js.map +1 -1
  212. package/Meshes/Node/Blocks/Sources/torusBlock.js +1 -0
  213. package/Meshes/Node/Blocks/Sources/torusBlock.js.map +1 -1
  214. package/Meshes/Node/nodeGeometry.js +1 -1
  215. package/Meshes/Node/nodeGeometry.js.map +1 -1
  216. package/Meshes/Node/nodeGeometryBlock.js +1 -0
  217. package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
  218. package/Meshes/Node/nodeGeometryBlockConnectionPoint.d.ts +14 -0
  219. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js +32 -5
  220. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js.map +1 -1
  221. package/Meshes/abstractMesh.js +5 -5
  222. package/Meshes/abstractMesh.js.map +1 -1
  223. package/Meshes/csg.js +5 -5
  224. package/Meshes/csg.js.map +1 -1
  225. package/Meshes/geodesicMesh.js +1 -1
  226. package/Meshes/geodesicMesh.js.map +1 -1
  227. package/Meshes/mesh.js +14 -10
  228. package/Meshes/mesh.js.map +1 -1
  229. package/Meshes/mesh.vertexData.js +1 -1
  230. package/Meshes/mesh.vertexData.js.map +1 -1
  231. package/Meshes/meshSimplification.js +2 -2
  232. package/Meshes/meshSimplification.js.map +1 -1
  233. package/Meshes/polygonMesh.js +7 -7
  234. package/Meshes/polygonMesh.js.map +1 -1
  235. package/Meshes/thinInstanceMesh.js +1 -1
  236. package/Meshes/thinInstanceMesh.js.map +1 -1
  237. package/Misc/codeStringParsingTools.d.ts +2 -1
  238. package/Misc/codeStringParsingTools.js +3 -2
  239. package/Misc/codeStringParsingTools.js.map +1 -1
  240. package/Misc/dds.js +1 -1
  241. package/Misc/dds.js.map +1 -1
  242. package/Misc/filesInput.js +1 -1
  243. package/Misc/filesInput.js.map +1 -1
  244. package/Misc/greasedLineTools.d.ts +2 -1
  245. package/Misc/greasedLineTools.js +2 -0
  246. package/Misc/greasedLineTools.js.map +1 -1
  247. package/Misc/precisionDate.js +4 -2
  248. package/Misc/precisionDate.js.map +1 -1
  249. package/Misc/sceneOptimizer.js +2 -2
  250. package/Misc/sceneOptimizer.js.map +1 -1
  251. package/Morph/morphTarget.js +1 -1
  252. package/Morph/morphTarget.js.map +1 -1
  253. package/Particles/gpuParticleSystem.js +1 -1
  254. package/Particles/gpuParticleSystem.js.map +1 -1
  255. package/Particles/particleSystem.js +2 -2
  256. package/Particles/particleSystem.js.map +1 -1
  257. package/Particles/particleSystemComponent.js +2 -2
  258. package/Particles/particleSystemComponent.js.map +1 -1
  259. package/Particles/particleSystemSet.js +1 -1
  260. package/Particles/particleSystemSet.js.map +1 -1
  261. package/Physics/v1/Plugins/cannonJSPlugin.js +2 -2
  262. package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -1
  263. package/Physics/v2/Plugins/havokPlugin.js +3 -1
  264. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  265. package/PostProcesses/postProcess.d.ts +1 -0
  266. package/PostProcesses/postProcess.js +30 -23
  267. package/PostProcesses/postProcess.js.map +1 -1
  268. package/PostProcesses/volumetricLightScatteringPostProcess.js +2 -2
  269. package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
  270. package/Probes/reflectionProbe.js +1 -1
  271. package/Probes/reflectionProbe.js.map +1 -1
  272. package/Rendering/edgesRenderer.js +3 -3
  273. package/Rendering/edgesRenderer.js.map +1 -1
  274. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js +2 -1
  275. package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js.map +1 -1
  276. package/Rendering/prePassRenderer.js +8 -4
  277. package/Rendering/prePassRenderer.js.map +1 -1
  278. package/Shaders/ShadersInclude/hdrFilteringFunctions.js +2 -1
  279. package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  280. package/Sprites/spriteManager.js +1 -1
  281. package/Sprites/spriteManager.js.map +1 -1
  282. package/Sprites/spriteMap.js +4 -4
  283. package/Sprites/spriteMap.js.map +1 -1
  284. package/Sprites/spriteSceneComponent.js +2 -2
  285. package/Sprites/spriteSceneComponent.js.map +1 -1
  286. package/XR/features/WebXRFeaturePointSystem.js +2 -2
  287. package/XR/features/WebXRFeaturePointSystem.js.map +1 -1
  288. package/abstractScene.js +16 -16
  289. package/abstractScene.js.map +1 -1
  290. package/assetContainer.js +2 -2
  291. package/assetContainer.js.map +1 -1
  292. package/node.js +2 -2
  293. package/node.js.map +1 -1
  294. package/package.json +1 -1
  295. package/scene.d.ts +0 -4
  296. package/scene.js +6 -12
  297. package/scene.js.map +1 -1
  298. package/Engines/WebGPU/webgpuRenderPassWrapper.d.ts +0 -13
  299. package/Engines/WebGPU/webgpuRenderPassWrapper.js +0 -18
  300. package/Engines/WebGPU/webgpuRenderPassWrapper.js.map +0 -1
@@ -15,7 +15,6 @@ import { WebGPUTextureHelper } from "./WebGPU/webgpuTextureHelper.js";
15
15
  import { WebGPUBufferManager } from "./WebGPU/webgpuBufferManager.js";
16
16
  import { WebGPUHardwareTexture } from "./WebGPU/webgpuHardwareTexture.js";
17
17
  import { UniformBuffer } from "../Materials/uniformBuffer.js";
18
- import { WebGPURenderPassWrapper } from "./WebGPU/webgpuRenderPassWrapper.js";
19
18
  import { WebGPUCacheSampler } from "./WebGPU/webgpuCacheSampler.js";
20
19
  import { WebGPUCacheRenderPipelineTree } from "./WebGPU/webgpuCacheRenderPipelineTree.js";
21
20
  import { WebGPUStencilStateComposer } from "./WebGPU/webgpuStencilStateComposer.js";
@@ -28,7 +27,6 @@ import { WebGPUClearQuad } from "./WebGPU/webgpuClearQuad.js";
28
27
  import { WebGPURenderItemBlendColor, WebGPURenderItemScissor, WebGPURenderItemStencilRef, WebGPURenderItemViewport, WebGPUBundleList } from "./WebGPU/webgpuBundleList.js";
29
28
  import { WebGPUTimestampQuery } from "./WebGPU/webgpuTimestampQuery.js";
30
29
  import { WebGPUOcclusionQuery } from "./WebGPU/webgpuOcclusionQuery.js";
31
- import { Observable } from "../Misc/observable.js";
32
30
  import { ShaderCodeInliner } from "./Processors/shaderCodeInliner.js";
33
31
  import { WebGPUTintWASM } from "./WebGPU/webgpuTintWASM.js";
34
32
  import { WebGPUShaderProcessor } from "./WebGPU/webgpuShaderProcessor.js";
@@ -217,7 +215,6 @@ export class WebGPUEngine extends Engine {
217
215
  // Page Life cycle and constants
218
216
  this._uploadEncoderDescriptor = { label: "upload" };
219
217
  this._renderEncoderDescriptor = { label: "render" };
220
- this._renderTargetEncoderDescriptor = { label: "renderTarget" };
221
218
  /** @internal */
222
219
  this._clearDepthValue = 1;
223
220
  /** @internal */
@@ -255,18 +252,26 @@ export class WebGPUEngine extends Engine {
255
252
  * Max number of uncaptured error messages to log
256
253
  */
257
254
  this.numMaxUncapturedErrors = 20;
258
- this._commandBuffers = [null, null, null];
255
+ this._commandBuffers = [null, null];
259
256
  // Frame Buffer Life Cycle (recreated for each render target pass)
260
257
  /** @internal */
261
258
  this._currentRenderPass = null;
262
- /** @internal */
263
- this._mainRenderPassWrapper = new WebGPURenderPassWrapper();
264
- /** @internal */
265
- this._rttRenderPassWrapper = new WebGPURenderPassWrapper();
259
+ this._mainRenderPassWrapper = {
260
+ renderPassDescriptor: null,
261
+ colorAttachmentViewDescriptor: null,
262
+ depthAttachmentViewDescriptor: null,
263
+ colorAttachmentGPUTextures: [],
264
+ depthTextureFormat: undefined,
265
+ };
266
+ this._rttRenderPassWrapper = {
267
+ renderPassDescriptor: null,
268
+ colorAttachmentViewDescriptor: null,
269
+ depthAttachmentViewDescriptor: null,
270
+ colorAttachmentGPUTextures: [],
271
+ depthTextureFormat: undefined,
272
+ };
266
273
  /** @internal */
267
274
  this._pendingDebugCommands = [];
268
- /** @internal */
269
- this._onAfterUnbindFrameBufferObservable = new Observable();
270
275
  this._currentOverrideVertexBuffers = null;
271
276
  this._currentIndexBuffer = null;
272
277
  this._colorWriteLocal = true;
@@ -296,20 +301,11 @@ export class WebGPUEngine extends Engine {
296
301
  // Dynamic WebGPU States
297
302
  //------------------------------------------------------------------------------
298
303
  // index 0 is for main render pass, 1 for RTT render pass
299
- this._viewportsCurrent = [
300
- { x: 0, y: 0, w: 0, h: 0 },
301
- { x: 0, y: 0, w: 0, h: 0 },
302
- ];
303
- this._scissorsCurrent = [
304
- { x: 0, y: 0, w: 0, h: 0 },
305
- { x: 0, y: 0, w: 0, h: 0 },
306
- ];
304
+ this._viewportsCurrent = { x: 0, y: 0, w: 0, h: 0 };
305
+ this._scissorsCurrent = { x: 0, y: 0, w: 0, h: 0 };
307
306
  this._scissorCached = { x: 0, y: 0, z: 0, w: 0 };
308
- this._stencilRefsCurrent = [-1, -1];
309
- this._blendColorsCurrent = [
310
- [null, null, null, null],
311
- [null, null, null, null],
312
- ];
307
+ this._stencilRefsCurrent = -1;
308
+ this._blendColorsCurrent = [null, null, null, null];
313
309
  this._name = "WebGPU";
314
310
  options.deviceDescriptor = options.deviceDescriptor || {};
315
311
  options.enableGPUDebugMarkers = (_b = options.enableGPUDebugMarkers) !== null && _b !== void 0 ? _b : false;
@@ -431,8 +427,7 @@ export class WebGPUEngine extends Engine {
431
427
  this._timestampQuery = new WebGPUTimestampQuery(this._device, this._bufferManager);
432
428
  this._occlusionQuery = this._device.createQuerySet ? new WebGPUOcclusionQuery(this, this._device, this._bufferManager) : undefined;
433
429
  this._bundleList = new WebGPUBundleList(this._device);
434
- this._bundleListRenderTarget = new WebGPUBundleList(this._device);
435
- this._snapshotRendering = new WebGPUSnapshotRendering(this, this._snapshotRenderingMode, this._bundleList, this._bundleListRenderTarget);
430
+ this._snapshotRendering = new WebGPUSnapshotRendering(this, this._snapshotRenderingMode, this._bundleList);
436
431
  this._ubInvertY = this._bufferManager.createBuffer(new Float32Array([-1, 0]), WebGPUConstants.BufferUsage.Uniform | WebGPUConstants.BufferUsage.CopyDst, "UBInvertY");
437
432
  this._ubDontInvertY = this._bufferManager.createBuffer(new Float32Array([1, 0]), WebGPUConstants.BufferUsage.Uniform | WebGPUConstants.BufferUsage.CopyDst, "UBDontInvertY");
438
433
  if (this.dbgVerboseLogsForFirstFrames) {
@@ -443,10 +438,9 @@ export class WebGPUEngine extends Engine {
443
438
  }
444
439
  this._uploadEncoder = this._device.createCommandEncoder(this._uploadEncoderDescriptor);
445
440
  this._renderEncoder = this._device.createCommandEncoder(this._renderEncoderDescriptor);
446
- this._renderTargetEncoder = this._device.createCommandEncoder(this._renderTargetEncoderDescriptor);
447
441
  this._initializeLimits();
448
442
  this._emptyVertexBuffer = new VertexBuffer(this, [0], "", false, false, 1, false, 0, 1);
449
- this._cacheRenderPipeline = new WebGPUCacheRenderPipelineTree(this._device, this._emptyVertexBuffer, !this._caps.textureFloatLinearFiltering);
443
+ this._cacheRenderPipeline = new WebGPUCacheRenderPipelineTree(this._device, this._emptyVertexBuffer);
450
444
  this._depthCullingState = new WebGPUDepthCullingState(this._cacheRenderPipeline);
451
445
  this._stencilStateComposer = new WebGPUStencilStateComposer(this._cacheRenderPipeline);
452
446
  this._stencilStateComposer.stencilGlobal = this._stencilState;
@@ -513,6 +507,7 @@ export class WebGPUEngine extends Engine {
513
507
  fragmentDepthSupported: true,
514
508
  highPrecisionShaderSupported: true,
515
509
  colorBufferFloat: true,
510
+ supportFloatTexturesResolve: false,
516
511
  textureFloat: true,
517
512
  textureFloatLinearFiltering: this._deviceEnabledExtensions.indexOf(WebGPUConstants.FeatureName.Float32Filterable) >= 0,
518
513
  textureFloatRender: true,
@@ -580,13 +575,14 @@ export class WebGPUEngine extends Engine {
580
575
  this._colorFormat = this._options.swapChainFormat;
581
576
  this._mainRenderPassWrapper.colorAttachmentGPUTextures = [new WebGPUHardwareTexture()];
582
577
  this._mainRenderPassWrapper.colorAttachmentGPUTextures[0].format = this._colorFormat;
578
+ this._setColorFormat(this._mainRenderPassWrapper);
583
579
  }
584
580
  // Set default values as WebGL with depth and stencil attachment for the broadest Compat.
585
581
  _initializeMainAttachments() {
586
582
  if (!this._bufferManager) {
587
583
  return;
588
584
  }
589
- this.flushFramebuffer(false);
585
+ this.flushFramebuffer();
590
586
  this._mainTextureExtends = {
591
587
  width: this.getRenderWidth(true),
592
588
  height: this.getRenderHeight(true),
@@ -637,6 +633,7 @@ export class WebGPUEngine extends Engine {
637
633
  }
638
634
  this._mainRenderPassWrapper.depthTextureFormat = this.isStencilEnable ? WebGPUConstants.TextureFormat.Depth24PlusStencil8 : WebGPUConstants.TextureFormat.Depth32Float;
639
635
  this._setDepthTextureFormat(this._mainRenderPassWrapper);
636
+ this._setColorFormat(this._mainRenderPassWrapper);
640
637
  const depthTextureDescriptor = {
641
638
  label: `Texture_MainDepthStencil_${this._mainTextureExtends.width}x${this._mainTextureExtends.height}`,
642
639
  size: this._mainTextureExtends,
@@ -695,7 +692,7 @@ export class WebGPUEngine extends Engine {
695
692
  this._count = 0;
696
693
  }
697
694
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
698
- console.log("frame #" + this._count + " - setSize called -", width, height);
695
+ console.log("frame #" + this._count + " - setSize -", width, height);
699
696
  }
700
697
  }
701
698
  this._initializeMainAttachments();
@@ -720,6 +717,23 @@ export class WebGPUEngine extends Engine {
720
717
  _getShaderProcessingContext(shaderLanguage) {
721
718
  return new WebGPUShaderProcessingContext(shaderLanguage);
722
719
  }
720
+ _currentPassIsMainPass() {
721
+ return this._currentRenderTarget === null;
722
+ }
723
+ _getCurrentRenderPass() {
724
+ if (this._currentRenderTarget && !this._currentRenderPass) {
725
+ // delayed creation of the render target pass, but we now need to create it as we are requested the render pass
726
+ this._startRenderTargetRenderPass(this._currentRenderTarget, false, null, false, false);
727
+ }
728
+ else if (!this._currentRenderPass) {
729
+ this._startMainRenderPass(false);
730
+ }
731
+ return this._currentRenderPass;
732
+ }
733
+ /** @internal */
734
+ _getCurrentRenderPassWrapper() {
735
+ return this._currentRenderTarget ? this._rttRenderPassWrapper : this._mainRenderPassWrapper;
736
+ }
723
737
  //------------------------------------------------------------------------------
724
738
  // Static Pipeline WebGPU States
725
739
  //------------------------------------------------------------------------------
@@ -773,37 +787,37 @@ export class WebGPUEngine extends Engine {
773
787
  getColorWrite() {
774
788
  return this._colorWriteLocal;
775
789
  }
776
- _resetCurrentViewport(index) {
777
- this._viewportsCurrent[index].x = 0;
778
- this._viewportsCurrent[index].y = 0;
779
- this._viewportsCurrent[index].w = 0;
780
- this._viewportsCurrent[index].h = 0;
781
- }
782
- _mustUpdateViewport(renderPass) {
783
- const index = renderPass === this._mainRenderPassWrapper.renderPass ? 0 : 1;
790
+ _mustUpdateViewport() {
784
791
  const x = this._viewportCached.x, y = this._viewportCached.y, w = this._viewportCached.z, h = this._viewportCached.w;
785
- const update = this._viewportsCurrent[index].x !== x || this._viewportsCurrent[index].y !== y || this._viewportsCurrent[index].w !== w || this._viewportsCurrent[index].h !== h;
792
+ const update = this._viewportsCurrent.x !== x || this._viewportsCurrent.y !== y || this._viewportsCurrent.w !== w || this._viewportsCurrent.h !== h;
786
793
  if (update) {
787
- this._viewportsCurrent[index].x = this._viewportCached.x;
788
- this._viewportsCurrent[index].y = this._viewportCached.y;
789
- this._viewportsCurrent[index].w = this._viewportCached.z;
790
- this._viewportsCurrent[index].h = this._viewportCached.w;
794
+ this._viewportsCurrent.x = this._viewportCached.x;
795
+ this._viewportsCurrent.y = this._viewportCached.y;
796
+ this._viewportsCurrent.w = this._viewportCached.z;
797
+ this._viewportsCurrent.h = this._viewportCached.w;
791
798
  }
792
799
  return update;
793
800
  }
794
- _applyViewport(renderPass) {
795
- let y = Math.floor(this._viewportCached.y);
801
+ _applyViewport(bundleList) {
802
+ const x = Math.floor(this._viewportCached.x);
803
+ const w = Math.floor(this._viewportCached.z);
796
804
  const h = Math.floor(this._viewportCached.w);
805
+ let y = Math.floor(this._viewportCached.y);
797
806
  if (!this._currentRenderTarget) {
798
807
  y = this.getRenderHeight(true) - y - h;
799
808
  }
800
- renderPass.setViewport(Math.floor(this._viewportCached.x), y, Math.floor(this._viewportCached.z), h, 0, 1);
809
+ if (bundleList) {
810
+ bundleList.addItem(new WebGPURenderItemViewport(x, y, w, h));
811
+ }
812
+ else {
813
+ this._getCurrentRenderPass().setViewport(x, y, w, h, 0, 1);
814
+ }
801
815
  if (this.dbgVerboseLogsForFirstFrames) {
802
816
  if (this._count === undefined) {
803
817
  this._count = 0;
804
818
  }
805
819
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
806
- console.log("frame #" + this._count + " - viewport applied - (", this._viewportCached.x, this._viewportCached.y, this._viewportCached.z, this._viewportCached.w, ") current pass is main pass=" + (renderPass === this._mainRenderPassWrapper.renderPass));
820
+ console.log("frame #" + this._count + " - viewport applied - (", this._viewportCached.x, this._viewportCached.y, this._viewportCached.z, this._viewportCached.w, ") current pass is main pass=" + this._currentPassIsMainPass());
807
821
  }
808
822
  }
809
823
  }
@@ -816,32 +830,31 @@ export class WebGPUEngine extends Engine {
816
830
  this._viewportCached.z = width;
817
831
  this._viewportCached.w = height;
818
832
  }
819
- _resetCurrentScissor(index) {
820
- this._scissorsCurrent[index].x = 0;
821
- this._scissorsCurrent[index].y = 0;
822
- this._scissorsCurrent[index].w = 0;
823
- this._scissorsCurrent[index].h = 0;
824
- }
825
- _mustUpdateScissor(renderPass) {
826
- const index = renderPass === this._mainRenderPassWrapper.renderPass ? 0 : 1;
833
+ _mustUpdateScissor() {
827
834
  const x = this._scissorCached.x, y = this._scissorCached.y, w = this._scissorCached.z, h = this._scissorCached.w;
828
- const update = this._scissorsCurrent[index].x !== x || this._scissorsCurrent[index].y !== y || this._scissorsCurrent[index].w !== w || this._scissorsCurrent[index].h !== h;
835
+ const update = this._scissorsCurrent.x !== x || this._scissorsCurrent.y !== y || this._scissorsCurrent.w !== w || this._scissorsCurrent.h !== h;
829
836
  if (update) {
830
- this._scissorsCurrent[index].x = this._scissorCached.x;
831
- this._scissorsCurrent[index].y = this._scissorCached.y;
832
- this._scissorsCurrent[index].w = this._scissorCached.z;
833
- this._scissorsCurrent[index].h = this._scissorCached.w;
837
+ this._scissorsCurrent.x = this._scissorCached.x;
838
+ this._scissorsCurrent.y = this._scissorCached.y;
839
+ this._scissorsCurrent.w = this._scissorCached.z;
840
+ this._scissorsCurrent.h = this._scissorCached.w;
834
841
  }
835
842
  return update;
836
843
  }
837
- _applyScissor(renderPass) {
838
- renderPass.setScissorRect(this._scissorCached.x, this._currentRenderTarget ? this._scissorCached.y : this.getRenderHeight() - this._scissorCached.w - this._scissorCached.y, this._scissorCached.z, this._scissorCached.w);
844
+ _applyScissor(bundleList) {
845
+ const y = this._currentRenderTarget ? this._scissorCached.y : this.getRenderHeight() - this._scissorCached.w - this._scissorCached.y;
846
+ if (bundleList) {
847
+ bundleList.addItem(new WebGPURenderItemScissor(this._scissorCached.x, y, this._scissorCached.z, this._scissorCached.w));
848
+ }
849
+ else {
850
+ this._getCurrentRenderPass().setScissorRect(this._scissorCached.x, y, this._scissorCached.z, this._scissorCached.w);
851
+ }
839
852
  if (this.dbgVerboseLogsForFirstFrames) {
840
853
  if (this._count === undefined) {
841
854
  this._count = 0;
842
855
  }
843
856
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
844
- console.log("frame #" + this._count + " - scissor applied - (", this._scissorCached.x, this._scissorCached.y, this._scissorCached.z, this._scissorCached.w, ") current pass is main pass=" + (renderPass === this._mainRenderPassWrapper.renderPass));
857
+ console.log("frame #" + this._count + " - scissor applied - (", this._scissorCached.x, this._scissorCached.y, this._scissorCached.z, this._scissorCached.w, ") current pass is main pass=" + this._currentPassIsMainPass());
845
858
  }
846
859
  }
847
860
  }
@@ -855,51 +868,52 @@ export class WebGPUEngine extends Engine {
855
868
  this._scissorCached.w = height;
856
869
  }
857
870
  disableScissor() {
858
- this._scissorCached.x = 0;
859
- this._scissorCached.y = 0;
860
- this._scissorCached.z = 0;
861
- this._scissorCached.w = 0;
862
- this._resetCurrentScissor(0);
863
- this._resetCurrentScissor(1);
864
- }
865
- _resetCurrentStencilRef(index) {
866
- this._stencilRefsCurrent[index] = -1;
867
- }
868
- _mustUpdateStencilRef(renderPass) {
869
- const index = renderPass === this._mainRenderPassWrapper.renderPass ? 0 : 1;
870
- const update = this._stencilStateComposer.funcRef !== this._stencilRefsCurrent[index];
871
+ this._scissorCached.x = this._scissorCached.y = this._scissorCached.z = this._scissorCached.w = 0;
872
+ this._scissorsCurrent.x = this._scissorsCurrent.y = this._scissorsCurrent.w = this._scissorsCurrent.h = 0;
873
+ }
874
+ _mustUpdateStencilRef() {
875
+ const update = this._stencilStateComposer.funcRef !== this._stencilRefsCurrent;
871
876
  if (update) {
872
- this._stencilRefsCurrent[index] = this._stencilStateComposer.funcRef;
877
+ this._stencilRefsCurrent = this._stencilStateComposer.funcRef;
873
878
  }
874
879
  return update;
875
880
  }
876
- /**
877
- * @internal
878
- */
879
- _applyStencilRef(renderPass) {
880
- var _a;
881
- renderPass.setStencilReference((_a = this._stencilStateComposer.funcRef) !== null && _a !== void 0 ? _a : 0);
882
- }
883
- _resetCurrentColorBlend(index) {
884
- this._blendColorsCurrent[index][0] = this._blendColorsCurrent[index][1] = this._blendColorsCurrent[index][2] = this._blendColorsCurrent[index][3] = null;
881
+ _applyStencilRef(bundleList) {
882
+ var _a, _b;
883
+ if (bundleList) {
884
+ bundleList.addItem(new WebGPURenderItemStencilRef((_a = this._stencilStateComposer.funcRef) !== null && _a !== void 0 ? _a : 0));
885
+ }
886
+ else {
887
+ this._getCurrentRenderPass().setStencilReference((_b = this._stencilStateComposer.funcRef) !== null && _b !== void 0 ? _b : 0);
888
+ }
885
889
  }
886
- _mustUpdateBlendColor(renderPass) {
887
- const index = renderPass === this._mainRenderPassWrapper.renderPass ? 0 : 1;
890
+ _mustUpdateBlendColor() {
888
891
  const colorBlend = this._alphaState._blendConstants;
889
- const update = colorBlend[0] !== this._blendColorsCurrent[index][0] ||
890
- colorBlend[1] !== this._blendColorsCurrent[index][1] ||
891
- colorBlend[2] !== this._blendColorsCurrent[index][2] ||
892
- colorBlend[3] !== this._blendColorsCurrent[index][3];
892
+ const update = colorBlend[0] !== this._blendColorsCurrent[0] ||
893
+ colorBlend[1] !== this._blendColorsCurrent[1] ||
894
+ colorBlend[2] !== this._blendColorsCurrent[2] ||
895
+ colorBlend[3] !== this._blendColorsCurrent[3];
893
896
  if (update) {
894
- this._blendColorsCurrent[index][0] = colorBlend[0];
895
- this._blendColorsCurrent[index][1] = colorBlend[1];
896
- this._blendColorsCurrent[index][2] = colorBlend[2];
897
- this._blendColorsCurrent[index][3] = colorBlend[3];
897
+ this._blendColorsCurrent[0] = colorBlend[0];
898
+ this._blendColorsCurrent[1] = colorBlend[1];
899
+ this._blendColorsCurrent[2] = colorBlend[2];
900
+ this._blendColorsCurrent[3] = colorBlend[3];
898
901
  }
899
902
  return update;
900
903
  }
901
- _applyBlendColor(renderPass) {
902
- renderPass.setBlendConstant(this._alphaState._blendConstants);
904
+ _applyBlendColor(bundleList) {
905
+ if (bundleList) {
906
+ bundleList.addItem(new WebGPURenderItemBlendColor(this._alphaState._blendConstants.slice()));
907
+ }
908
+ else {
909
+ this._getCurrentRenderPass().setBlendConstant(this._alphaState._blendConstants);
910
+ }
911
+ }
912
+ _resetRenderPassStates() {
913
+ this._viewportsCurrent.x = this._viewportsCurrent.y = this._viewportsCurrent.w = this._viewportsCurrent.h = 0;
914
+ this._scissorsCurrent.x = this._scissorsCurrent.y = this._scissorsCurrent.w = this._scissorsCurrent.h = 0;
915
+ this._stencilRefsCurrent = -1;
916
+ this._blendColorsCurrent[0] = this._blendColorsCurrent[1] = this._blendColorsCurrent[2] = this._blendColorsCurrent[3] = null;
903
917
  }
904
918
  /**
905
919
  * Clear the current render buffer or the current render target (if any is set up)
@@ -919,67 +933,55 @@ export class WebGPUEngine extends Engine {
919
933
  this._count = 0;
920
934
  }
921
935
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
922
- console.log("frame #" + this._count + " - clear called - backBuffer=", backBuffer, " depth=", depth, " stencil=", stencil, " scissor is active=", hasScissor);
936
+ console.log("frame #" + this._count + " - clear - backBuffer=", backBuffer, " depth=", depth, " stencil=", stencil, " scissor is active=", hasScissor);
923
937
  }
924
938
  }
925
939
  // We need to recreate the render pass so that the new parameters for clear color / depth / stencil are taken into account
926
940
  if (this._currentRenderTarget) {
927
941
  if (hasScissor) {
928
- if (!this._rttRenderPassWrapper.renderPass) {
942
+ if (!this._currentRenderPass) {
929
943
  this._startRenderTargetRenderPass(this._currentRenderTarget, false, backBuffer ? color : null, depth, stencil);
930
944
  }
931
- if (!this.compatibilityMode) {
932
- this._bundleListRenderTarget.addItem(new WebGPURenderItemScissor(this._scissorCached.x, this._scissorCached.y, this._scissorCached.z, this._scissorCached.w));
933
- }
934
- else {
935
- this._applyScissor(this._currentRenderPass);
936
- }
945
+ this._applyScissor(!this.compatibilityMode ? this._bundleList : null);
937
946
  this._clearFullQuad(backBuffer ? color : null, depth, stencil);
938
947
  }
939
948
  else {
940
949
  if (this._currentRenderPass) {
941
- this._endRenderTargetRenderPass();
950
+ this._endCurrentRenderPass();
942
951
  }
943
952
  this._startRenderTargetRenderPass(this._currentRenderTarget, true, backBuffer ? color : null, depth, stencil);
944
953
  }
945
954
  }
946
955
  else {
947
- if (!this._mainRenderPassWrapper.renderPass || !hasScissor) {
956
+ if (!this._currentRenderPass || !hasScissor) {
948
957
  this._startMainRenderPass(!hasScissor, backBuffer ? color : null, depth, stencil);
949
958
  }
950
959
  if (hasScissor) {
951
- if (!this.compatibilityMode) {
952
- this._bundleList.addItem(new WebGPURenderItemScissor(this._scissorCached.x, this._scissorCached.y, this._scissorCached.z, this._scissorCached.w));
953
- }
954
- else {
955
- this._applyScissor(this._currentRenderPass);
956
- }
960
+ this._applyScissor(!this.compatibilityMode ? this._bundleList : null);
957
961
  this._clearFullQuad(backBuffer ? color : null, depth, stencil);
958
962
  }
959
963
  }
960
964
  }
961
965
  _clearFullQuad(clearColor, clearDepth, clearStencil) {
962
- var _a, _b, _c;
966
+ var _a, _b;
963
967
  const renderPass = !this.compatibilityMode ? null : this._getCurrentRenderPass();
964
- const renderPassIndex = this._getCurrentRenderPassIndex();
965
- const bundleList = renderPassIndex === 0 ? this._bundleList : this._bundleListRenderTarget;
966
968
  this._clearQuad.setColorFormat(this._colorFormat);
967
969
  this._clearQuad.setDepthStencilFormat(this._depthTextureFormat);
968
970
  this._clearQuad.setMRTAttachments((_a = this._cacheRenderPipeline.mrtAttachments) !== null && _a !== void 0 ? _a : [], (_b = this._cacheRenderPipeline.mrtTextureArray) !== null && _b !== void 0 ? _b : [], this._cacheRenderPipeline.mrtTextureCount);
969
971
  if (!this.compatibilityMode) {
970
- bundleList.addItem(new WebGPURenderItemStencilRef(this._clearStencilValue));
972
+ this._bundleList.addItem(new WebGPURenderItemStencilRef(this._clearStencilValue));
971
973
  }
972
974
  else {
973
975
  renderPass.setStencilReference(this._clearStencilValue);
974
976
  }
975
977
  const bundle = this._clearQuad.clear(renderPass, clearColor, clearDepth, clearStencil, this.currentSampleCount);
976
978
  if (!this.compatibilityMode) {
977
- bundleList.addBundle(bundle);
978
- bundleList.addItem(new WebGPURenderItemStencilRef((_c = this._stencilStateComposer.funcRef) !== null && _c !== void 0 ? _c : 0));
979
+ this._bundleList.addBundle(bundle);
980
+ this._applyStencilRef(this._bundleList);
979
981
  this._reportDrawCall();
980
982
  }
981
983
  else {
982
- this._applyStencilRef(renderPass);
984
+ this._applyStencilRef(null);
983
985
  }
984
986
  }
985
987
  //------------------------------------------------------------------------------
@@ -1550,7 +1552,7 @@ export class WebGPUEngine extends Engine {
1550
1552
  if (!gpuTexture) {
1551
1553
  this._textureHelper.createGPUTextureForInternalTexture(texture);
1552
1554
  }
1553
- this._generateMipmaps(texture, texture.source === InternalTextureSource.RenderTarget || texture.source === InternalTextureSource.MultiRenderTarget ? this._renderTargetEncoder : undefined);
1555
+ this._generateMipmaps(texture);
1554
1556
  }
1555
1557
  }
1556
1558
  /**
@@ -1734,20 +1736,21 @@ export class WebGPUEngine extends Engine {
1734
1736
  * @param texture texture to generate the mipmaps for
1735
1737
  */
1736
1738
  generateMipmaps(texture) {
1737
- this._generateMipmaps(texture, this._renderTargetEncoder);
1739
+ this._generateMipmaps(texture);
1738
1740
  }
1739
1741
  /**
1740
1742
  * @internal
1741
1743
  */
1742
1744
  _generateMipmaps(texture, commandEncoder) {
1745
+ commandEncoder = commandEncoder !== null && commandEncoder !== void 0 ? commandEncoder : this._renderEncoder;
1743
1746
  const gpuHardwareTexture = texture._hardwareTexture;
1744
1747
  if (!gpuHardwareTexture) {
1745
1748
  return;
1746
1749
  }
1747
- // try as much as possible to use the command encoder corresponding to the current pass.
1748
- // If not possible (because the pass is started - generateMipmaps itself creates a pass and it's not allowed to have a pass inside a pass), use _uploadEncoder
1749
- commandEncoder =
1750
- commandEncoder !== null && commandEncoder !== void 0 ? commandEncoder : (this._currentRenderTarget && !this._currentRenderPass ? this._renderTargetEncoder : !this._currentRenderPass ? this._renderEncoder : this._uploadEncoder);
1750
+ if (commandEncoder === this._renderEncoder) {
1751
+ // We must close the current pass (if any) because we are going to use the render encoder to generate the mipmaps (so, we are going to create a new render pass)
1752
+ this._endCurrentRenderPass();
1753
+ }
1751
1754
  const format = texture._hardwareTexture.format;
1752
1755
  const mipmapCount = WebGPUTextureHelper.ComputeNumMipmapLevels(texture.width, texture.height);
1753
1756
  if (this.dbgVerboseLogsForFirstFrames) {
@@ -1755,7 +1758,16 @@ export class WebGPUEngine extends Engine {
1755
1758
  this._count = 0;
1756
1759
  }
1757
1760
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
1758
- console.log("frame #" + this._count + " - generate mipmaps called - width=", texture.width, "height=", texture.height, "isCube=", texture.isCube);
1761
+ console.log("frame #" +
1762
+ this._count +
1763
+ " - generate mipmaps - width=" +
1764
+ texture.width +
1765
+ ", height=" +
1766
+ texture.height +
1767
+ ", isCube=" +
1768
+ texture.isCube +
1769
+ ", command encoder=" +
1770
+ (commandEncoder === this._renderEncoder ? "render" : "copy"));
1759
1771
  }
1760
1772
  }
1761
1773
  if (texture.isCube) {
@@ -1786,7 +1798,7 @@ export class WebGPUEngine extends Engine {
1786
1798
  const data = new Uint8Array(imageData.buffer, imageData.byteOffset, imageData.byteLength);
1787
1799
  this._textureHelper.updateTexture(data, texture, width, height, texture.depth, gpuTextureWrapper.format, faceIndex, lod, texture.invertY, false, xOffset, yOffset);
1788
1800
  if (generateMipMaps) {
1789
- this._generateMipmaps(texture, this._renderTargetEncoder);
1801
+ this._generateMipmaps(texture);
1790
1802
  }
1791
1803
  }
1792
1804
  /**
@@ -1853,7 +1865,7 @@ export class WebGPUEngine extends Engine {
1853
1865
  */
1854
1866
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1855
1867
  readPixels(x, y, width, height, hasAlpha = true, flushRenderer = true) {
1856
- const renderPassWrapper = this._rttRenderPassWrapper.renderPass ? this._rttRenderPassWrapper : this._mainRenderPassWrapper;
1868
+ const renderPassWrapper = this._getCurrentRenderPassWrapper();
1857
1869
  const hardwareTexture = renderPassWrapper.colorAttachmentGPUTextures[0];
1858
1870
  if (!hardwareTexture) {
1859
1871
  // we are calling readPixels for a render pass with no color texture bound
@@ -1883,18 +1895,10 @@ export class WebGPUEngine extends Engine {
1883
1895
  * End the current frame
1884
1896
  */
1885
1897
  endFrame() {
1886
- this._snapshotRendering.endFrame(this._mainRenderPassWrapper.renderPass);
1887
- this._endMainRenderPass();
1898
+ this._endCurrentRenderPass();
1899
+ this._snapshotRendering.endFrame();
1888
1900
  this._timestampQuery.endFrame(this._renderEncoder);
1889
- this.flushFramebuffer(false);
1890
- if (this.dbgVerboseLogsForFirstFrames) {
1891
- if (this._count === undefined) {
1892
- this._count = 0;
1893
- }
1894
- if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
1895
- console.log("frame #" + this._count + " - counters");
1896
- }
1897
- }
1901
+ this.flushFramebuffer();
1898
1902
  this._textureHelper.destroyDeferredTextures();
1899
1903
  this._bufferManager.destroyDeferredBuffers();
1900
1904
  if (this._features._collectUbosUpdatedInFrame) {
@@ -1941,53 +1945,29 @@ export class WebGPUEngine extends Engine {
1941
1945
  }
1942
1946
  /**
1943
1947
  * Force a WebGPU flush (ie. a flush of all waiting commands)
1944
- * @param reopenPass true to reopen at the end of the function the pass that was active when entering the function
1945
1948
  */
1946
- flushFramebuffer(reopenPass = true) {
1949
+ flushFramebuffer() {
1947
1950
  // we need to end the current render pass (main or rtt) if any as we are not allowed to submit the command buffers when being in a pass
1948
- const currentRenderPassIsNULL = !this._currentRenderPass;
1949
- let currentPasses = 0; // 0 if no pass, 1 for rtt, 2 for main pass
1950
- if (this._currentRenderPass && this._currentRenderTarget) {
1951
- currentPasses |= 1;
1952
- this._endRenderTargetRenderPass();
1953
- }
1954
- if (this._mainRenderPassWrapper.renderPass) {
1955
- currentPasses |= 2;
1956
- this._endMainRenderPass();
1957
- }
1951
+ this._endCurrentRenderPass();
1958
1952
  this._commandBuffers[0] = this._uploadEncoder.finish();
1959
- this._commandBuffers[1] = this._renderTargetEncoder.finish();
1960
- this._commandBuffers[2] = this._renderEncoder.finish();
1953
+ this._commandBuffers[1] = this._renderEncoder.finish();
1961
1954
  this._device.queue.submit(this._commandBuffers);
1962
1955
  this._uploadEncoder = this._device.createCommandEncoder(this._uploadEncoderDescriptor);
1963
1956
  this._renderEncoder = this._device.createCommandEncoder(this._renderEncoderDescriptor);
1964
- this._renderTargetEncoder = this._device.createCommandEncoder(this._renderTargetEncoderDescriptor);
1965
1957
  this._timestampQuery.startFrame(this._uploadEncoder);
1966
1958
  this._textureHelper.setCommandEncoder(this._uploadEncoder);
1967
1959
  this._bundleList.reset();
1968
- this._bundleListRenderTarget.reset();
1969
- // restart the render pass
1970
- if (reopenPass) {
1971
- if (currentPasses & 2) {
1972
- this._startMainRenderPass(false);
1973
- }
1974
- if (currentPasses & 1) {
1975
- this._startRenderTargetRenderPass(this._currentRenderTarget, false, null, false, false);
1976
- }
1977
- if (currentRenderPassIsNULL && this._currentRenderTarget) {
1978
- this._currentRenderPass = null;
1979
- }
1980
- }
1981
1960
  }
1982
1961
  /** @internal */
1983
1962
  _currentFrameBufferIsDefaultFrameBuffer() {
1984
- return this._currentRenderTarget === null;
1963
+ return this._currentPassIsMainPass();
1985
1964
  }
1986
1965
  //------------------------------------------------------------------------------
1987
1966
  // Render Pass
1988
1967
  //------------------------------------------------------------------------------
1989
1968
  _startRenderTargetRenderPass(renderTargetWrapper, setClearStates, clearColor, clearDepth, clearStencil) {
1990
1969
  var _a, _b, _c, _d, _e, _f, _g, _h;
1970
+ this._endCurrentRenderPass();
1991
1971
  const rtWrapper = renderTargetWrapper;
1992
1972
  const depthStencilTexture = rtWrapper._depthStencilTexture;
1993
1973
  const gpuDepthStencilWrapper = depthStencilTexture === null || depthStencilTexture === void 0 ? void 0 : depthStencilTexture._hardwareTexture;
@@ -2084,73 +2064,36 @@ export class WebGPUEngine extends Engine {
2084
2064
  : undefined,
2085
2065
  occlusionQuerySet: ((_g = this._occlusionQuery) === null || _g === void 0 ? void 0 : _g.hasQueries) ? this._occlusionQuery.querySet : undefined,
2086
2066
  };
2087
- this._rttRenderPassWrapper.renderPass = this._renderTargetEncoder.beginRenderPass(this._rttRenderPassWrapper.renderPassDescriptor);
2067
+ this._currentRenderPass = this._renderEncoder.beginRenderPass(this._rttRenderPassWrapper.renderPassDescriptor);
2088
2068
  if (this.dbgVerboseLogsForFirstFrames) {
2089
2069
  if (this._count === undefined) {
2090
2070
  this._count = 0;
2091
2071
  }
2092
2072
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
2093
2073
  const internalTexture = rtWrapper.texture;
2094
- console.log("frame #" + this._count + " - render target begin pass - internalTexture.uniqueId=", internalTexture.uniqueId, "width=", internalTexture.width, "height=", internalTexture.height, this._rttRenderPassWrapper.renderPassDescriptor);
2074
+ console.log("frame #" +
2075
+ this._count +
2076
+ " - render target begin pass - rtt name=" +
2077
+ renderTargetWrapper.label +
2078
+ ", internalTexture.uniqueId=" +
2079
+ internalTexture.uniqueId +
2080
+ ", width=" +
2081
+ internalTexture.width +
2082
+ ", height=" +
2083
+ internalTexture.height +
2084
+ ", setClearStates=" +
2085
+ setClearStates, "renderPassDescriptor=", this._rttRenderPassWrapper.renderPassDescriptor);
2095
2086
  }
2096
2087
  }
2097
- this._currentRenderPass = this._rttRenderPassWrapper.renderPass;
2098
2088
  (_h = this._debugFlushPendingCommands) === null || _h === void 0 ? void 0 : _h.call(this);
2099
- this._resetCurrentViewport(1);
2100
- this._resetCurrentScissor(1);
2101
- this._resetCurrentStencilRef(1);
2102
- this._resetCurrentColorBlend(1);
2089
+ this._resetRenderPassStates();
2103
2090
  if (!gpuDepthStencilWrapper || !WebGPUTextureHelper.HasStencilAspect(gpuDepthStencilWrapper.format)) {
2104
2091
  this._stencilStateComposer.enabled = false;
2105
2092
  }
2106
2093
  }
2107
- /** @internal */
2108
- _endRenderTargetRenderPass() {
2109
- var _a, _b, _c, _d;
2110
- if (this._currentRenderPass) {
2111
- const gpuWrapper = (_a = this._currentRenderTarget.texture) === null || _a === void 0 ? void 0 : _a._hardwareTexture;
2112
- if (gpuWrapper && !this._snapshotRendering.endRenderTargetPass(this._currentRenderPass, gpuWrapper) && !this.compatibilityMode) {
2113
- this._bundleListRenderTarget.run(this._currentRenderPass);
2114
- this._bundleListRenderTarget.reset();
2115
- }
2116
- this._currentRenderPass.end();
2117
- if (this.dbgVerboseLogsForFirstFrames) {
2118
- if (this._count === undefined) {
2119
- this._count = 0;
2120
- }
2121
- if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
2122
- console.log("frame #" + this._count + " - render target end pass - internalTexture.uniqueId=", (_c = (_b = this._currentRenderTarget) === null || _b === void 0 ? void 0 : _b.texture) === null || _c === void 0 ? void 0 : _c.uniqueId);
2123
- }
2124
- }
2125
- (_d = this._debugPopGroup) === null || _d === void 0 ? void 0 : _d.call(this, 1);
2126
- this._resetCurrentViewport(1);
2127
- this._viewport(0, 0, 0, 0);
2128
- this._resetCurrentScissor(1);
2129
- this._resetCurrentStencilRef(1);
2130
- this._resetCurrentColorBlend(1);
2131
- this._currentRenderPass = null;
2132
- this._rttRenderPassWrapper.reset();
2133
- }
2134
- }
2135
- _getCurrentRenderPass() {
2136
- if (this._currentRenderTarget && !this._currentRenderPass) {
2137
- // delayed creation of the render target pass, but we now need to create it as we are requested the render pass
2138
- this._startRenderTargetRenderPass(this._currentRenderTarget, false, null, false, false);
2139
- }
2140
- else if (!this._currentRenderPass) {
2141
- this._startMainRenderPass(false);
2142
- }
2143
- return this._currentRenderPass;
2144
- }
2145
- /** @internal */
2146
- _getCurrentRenderPassIndex() {
2147
- return this._currentRenderPass === null ? -1 : this._currentRenderPass === this._mainRenderPassWrapper.renderPass ? 0 : 1;
2148
- }
2149
2094
  _startMainRenderPass(setClearStates, clearColor, clearDepth, clearStencil) {
2150
2095
  var _a, _b, _c;
2151
- if (this._mainRenderPassWrapper.renderPass) {
2152
- this.flushFramebuffer(false);
2153
- }
2096
+ this._endCurrentRenderPass();
2154
2097
  if (this.useReverseDepthBuffer) {
2155
2098
  this.setDepthFunctionToGreaterOrEqual();
2156
2099
  }
@@ -2188,48 +2131,47 @@ export class WebGPUEngine extends Engine {
2188
2131
  this._count = 0;
2189
2132
  }
2190
2133
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
2191
- console.log("frame #" + this._count + " - main begin pass - texture width=" + this._mainTextureExtends.width, " height=" + this._mainTextureExtends.height, this._mainRenderPassWrapper.renderPassDescriptor);
2134
+ console.log("frame #" + this._count + " - main begin pass - texture width=" + this._mainTextureExtends.width, " height=" + this._mainTextureExtends.height + ", setClearStates=" + setClearStates, "renderPassDescriptor=", this._mainRenderPassWrapper.renderPassDescriptor);
2192
2135
  }
2193
2136
  }
2194
2137
  (_b = this._debugPushGroup) === null || _b === void 0 ? void 0 : _b.call(this, "main pass", 0);
2195
2138
  this._currentRenderPass = this._renderEncoder.beginRenderPass(this._mainRenderPassWrapper.renderPassDescriptor);
2196
- this._mainRenderPassWrapper.renderPass = this._currentRenderPass;
2139
+ this._setDepthTextureFormat(this._mainRenderPassWrapper);
2140
+ this._setColorFormat(this._mainRenderPassWrapper);
2197
2141
  (_c = this._debugFlushPendingCommands) === null || _c === void 0 ? void 0 : _c.call(this);
2198
- this._resetCurrentViewport(0);
2199
- this._resetCurrentScissor(0);
2200
- this._resetCurrentStencilRef(0);
2201
- this._resetCurrentColorBlend(0);
2142
+ this._resetRenderPassStates();
2202
2143
  if (!this._isStencilEnable) {
2203
2144
  this._stencilStateComposer.enabled = false;
2204
2145
  }
2205
2146
  }
2206
- _endMainRenderPass() {
2207
- var _a;
2208
- if (this._mainRenderPassWrapper.renderPass !== null) {
2209
- this._snapshotRendering.endMainRenderPass();
2210
- if (!this.compatibilityMode && !this._snapshotRendering.play) {
2211
- this._bundleList.run(this._mainRenderPassWrapper.renderPass);
2212
- this._bundleList.reset();
2213
- }
2214
- this._mainRenderPassWrapper.renderPass.end();
2215
- if (this.dbgVerboseLogsForFirstFrames) {
2216
- if (this._count === undefined) {
2217
- this._count = 0;
2218
- }
2219
- if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
2220
- console.log("frame #" + this._count + " - main end pass");
2221
- }
2147
+ /** @internal */
2148
+ _endCurrentRenderPass() {
2149
+ var _a, _b, _c;
2150
+ if (!this._currentRenderPass) {
2151
+ return 0;
2152
+ }
2153
+ const currentPassIndex = this._currentPassIsMainPass() ? 2 : 1;
2154
+ if (!this._snapshotRendering.endRenderPass(this._currentRenderPass) && !this.compatibilityMode) {
2155
+ this._bundleList.run(this._currentRenderPass);
2156
+ this._bundleList.reset();
2157
+ }
2158
+ this._currentRenderPass.end();
2159
+ if (this.dbgVerboseLogsForFirstFrames) {
2160
+ if (this._count === undefined) {
2161
+ this._count = 0;
2222
2162
  }
2223
- (_a = this._debugPopGroup) === null || _a === void 0 ? void 0 : _a.call(this, 0);
2224
- this._resetCurrentViewport(0);
2225
- this._resetCurrentScissor(0);
2226
- this._resetCurrentStencilRef(0);
2227
- this._resetCurrentColorBlend(0);
2228
- if (this._mainRenderPassWrapper.renderPass === this._currentRenderPass) {
2229
- this._currentRenderPass = null;
2163
+ if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
2164
+ console.log("frame #" +
2165
+ this._count +
2166
+ " - " +
2167
+ (currentPassIndex === 2 ? "main" : "render target") +
2168
+ " end pass" +
2169
+ (currentPassIndex === 1 ? " - internalTexture.uniqueId=" + ((_b = (_a = this._currentRenderTarget) === null || _a === void 0 ? void 0 : _a.texture) === null || _b === void 0 ? void 0 : _b.uniqueId) : ""));
2230
2170
  }
2231
- this._mainRenderPassWrapper.reset(false);
2232
2171
  }
2172
+ (_c = this._debugPopGroup) === null || _c === void 0 ? void 0 : _c.call(this, 0);
2173
+ this._currentRenderPass = null;
2174
+ return currentPassIndex;
2233
2175
  }
2234
2176
  /**
2235
2177
  * Binds the frame buffer to the specified texture.
@@ -2247,10 +2189,10 @@ export class WebGPUEngine extends Engine {
2247
2189
  if (this._currentRenderTarget) {
2248
2190
  this.unBindFramebuffer(this._currentRenderTarget);
2249
2191
  }
2250
- this._currentRenderTarget = texture;
2251
- if (hardwareTexture) {
2252
- hardwareTexture._currentLayer = texture.isCube ? layer * 6 + faceIndex : layer;
2192
+ else {
2193
+ this._endCurrentRenderPass();
2253
2194
  }
2195
+ this._currentRenderTarget = texture;
2254
2196
  this._rttRenderPassWrapper.colorAttachmentGPUTextures[0] = hardwareTexture;
2255
2197
  this._rttRenderPassWrapper.depthTextureFormat = this._currentRenderTarget._depthStencilTexture
2256
2198
  ? WebGPUTextureHelper.GetWebGPUTextureFormat(-1, this._currentRenderTarget._depthStencilTexture.format)
@@ -2280,14 +2222,21 @@ export class WebGPUEngine extends Engine {
2280
2222
  this._count = 0;
2281
2223
  }
2282
2224
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
2283
- console.log("frame #" + this._count + " - bindFramebuffer called - internalTexture.uniqueId=", (_b = texture.texture) === null || _b === void 0 ? void 0 : _b.uniqueId, "face=", faceIndex, "lodLevel=", lodLevel, "layer=", layer, this._rttRenderPassWrapper.colorAttachmentViewDescriptor, this._rttRenderPassWrapper.depthAttachmentViewDescriptor);
2284
- }
2285
- }
2286
- this._currentRenderPass = null; // lazy creation of the render pass, hoping the render pass will be created by a call to clear()...
2287
- if (this.snapshotRendering && this.snapshotRenderingMode === 1) {
2288
- // force the creation of the render pass as we know in fast snapshot rendering mode clear() won't be called
2289
- this._getCurrentRenderPass();
2290
- }
2225
+ console.log("frame #" +
2226
+ this._count +
2227
+ " - bindFramebuffer - rtt name=" +
2228
+ texture.label +
2229
+ ", internalTexture.uniqueId=" +
2230
+ ((_b = texture.texture) === null || _b === void 0 ? void 0 : _b.uniqueId) +
2231
+ ", face=" +
2232
+ faceIndex +
2233
+ ", lodLevel=" +
2234
+ lodLevel +
2235
+ ", layer=" +
2236
+ layer, "colorAttachmentViewDescriptor=", this._rttRenderPassWrapper.colorAttachmentViewDescriptor, "depthAttachmentViewDescriptor=", this._rttRenderPassWrapper.depthAttachmentViewDescriptor);
2237
+ }
2238
+ }
2239
+ // We don't create the render pass just now, we do a lazy creation of the render pass, hoping the render pass will be created by a call to clear()...
2291
2240
  if (this._cachedViewport && !forceFullscreenViewport) {
2292
2241
  this.setViewport(this._cachedViewport, requiredWidth, requiredHeight);
2293
2242
  }
@@ -2322,28 +2271,22 @@ export class WebGPUEngine extends Engine {
2322
2271
  onBeforeUnbind();
2323
2272
  }
2324
2273
  this._currentRenderTarget = saveCRT;
2325
- if (this._currentRenderPass && this._currentRenderPass !== this._mainRenderPassWrapper.renderPass) {
2326
- this._endRenderTargetRenderPass();
2327
- }
2274
+ this._endCurrentRenderPass();
2328
2275
  if (((_a = texture.texture) === null || _a === void 0 ? void 0 : _a.generateMipMaps) && !disableGenerateMipMaps && !texture.isCube) {
2329
2276
  this._generateMipmaps(texture.texture);
2330
2277
  }
2331
2278
  this._currentRenderTarget = null;
2332
- this._onAfterUnbindFrameBufferObservable.notifyObservers(this);
2333
2279
  if (this.dbgVerboseLogsForFirstFrames) {
2334
2280
  if (this._count === undefined) {
2335
2281
  this._count = 0;
2336
2282
  }
2337
2283
  if (!this._count || this._count < this.dbgVerboseLogsNumFrames) {
2338
- console.log("frame #" + this._count + " - unBindFramebuffer called - internalTexture.uniqueId=", (_b = texture.texture) === null || _b === void 0 ? void 0 : _b.uniqueId);
2284
+ console.log("frame #" + this._count + " - unBindFramebuffer - rtt name=" + texture.label + ", internalTexture.uniqueId=", (_b = texture.texture) === null || _b === void 0 ? void 0 : _b.uniqueId);
2339
2285
  }
2340
2286
  }
2341
2287
  this._mrtAttachments = [];
2342
2288
  this._cacheRenderPipeline.setMRT([]);
2343
2289
  this._cacheRenderPipeline.setMRTAttachments(this._mrtAttachments);
2344
- this._currentRenderPass = this._mainRenderPassWrapper.renderPass;
2345
- this._setDepthTextureFormat(this._mainRenderPassWrapper);
2346
- this._setColorFormat(this._mainRenderPassWrapper);
2347
2290
  }
2348
2291
  /**
2349
2292
  * Unbind the current render target and bind the default framebuffer
@@ -2352,15 +2295,11 @@ export class WebGPUEngine extends Engine {
2352
2295
  if (this._currentRenderTarget) {
2353
2296
  this.unBindFramebuffer(this._currentRenderTarget);
2354
2297
  }
2355
- else {
2356
- this._currentRenderPass = this._mainRenderPassWrapper.renderPass;
2357
- this._setDepthTextureFormat(this._mainRenderPassWrapper);
2358
- this._setColorFormat(this._mainRenderPassWrapper);
2298
+ else if (!this._currentRenderPass) {
2299
+ this._startMainRenderPass(false);
2359
2300
  }
2360
- if (this._currentRenderPass) {
2361
- if (this._cachedViewport) {
2362
- this.setViewport(this._cachedViewport);
2363
- }
2301
+ if (this._cachedViewport) {
2302
+ this.setViewport(this._cachedViewport);
2364
2303
  }
2365
2304
  this.wipeCaches();
2366
2305
  }
@@ -2426,46 +2365,26 @@ export class WebGPUEngine extends Engine {
2426
2365
  }
2427
2366
  this._stencilStateComposer.stencilMaterial = stencil;
2428
2367
  }
2429
- _applyRenderPassChanges(renderPass, bundleList) {
2430
- var _a;
2431
- const mustUpdateViewport = this._mustUpdateViewport(renderPass);
2432
- const mustUpdateScissor = this._mustUpdateScissor(renderPass);
2433
- const mustUpdateStencilRef = !this._stencilStateComposer.enabled ? false : this._mustUpdateStencilRef(renderPass);
2434
- const mustUpdateBlendColor = !this._alphaState.alphaBlend ? false : this._mustUpdateBlendColor(renderPass);
2435
- if (bundleList) {
2436
- if (mustUpdateViewport) {
2437
- bundleList.addItem(new WebGPURenderItemViewport(this._viewportCached.x, this._viewportCached.y, this._viewportCached.z, this._viewportCached.w));
2438
- }
2439
- if (mustUpdateScissor) {
2440
- bundleList.addItem(new WebGPURenderItemScissor(this._scissorCached.x, this._scissorCached.y, this._scissorCached.z, this._scissorCached.w));
2441
- }
2442
- if (mustUpdateStencilRef) {
2443
- bundleList.addItem(new WebGPURenderItemStencilRef((_a = this._stencilStateComposer.funcRef) !== null && _a !== void 0 ? _a : 0));
2444
- }
2445
- if (mustUpdateBlendColor) {
2446
- bundleList.addItem(new WebGPURenderItemBlendColor(this._alphaState._blendConstants.slice()));
2447
- }
2368
+ _applyRenderPassChanges(bundleList) {
2369
+ const mustUpdateStencilRef = !this._stencilStateComposer.enabled ? false : this._mustUpdateStencilRef();
2370
+ const mustUpdateBlendColor = !this._alphaState.alphaBlend ? false : this._mustUpdateBlendColor();
2371
+ if (this._mustUpdateViewport()) {
2372
+ this._applyViewport(bundleList);
2448
2373
  }
2449
- else {
2450
- if (mustUpdateViewport) {
2451
- this._applyViewport(renderPass);
2452
- }
2453
- if (mustUpdateScissor) {
2454
- this._applyScissor(renderPass);
2455
- }
2456
- if (mustUpdateStencilRef) {
2457
- this._applyStencilRef(renderPass);
2458
- }
2459
- if (mustUpdateBlendColor) {
2460
- this._applyBlendColor(renderPass);
2461
- }
2374
+ if (this._mustUpdateScissor()) {
2375
+ this._applyScissor(bundleList);
2376
+ }
2377
+ if (mustUpdateStencilRef) {
2378
+ this._applyStencilRef(bundleList);
2379
+ }
2380
+ if (mustUpdateBlendColor) {
2381
+ this._applyBlendColor(bundleList);
2462
2382
  }
2463
2383
  }
2464
2384
  _draw(drawType, fillMode, start, count, instancesCount) {
2465
2385
  var _a;
2466
2386
  const renderPass = this._getCurrentRenderPass();
2467
- const renderPassIndex = this._getCurrentRenderPassIndex();
2468
- const bundleList = renderPassIndex === 0 ? this._bundleList : this._bundleListRenderTarget;
2387
+ const bundleList = this._bundleList;
2469
2388
  this.applyStates();
2470
2389
  const webgpuPipelineContext = this._currentEffect._pipelineContext;
2471
2390
  this.bindUniformBufferBase(this._currentRenderTarget ? this._ubInvertY : this._ubDontInvertY, 0, WebGPUShaderProcessor.InternalsUBOName);
@@ -2484,7 +2403,7 @@ export class WebGPUEngine extends Engine {
2484
2403
  const useFastPath = !this.compatibilityMode && this._currentDrawContext.fastBundle;
2485
2404
  let renderPass2 = renderPass;
2486
2405
  if (useFastPath || this._snapshotRendering.record) {
2487
- this._applyRenderPassChanges(renderPass, bundleList);
2406
+ this._applyRenderPassChanges(bundleList);
2488
2407
  if (!this._snapshotRendering.record) {
2489
2408
  this._counters.numBundleReuseNonCompatMode++;
2490
2409
  if (this._currentDrawContext.indirectDrawBuffer) {
@@ -2498,12 +2417,13 @@ export class WebGPUEngine extends Engine {
2498
2417
  bundleList.numDrawCalls++;
2499
2418
  }
2500
2419
  let textureState = 0;
2501
- if (!this._caps.textureFloatLinearFiltering && this._currentMaterialContext.hasFloatTextures) {
2420
+ if (this._currentMaterialContext.hasFloatOrDepthTextures) {
2502
2421
  let bitVal = 1;
2503
2422
  for (let i = 0; i < webgpuPipelineContext.shaderProcessingContext.textureNames.length; ++i) {
2504
2423
  const textureName = webgpuPipelineContext.shaderProcessingContext.textureNames[i];
2505
2424
  const texture = (_a = this._currentMaterialContext.textures[textureName]) === null || _a === void 0 ? void 0 : _a.texture;
2506
- if ((texture === null || texture === void 0 ? void 0 : texture.type) === 1) {
2425
+ const textureIsDepth = texture && texture.format >= 13 && texture.format <= 18;
2426
+ if (((texture === null || texture === void 0 ? void 0 : texture.type) === 1 && !this._caps.textureFloatLinearFiltering) || textureIsDepth) {
2507
2427
  textureState |= bitVal;
2508
2428
  }
2509
2429
  bitVal = bitVal << 1;
@@ -2513,13 +2433,13 @@ export class WebGPUEngine extends Engine {
2513
2433
  const pipeline = this._cacheRenderPipeline.getRenderPipeline(fillMode, this._currentEffect, this.currentSampleCount, textureState);
2514
2434
  const bindGroups = this._cacheBindGroups.getBindGroups(webgpuPipelineContext, this._currentDrawContext, this._currentMaterialContext);
2515
2435
  if (!this._snapshotRendering.record) {
2516
- this._applyRenderPassChanges(renderPass, !this.compatibilityMode ? bundleList : null);
2436
+ this._applyRenderPassChanges(!this.compatibilityMode ? bundleList : null);
2517
2437
  if (!this.compatibilityMode) {
2518
2438
  this._counters.numBundleCreationNonCompatMode++;
2519
2439
  renderPass2 = this._device.createRenderBundleEncoder({
2520
2440
  colorFormats: this._cacheRenderPipeline.colorFormats,
2521
2441
  depthStencilFormat: this._depthTextureFormat,
2522
- sampleCount: this.currentSampleCount,
2442
+ sampleCount: WebGPUTextureHelper.GetSample(this.currentSampleCount),
2523
2443
  });
2524
2444
  }
2525
2445
  }