@babylonjs/core 7.4.0 → 7.6.0

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 (235) hide show
  1. package/Audio/sound.js +3 -0
  2. package/Audio/sound.js.map +1 -1
  3. package/Buffers/storageBuffer.d.ts +2 -2
  4. package/Buffers/storageBuffer.js.map +1 -1
  5. package/Cameras/arcRotateCamera.js +3 -0
  6. package/Cameras/arcRotateCamera.js.map +1 -1
  7. package/Cameras/flyCamera.js +3 -0
  8. package/Cameras/flyCamera.js.map +1 -1
  9. package/Cameras/followCamera.js +4 -0
  10. package/Cameras/followCamera.js.map +1 -1
  11. package/Cameras/freeCamera.js +3 -0
  12. package/Cameras/freeCamera.js.map +1 -1
  13. package/Engines/Extensions/index.d.ts +0 -3
  14. package/Engines/Extensions/index.js +0 -3
  15. package/Engines/Extensions/index.js.map +1 -1
  16. package/Engines/WebGPU/Extensions/index.d.ts +0 -3
  17. package/Engines/WebGPU/Extensions/index.js +0 -3
  18. package/Engines/WebGPU/Extensions/index.js.map +1 -1
  19. package/Engines/abstractEngine.d.ts +11 -63
  20. package/Engines/abstractEngine.js +7 -7
  21. package/Engines/abstractEngine.js.map +1 -1
  22. package/Engines/nativeEngine.js +2 -2
  23. package/Engines/nativeEngine.js.map +1 -1
  24. package/Engines/thinEngine.d.ts +2 -2
  25. package/Engines/thinEngine.functions.d.ts +2 -10
  26. package/Engines/thinEngine.functions.js +1 -20
  27. package/Engines/thinEngine.functions.js.map +1 -1
  28. package/Engines/thinEngine.js +27 -11
  29. package/Engines/thinEngine.js.map +1 -1
  30. package/Engines/webgpuEngine.d.ts +54 -2
  31. package/Engines/webgpuEngine.js +147 -0
  32. package/Engines/webgpuEngine.js.map +1 -1
  33. package/Inputs/scene.inputManager.d.ts +1 -0
  34. package/Inputs/scene.inputManager.js +1 -0
  35. package/Inputs/scene.inputManager.js.map +1 -1
  36. package/Lights/directionalLight.js +3 -0
  37. package/Lights/directionalLight.js.map +1 -1
  38. package/Lights/hemisphericLight.js +3 -0
  39. package/Lights/hemisphericLight.js.map +1 -1
  40. package/Lights/pointLight.js +3 -0
  41. package/Lights/pointLight.js.map +1 -1
  42. package/Lights/spotLight.js +3 -0
  43. package/Lights/spotLight.js.map +1 -1
  44. package/Loading/Plugins/babylonFileLoader.js +25 -14
  45. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  46. package/Materials/Background/backgroundMaterial.js +1 -2
  47. package/Materials/Background/backgroundMaterial.js.map +1 -1
  48. package/Materials/GreasedLine/greasedLinePluginMaterial.js +7 -3
  49. package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
  50. package/Materials/Node/Blocks/Dual/clipPlanesBlock.d.ts +1 -1
  51. package/Materials/Node/Blocks/Dual/clipPlanesBlock.js.map +1 -1
  52. package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +1 -1
  53. package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
  54. package/Materials/Node/Blocks/Dual/fogBlock.d.ts +1 -1
  55. package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
  56. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.d.ts +1 -1
  57. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
  58. package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +1 -1
  59. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
  60. package/Materials/Node/Blocks/Dual/textureBlock.d.ts +1 -1
  61. package/Materials/Node/Blocks/Dual/textureBlock.js +5 -1
  62. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  63. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +1 -1
  64. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  65. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +1 -1
  66. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  67. package/Materials/Node/Blocks/Fragment/screenSizeBlock.d.ts +1 -1
  68. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js.map +1 -1
  69. package/Materials/Node/Blocks/Fragment/shadowMapBlock.d.ts +1 -1
  70. package/Materials/Node/Blocks/Fragment/shadowMapBlock.js.map +1 -1
  71. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.d.ts +2 -1
  72. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js +1 -0
  73. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js.map +1 -1
  74. package/Materials/Node/Blocks/Input/inputBlock.d.ts +1 -1
  75. package/Materials/Node/Blocks/Input/inputBlock.js +16 -0
  76. package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
  77. package/Materials/Node/Blocks/PBR/anisotropyBlock.d.ts +1 -1
  78. package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
  79. package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +1 -1
  80. package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
  81. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.d.ts +1 -1
  82. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  83. package/Materials/Node/Blocks/PBR/reflectionBlock.d.ts +1 -1
  84. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  85. package/Materials/Node/Blocks/PBR/refractionBlock.d.ts +1 -1
  86. package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
  87. package/Materials/Node/Blocks/Vertex/lightInformationBlock.d.ts +1 -1
  88. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js.map +1 -1
  89. package/Materials/Node/Blocks/Vertex/vertexOutputBlock.d.ts +1 -1
  90. package/Materials/Node/Blocks/Vertex/vertexOutputBlock.js.map +1 -1
  91. package/Materials/Node/Blocks/baseMathBlock.js +2 -4
  92. package/Materials/Node/Blocks/baseMathBlock.js.map +1 -1
  93. package/Materials/Node/Blocks/modBlock.js +7 -1
  94. package/Materials/Node/Blocks/modBlock.js.map +1 -1
  95. package/Materials/Node/Blocks/triPlanarBlock.d.ts +1 -1
  96. package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
  97. package/Materials/Node/nodeMaterial.d.ts +2 -4
  98. package/Materials/Node/nodeMaterial.js +1 -3
  99. package/Materials/Node/nodeMaterial.js.map +1 -1
  100. package/Materials/Node/nodeMaterialBlockConnectionPoint.d.ts +34 -14
  101. package/Materials/Node/nodeMaterialBlockConnectionPoint.js +87 -9
  102. package/Materials/Node/nodeMaterialBlockConnectionPoint.js.map +1 -1
  103. package/Materials/Node/nodeMaterialBuildState.d.ts +1 -1
  104. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  105. package/Materials/PBR/pbrBaseMaterial.d.ts +1 -2
  106. package/Materials/PBR/pbrBaseMaterial.js +1 -2
  107. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  108. package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -1
  109. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  110. package/Materials/Textures/htmlElementTexture.d.ts +0 -1
  111. package/Materials/Textures/htmlElementTexture.js +7 -2
  112. package/Materials/Textures/htmlElementTexture.js.map +1 -1
  113. package/Materials/Textures/videoTexture.js +4 -2
  114. package/Materials/Textures/videoTexture.js.map +1 -1
  115. package/Materials/effect.d.ts +4 -0
  116. package/Materials/effect.functions.d.ts +1 -1
  117. package/Materials/effect.functions.js +6 -4
  118. package/Materials/effect.functions.js.map +1 -1
  119. package/Materials/effect.js +1 -1
  120. package/Materials/effect.js.map +1 -1
  121. package/Materials/effect.webgl.functions.js +3 -3
  122. package/Materials/effect.webgl.functions.js.map +1 -1
  123. package/Materials/imageProcessingConfiguration.d.ts +5 -0
  124. package/Materials/imageProcessingConfiguration.defines.d.ts +2 -4
  125. package/Materials/imageProcessingConfiguration.defines.js +1 -2
  126. package/Materials/imageProcessingConfiguration.defines.js.map +1 -1
  127. package/Materials/imageProcessingConfiguration.js +26 -11
  128. package/Materials/imageProcessingConfiguration.js.map +1 -1
  129. package/Materials/materialPluginBase.js +3 -0
  130. package/Materials/materialPluginBase.js.map +1 -1
  131. package/Materials/meshDebugPluginMaterial.js +2 -2
  132. package/Materials/meshDebugPluginMaterial.js.map +1 -1
  133. package/Materials/shaderMaterial.js +18 -8
  134. package/Materials/shaderMaterial.js.map +1 -1
  135. package/Materials/standardMaterial.d.ts +1 -2
  136. package/Materials/standardMaterial.js +1 -2
  137. package/Materials/standardMaterial.js.map +1 -1
  138. package/Maths/math.color.d.ts +85 -82
  139. package/Maths/math.color.js +34 -27
  140. package/Maths/math.color.js.map +1 -1
  141. package/Maths/math.vector.d.ts +202 -202
  142. package/Maths/math.vector.js +133 -130
  143. package/Maths/math.vector.js.map +1 -1
  144. package/Maths/tensor.d.ts +44 -42
  145. package/Maths/tensor.js.map +1 -1
  146. package/Meshes/Compression/dracoCompression.d.ts +7 -0
  147. package/Meshes/Compression/dracoCompression.js +14 -0
  148. package/Meshes/Compression/dracoCompression.js.map +1 -1
  149. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js +6 -0
  150. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js.map +1 -1
  151. package/Meshes/instancedMesh.js +3 -0
  152. package/Meshes/instancedMesh.js.map +1 -1
  153. package/Misc/dumpTools.js +11 -0
  154. package/Misc/dumpTools.js.map +1 -1
  155. package/Misc/fileTools.d.ts +9 -3
  156. package/Misc/fileTools.js +17 -14
  157. package/Misc/fileTools.js.map +1 -1
  158. package/Misc/greasedLineTools.js +7 -1
  159. package/Misc/greasedLineTools.js.map +1 -1
  160. package/Misc/sceneSerializer.js +9 -1
  161. package/Misc/sceneSerializer.js.map +1 -1
  162. package/Misc/textureTools.d.ts +2 -0
  163. package/Misc/textureTools.js +2 -0
  164. package/Misc/textureTools.js.map +1 -1
  165. package/Misc/tools.d.ts +5 -6
  166. package/Misc/tools.js +9 -9
  167. package/Misc/tools.js.map +1 -1
  168. package/Misc/typeStore.d.ts +4 -0
  169. package/Misc/typeStore.js +11 -0
  170. package/Misc/typeStore.js.map +1 -1
  171. package/NOTICE.md +8 -0
  172. package/Particles/baseParticleSystem.js +3 -0
  173. package/Particles/baseParticleSystem.js.map +1 -1
  174. package/Particles/computeShaderParticleSystem.d.ts +2 -2
  175. package/Particles/computeShaderParticleSystem.js.map +1 -1
  176. package/Physics/v1/Plugins/ammoJSPlugin.js +39 -10
  177. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
  178. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +4 -0
  179. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
  180. package/PostProcesses/imageProcessingPostProcess.js +14 -5
  181. package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
  182. package/Rendering/GlobalIllumination/giRSMManager.d.ts +6 -0
  183. package/Rendering/GlobalIllumination/giRSMManager.js +15 -1
  184. package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
  185. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +22 -20
  186. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -1
  187. package/Rendering/renderingGroup.js +1 -1
  188. package/Rendering/renderingGroup.js.map +1 -1
  189. package/Shaders/ShadersInclude/imageProcessingFunctions.js +8 -5
  190. package/Shaders/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  191. package/Shaders/ShadersInclude/screenSpaceRayTrace.js +8 -0
  192. package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
  193. package/Shaders/lod.fragment.d.ts +5 -0
  194. package/Shaders/lod.fragment.js +12 -0
  195. package/Shaders/lod.fragment.js.map +1 -0
  196. package/Shaders/lodCube.fragment.d.ts +5 -0
  197. package/Shaders/lodCube.fragment.js +30 -0
  198. package/Shaders/lodCube.fragment.js.map +1 -0
  199. package/Shaders/screenSpaceReflection2.fragment.js +7 -1
  200. package/Shaders/screenSpaceReflection2.fragment.js.map +1 -1
  201. package/Shaders/ssao2.fragment.js +1 -1
  202. package/Shaders/ssao2.fragment.js.map +1 -1
  203. package/XR/features/WebXRNearInteraction.d.ts +6 -0
  204. package/XR/features/WebXRNearInteraction.js +14 -2
  205. package/XR/features/WebXRNearInteraction.js.map +1 -1
  206. package/XR/webXRManagedOutputCanvas.d.ts +2 -0
  207. package/XR/webXRManagedOutputCanvas.js +14 -6
  208. package/XR/webXRManagedOutputCanvas.js.map +1 -1
  209. package/abstractScene.js +3 -0
  210. package/abstractScene.js.map +1 -1
  211. package/assets/glslang/glslang.js +113 -0
  212. package/assets/glslang/glslang.wasm +0 -0
  213. package/assets/twgsl/twgsl.js +53 -0
  214. package/assets/twgsl/twgsl.wasm +0 -0
  215. package/package.json +1 -1
  216. package/scene.js +3 -0
  217. package/scene.js.map +1 -1
  218. package/Engines/Extensions/engine.externalTexture.d.ts +0 -18
  219. package/Engines/Extensions/engine.externalTexture.js +0 -10
  220. package/Engines/Extensions/engine.externalTexture.js.map +0 -1
  221. package/Engines/Extensions/engine.storageBuffer.d.ts +0 -39
  222. package/Engines/Extensions/engine.storageBuffer.js +0 -16
  223. package/Engines/Extensions/engine.storageBuffer.js.map +0 -1
  224. package/Engines/Extensions/engine.textureSampler.d.ts +0 -12
  225. package/Engines/Extensions/engine.textureSampler.js +0 -6
  226. package/Engines/Extensions/engine.textureSampler.js.map +0 -1
  227. package/Engines/WebGPU/Extensions/engine.externalTexture.d.ts +0 -28
  228. package/Engines/WebGPU/Extensions/engine.externalTexture.js +0 -18
  229. package/Engines/WebGPU/Extensions/engine.externalTexture.js.map +0 -1
  230. package/Engines/WebGPU/Extensions/engine.storageBuffer.d.ts +0 -50
  231. package/Engines/WebGPU/Extensions/engine.storageBuffer.js +0 -88
  232. package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +0 -1
  233. package/Engines/WebGPU/Extensions/engine.textureSampler.d.ts +0 -22
  234. package/Engines/WebGPU/Extensions/engine.textureSampler.js +0 -9
  235. package/Engines/WebGPU/Extensions/engine.textureSampler.js.map +0 -1
@@ -10,7 +10,8 @@ import type { BaseTexture } from "../Materials/Textures/baseTexture";
10
10
  import type { IShaderProcessor } from "./Processors/iShaderProcessor";
11
11
  import type { ShaderProcessingContext } from "./Processors/shaderProcessingOptions";
12
12
  import { WebGPUTextureManager } from "./WebGPU/webgpuTextureManager";
13
- import { type ISceneLike, AbstractEngine } from "./abstractEngine";
13
+ import { AbstractEngine } from "./abstractEngine";
14
+ import type { ISceneLike, AbstractEngineOptions } from "./abstractEngine";
14
15
  import { WebGPUBufferManager } from "./WebGPU/webgpuBufferManager";
15
16
  import type { HardwareTextureWrapper } from "../Materials/Textures/hardwareTextureWrapper";
16
17
  import { WebGPUHardwareTexture } from "./WebGPU/webgpuHardwareTexture";
@@ -36,7 +37,6 @@ import type { RenderTargetTexture } from "../Materials/Textures/renderTargetText
36
37
  import type { RenderTargetWrapper } from "./renderTargetWrapper";
37
38
  import { WebGPUPerfCounter } from "./WebGPU/webgpuPerfCounter";
38
39
  import type { Scene } from "../scene";
39
- import type { AbstractEngineOptions } from "./abstractEngine";
40
40
  import type { PostProcess } from "../PostProcesses/postProcess";
41
41
  import { PerformanceMonitor } from "../Misc/performanceMonitor";
42
42
  import "./AbstractEngine/abstractEngine.loadingScreen";
@@ -44,6 +44,8 @@ import "./AbstractEngine/abstractEngine.dom";
44
44
  import "./AbstractEngine/abstractEngine.states";
45
45
  import "./AbstractEngine/abstractEngine.renderPass";
46
46
  import "../Audio/audioEngine";
47
+ import type { TextureSampler } from "../Materials/Textures/textureSampler";
48
+ import type { StorageBuffer } from "../Buffers/storageBuffer";
47
49
  /** @internal */
48
50
  interface IWebGPURenderPassWrapper {
49
51
  renderPassDescriptor: Nullable<GPURenderPassDescriptor>;
@@ -1018,5 +1020,55 @@ export declare class WebGPUEngine extends AbstractEngine {
1018
1020
  * @returns the error code
1019
1021
  */
1020
1022
  getError(): number;
1023
+ /**
1024
+ * Creates an external texture
1025
+ * @param video video element
1026
+ * @returns the external texture, or null if external textures are not supported by the engine
1027
+ */
1028
+ createExternalTexture(video: HTMLVideoElement): Nullable<ExternalTexture>;
1029
+ /**
1030
+ * Sets an internal texture to the according uniform.
1031
+ * @param name The name of the uniform in the effect
1032
+ * @param texture The texture to apply
1033
+ */
1034
+ setExternalTexture(name: string, texture: Nullable<ExternalTexture>): void;
1035
+ /**
1036
+ * Sets a texture sampler to the according uniform.
1037
+ * @param name The name of the uniform in the effect
1038
+ * @param sampler The sampler to apply
1039
+ */
1040
+ setTextureSampler(name: string, sampler: Nullable<TextureSampler>): void;
1041
+ /**
1042
+ * Creates a storage buffer
1043
+ * @param data the data for the storage buffer or the size of the buffer
1044
+ * @param creationFlags flags to use when creating the buffer (see Constants.BUFFER_CREATIONFLAG_XXX). The BUFFER_CREATIONFLAG_STORAGE flag will be automatically added
1045
+ * @param label defines the label of the buffer (for debug purpose)
1046
+ * @returns the new buffer
1047
+ */
1048
+ createStorageBuffer(data: DataArray | number, creationFlags: number, label?: string): DataBuffer;
1049
+ /**
1050
+ * Updates a storage buffer
1051
+ * @param buffer the storage buffer to update
1052
+ * @param data the data used to update the storage buffer
1053
+ * @param byteOffset the byte offset of the data
1054
+ * @param byteLength the byte length of the data
1055
+ */
1056
+ updateStorageBuffer(buffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void;
1057
+ /**
1058
+ * Read data from a storage buffer
1059
+ * @param storageBuffer The storage buffer to read from
1060
+ * @param offset The offset in the storage buffer to start reading from (default: 0)
1061
+ * @param size The number of bytes to read from the storage buffer (default: capacity of the buffer)
1062
+ * @param buffer The buffer to write the data we have read from the storage buffer to (optional)
1063
+ * @param noDelay If true, a call to flushFramebuffer will be issued so that the data can be read back immediately and not in engine.onEndFrameObservable. This can speed up data retrieval, at the cost of a small perf penalty (default: false).
1064
+ * @returns If not undefined, returns the (promise) buffer (as provided by the 4th parameter) filled with the data, else it returns a (promise) Uint8Array with the data read from the storage buffer
1065
+ */
1066
+ readFromStorageBuffer(storageBuffer: DataBuffer, offset?: number, size?: number, buffer?: ArrayBufferView, noDelay?: boolean): Promise<ArrayBufferView>;
1067
+ /**
1068
+ * Sets a storage buffer in the shader
1069
+ * @param name Defines the name of the storage buffer as defined in the shader
1070
+ * @param buffer Defines the value to give to the uniform
1071
+ */
1072
+ setStorageBuffer(name: string, buffer: Nullable<StorageBuffer>): void;
1021
1073
  }
1022
1074
  export {};
@@ -49,6 +49,7 @@ import "./AbstractEngine/abstractEngine.states.js";
49
49
  import "./AbstractEngine/abstractEngine.renderPass.js";
50
50
  import "../Audio/audioEngine.js";
51
51
  import { resetCachedPipeline } from "../Materials/effect.functions.js";
52
+ import { WebGPUExternalTexture } from "./WebGPU/webgpuExternalTexture.js";
52
53
  const viewDescriptorSwapChainAntialiasing = {
53
54
  label: `TextureView_SwapChain_ResolveTarget`,
54
55
  dimension: WebGPUConstants.TextureDimension.E2d,
@@ -3055,6 +3056,152 @@ export class WebGPUEngine extends AbstractEngine {
3055
3056
  // TODO WEBGPU. from the webgpu errors.
3056
3057
  return 0;
3057
3058
  }
3059
+ //------------------------------------------------------------------------------
3060
+ // External Textures
3061
+ //------------------------------------------------------------------------------
3062
+ /**
3063
+ * Creates an external texture
3064
+ * @param video video element
3065
+ * @returns the external texture, or null if external textures are not supported by the engine
3066
+ */
3067
+ createExternalTexture(video) {
3068
+ const texture = new WebGPUExternalTexture(video);
3069
+ return texture;
3070
+ }
3071
+ /**
3072
+ * Sets an internal texture to the according uniform.
3073
+ * @param name The name of the uniform in the effect
3074
+ * @param texture The texture to apply
3075
+ */
3076
+ setExternalTexture(name, texture) {
3077
+ if (!texture) {
3078
+ this._currentMaterialContext.setTexture(name, null);
3079
+ return;
3080
+ }
3081
+ this._setInternalTexture(name, texture);
3082
+ }
3083
+ //------------------------------------------------------------------------------
3084
+ // Samplers
3085
+ //------------------------------------------------------------------------------
3086
+ /**
3087
+ * Sets a texture sampler to the according uniform.
3088
+ * @param name The name of the uniform in the effect
3089
+ * @param sampler The sampler to apply
3090
+ */
3091
+ setTextureSampler(name, sampler) {
3092
+ this._currentMaterialContext?.setSampler(name, sampler);
3093
+ }
3094
+ //------------------------------------------------------------------------------
3095
+ // Storage Buffers
3096
+ //------------------------------------------------------------------------------
3097
+ /**
3098
+ * Creates a storage buffer
3099
+ * @param data the data for the storage buffer or the size of the buffer
3100
+ * @param creationFlags flags to use when creating the buffer (see undefined). The BUFFER_CREATIONFLAG_STORAGE flag will be automatically added
3101
+ * @param label defines the label of the buffer (for debug purpose)
3102
+ * @returns the new buffer
3103
+ */
3104
+ createStorageBuffer(data, creationFlags, label) {
3105
+ return this._createBuffer(data, creationFlags | 32, label);
3106
+ }
3107
+ /**
3108
+ * Updates a storage buffer
3109
+ * @param buffer the storage buffer to update
3110
+ * @param data the data used to update the storage buffer
3111
+ * @param byteOffset the byte offset of the data
3112
+ * @param byteLength the byte length of the data
3113
+ */
3114
+ updateStorageBuffer(buffer, data, byteOffset, byteLength) {
3115
+ const dataBuffer = buffer;
3116
+ if (byteOffset === undefined) {
3117
+ byteOffset = 0;
3118
+ }
3119
+ let view;
3120
+ if (byteLength === undefined) {
3121
+ if (data instanceof Array) {
3122
+ view = new Float32Array(data);
3123
+ }
3124
+ else if (data instanceof ArrayBuffer) {
3125
+ view = new Uint8Array(data);
3126
+ }
3127
+ else {
3128
+ view = data;
3129
+ }
3130
+ byteLength = view.byteLength;
3131
+ }
3132
+ else {
3133
+ if (data instanceof Array) {
3134
+ view = new Float32Array(data);
3135
+ }
3136
+ else if (data instanceof ArrayBuffer) {
3137
+ view = new Uint8Array(data);
3138
+ }
3139
+ else {
3140
+ view = data;
3141
+ }
3142
+ }
3143
+ this._bufferManager.setSubData(dataBuffer, byteOffset, view, 0, byteLength);
3144
+ }
3145
+ /**
3146
+ * Read data from a storage buffer
3147
+ * @param storageBuffer The storage buffer to read from
3148
+ * @param offset The offset in the storage buffer to start reading from (default: 0)
3149
+ * @param size The number of bytes to read from the storage buffer (default: capacity of the buffer)
3150
+ * @param buffer The buffer to write the data we have read from the storage buffer to (optional)
3151
+ * @param noDelay If true, a call to flushFramebuffer will be issued so that the data can be read back immediately and not in engine.onEndFrameObservable. This can speed up data retrieval, at the cost of a small perf penalty (default: false).
3152
+ * @returns If not undefined, returns the (promise) buffer (as provided by the 4th parameter) filled with the data, else it returns a (promise) Uint8Array with the data read from the storage buffer
3153
+ */
3154
+ readFromStorageBuffer(storageBuffer, offset, size, buffer, noDelay) {
3155
+ size = size || storageBuffer.capacity;
3156
+ const gpuBuffer = this._bufferManager.createRawBuffer(size, WebGPUConstants.BufferUsage.MapRead | WebGPUConstants.BufferUsage.CopyDst, undefined, "TempReadFromStorageBuffer");
3157
+ this._renderEncoder.copyBufferToBuffer(storageBuffer.underlyingResource, offset ?? 0, gpuBuffer, 0, size);
3158
+ return new Promise((resolve, reject) => {
3159
+ const readFromBuffer = () => {
3160
+ gpuBuffer.mapAsync(WebGPUConstants.MapMode.Read, 0, size).then(() => {
3161
+ const copyArrayBuffer = gpuBuffer.getMappedRange(0, size);
3162
+ let data = buffer;
3163
+ if (data === undefined) {
3164
+ data = new Uint8Array(size);
3165
+ data.set(new Uint8Array(copyArrayBuffer));
3166
+ }
3167
+ else {
3168
+ const ctor = data.constructor; // we want to create result data with the same type as buffer (Uint8Array, Float32Array, ...)
3169
+ data = new ctor(data.buffer);
3170
+ data.set(new ctor(copyArrayBuffer));
3171
+ }
3172
+ gpuBuffer.unmap();
3173
+ this._bufferManager.releaseBuffer(gpuBuffer);
3174
+ resolve(data);
3175
+ }, (reason) => {
3176
+ if (this.isDisposed) {
3177
+ resolve(new Uint8Array());
3178
+ }
3179
+ else {
3180
+ reject(reason);
3181
+ }
3182
+ });
3183
+ };
3184
+ if (noDelay) {
3185
+ this.flushFramebuffer();
3186
+ readFromBuffer();
3187
+ }
3188
+ else {
3189
+ // we are using onEndFrameObservable because we need to map the gpuBuffer AFTER the command buffers
3190
+ // have been submitted, else we get the error: "Buffer used in a submit while mapped"
3191
+ this.onEndFrameObservable.addOnce(() => {
3192
+ readFromBuffer();
3193
+ });
3194
+ }
3195
+ });
3196
+ }
3197
+ /**
3198
+ * Sets a storage buffer in the shader
3199
+ * @param name Defines the name of the storage buffer as defined in the shader
3200
+ * @param buffer Defines the value to give to the uniform
3201
+ */
3202
+ setStorageBuffer(name, buffer) {
3203
+ this._currentDrawContext?.setBuffer(name, buffer?.getBuffer() ?? null);
3204
+ }
3058
3205
  }
3059
3206
  // Default glslang options.
3060
3207
  WebGPUEngine._GLSLslangDefaultOptions = {