@babylonjs/core 8.18.0 → 8.19.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 (100) hide show
  1. package/Collisions/intersectionInfo.d.ts +1 -0
  2. package/Collisions/intersectionInfo.js +1 -0
  3. package/Collisions/intersectionInfo.js.map +1 -1
  4. package/Compute/computeShader.d.ts +7 -0
  5. package/Compute/computeShader.js +15 -0
  6. package/Compute/computeShader.js.map +1 -1
  7. package/Engines/Extensions/engine.computeShader.d.ts +2 -1
  8. package/Engines/Extensions/engine.computeShader.js +1 -0
  9. package/Engines/Extensions/engine.computeShader.js.map +1 -1
  10. package/Engines/IDrawContext.d.ts +31 -1
  11. package/Engines/IDrawContext.js.map +1 -1
  12. package/Engines/IMaterialContext.d.ts +1 -0
  13. package/Engines/IMaterialContext.js.map +1 -1
  14. package/Engines/WebGPU/webgpuCacheRenderPipeline.d.ts +1 -1
  15. package/Engines/WebGPU/webgpuCacheRenderPipeline.js +2 -2
  16. package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
  17. package/Engines/WebGPU/webgpuComputeContext.js +15 -0
  18. package/Engines/WebGPU/webgpuComputeContext.js.map +1 -1
  19. package/Engines/WebGPU/webgpuDrawContext.d.ts +48 -3
  20. package/Engines/WebGPU/webgpuDrawContext.js +81 -13
  21. package/Engines/WebGPU/webgpuDrawContext.js.map +1 -1
  22. package/Engines/WebGPU/webgpuMaterialContext.d.ts +1 -0
  23. package/Engines/WebGPU/webgpuMaterialContext.js +1 -0
  24. package/Engines/WebGPU/webgpuMaterialContext.js.map +1 -1
  25. package/Engines/WebGPU/webgpuStencilStateComposer.js +7 -3
  26. package/Engines/WebGPU/webgpuStencilStateComposer.js.map +1 -1
  27. package/Engines/abstractEngine.d.ts +4 -1
  28. package/Engines/abstractEngine.js +2 -2
  29. package/Engines/abstractEngine.js.map +1 -1
  30. package/Engines/engine.d.ts +2 -2
  31. package/Engines/nativeEngine.d.ts +1 -1
  32. package/Engines/nativeEngine.js +2 -2
  33. package/Engines/nativeEngine.js.map +1 -1
  34. package/Engines/renderTargetWrapper.d.ts +8 -0
  35. package/Engines/renderTargetWrapper.js +8 -0
  36. package/Engines/renderTargetWrapper.js.map +1 -1
  37. package/Engines/thinEngine.d.ts +2 -3
  38. package/Engines/thinEngine.js +3 -2
  39. package/Engines/thinEngine.js.map +1 -1
  40. package/Engines/webgpuEngine.d.ts +7 -4
  41. package/Engines/webgpuEngine.js +28 -15
  42. package/Engines/webgpuEngine.js.map +1 -1
  43. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.d.ts +1 -1
  44. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js.map +1 -1
  45. package/FrameGraph/Passes/renderPass.d.ts +8 -0
  46. package/FrameGraph/Passes/renderPass.js +10 -1
  47. package/FrameGraph/Passes/renderPass.js.map +1 -1
  48. package/FrameGraph/Tasks/PostProcesses/postProcessTask.d.ts +46 -2
  49. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js +62 -15
  50. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js.map +1 -1
  51. package/FrameGraph/Tasks/Texture/clearTextureTask.d.ts +4 -0
  52. package/FrameGraph/Tasks/Texture/clearTextureTask.js +5 -1
  53. package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
  54. package/FrameGraph/frameGraphRenderContext.d.ts +14 -5
  55. package/FrameGraph/frameGraphRenderContext.js +34 -14
  56. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  57. package/FrameGraph/frameGraphTextureManager.d.ts +3 -1
  58. package/FrameGraph/frameGraphTextureManager.js +16 -10
  59. package/FrameGraph/frameGraphTextureManager.js.map +1 -1
  60. package/Materials/Node/Blocks/PBR/reflectionBlock.d.ts +1 -0
  61. package/Materials/Node/Blocks/PBR/reflectionBlock.js +4 -1
  62. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  63. package/Materials/Node/nodeMaterial.js +7 -0
  64. package/Materials/Node/nodeMaterial.js.map +1 -1
  65. package/Materials/PBR/pbrBaseMaterial.d.ts +1 -0
  66. package/Materials/PBR/pbrBaseMaterial.js +8 -6
  67. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  68. package/Materials/drawWrapper.d.ts +34 -2
  69. package/Materials/drawWrapper.js +22 -2
  70. package/Materials/drawWrapper.js.map +1 -1
  71. package/Materials/effectRenderer.d.ts +4 -0
  72. package/Materials/effectRenderer.js +2 -1
  73. package/Materials/effectRenderer.js.map +1 -1
  74. package/Materials/index.d.ts +1 -0
  75. package/Materials/index.js +1 -0
  76. package/Materials/index.js.map +1 -1
  77. package/Materials/material.d.ts +8 -1
  78. package/Materials/material.js +21 -1
  79. package/Materials/material.js.map +1 -1
  80. package/Materials/materialHelper.functions.d.ts +3 -1
  81. package/Materials/materialHelper.functions.js +7 -1
  82. package/Materials/materialHelper.functions.js.map +1 -1
  83. package/Materials/shaderMaterial.js +11 -0
  84. package/Materials/shaderMaterial.js.map +1 -1
  85. package/Materials/standardMaterial.d.ts +1 -0
  86. package/Materials/standardMaterial.js +2 -1
  87. package/Materials/standardMaterial.js.map +1 -1
  88. package/Materials/uniformBuffer.d.ts +6 -0
  89. package/Materials/uniformBuffer.js +8 -0
  90. package/Materials/uniformBuffer.js.map +1 -1
  91. package/Meshes/abstractMesh.js +3 -2
  92. package/Meshes/abstractMesh.js.map +1 -1
  93. package/Meshes/mesh.js +6 -0
  94. package/Meshes/mesh.js.map +1 -1
  95. package/Misc/fileTools.js +1 -1
  96. package/Misc/fileTools.js.map +1 -1
  97. package/States/index.d.ts +1 -0
  98. package/States/index.js +1 -0
  99. package/States/index.js.map +1 -1
  100. package/package.json +1 -1
@@ -8,5 +8,6 @@ export declare class IntersectionInfo {
8
8
  distance: number;
9
9
  faceId: number;
10
10
  subMeshId: number;
11
+ _internalSubMeshId: number;
11
12
  constructor(bu: Nullable<number>, bv: Nullable<number>, distance: number);
12
13
  }
@@ -8,6 +8,7 @@ export class IntersectionInfo {
8
8
  this.distance = distance;
9
9
  this.faceId = 0;
10
10
  this.subMeshId = 0;
11
+ this._internalSubMeshId = 0;
11
12
  }
12
13
  }
13
14
  //# sourceMappingURL=intersectionInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"intersectionInfo.js","sourceRoot":"","sources":["../../../../dev/core/src/Collisions/intersectionInfo.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAIzB,YACW,EAAoB,EACpB,EAAoB,EACpB,QAAgB;QAFhB,OAAE,GAAF,EAAE,CAAkB;QACpB,OAAE,GAAF,EAAE,CAAkB;QACpB,aAAQ,GAAR,QAAQ,CAAQ;QANpB,WAAM,GAAG,CAAC,CAAC;QACX,cAAS,GAAG,CAAC,CAAC;IAMlB,CAAC;CACP","sourcesContent":["import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class IntersectionInfo {\r\n public faceId = 0;\r\n public subMeshId = 0;\r\n\r\n constructor(\r\n public bu: Nullable<number>,\r\n public bv: Nullable<number>,\r\n public distance: number\r\n ) {}\r\n}\r\n"]}
1
+ {"version":3,"file":"intersectionInfo.js","sourceRoot":"","sources":["../../../../dev/core/src/Collisions/intersectionInfo.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAKzB,YACW,EAAoB,EACpB,EAAoB,EACpB,QAAgB;QAFhB,OAAE,GAAF,EAAE,CAAkB;QACpB,OAAE,GAAF,EAAE,CAAkB;QACpB,aAAQ,GAAR,QAAQ,CAAQ;QAPpB,WAAM,GAAG,CAAC,CAAC;QACX,cAAS,GAAG,CAAC,CAAC;QACd,uBAAkB,GAAG,CAAC,CAAC;IAM3B,CAAC;CACP","sourcesContent":["import type { Nullable } from \"../types\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class IntersectionInfo {\r\n public faceId = 0;\r\n public subMeshId = 0;\r\n public _internalSubMeshId = 0;\r\n\r\n constructor(\r\n public bu: Nullable<number>,\r\n public bv: Nullable<number>,\r\n public distance: number\r\n ) {}\r\n}\r\n"]}
@@ -11,6 +11,7 @@ import type { ExternalTexture } from "../Materials/Textures/externalTexture.js";
11
11
  import type { VideoTexture } from "../Materials/Textures/videoTexture.js";
12
12
  import { WebGPUPerfCounter } from "../Engines/WebGPU/webgpuPerfCounter.js";
13
13
  import type { AbstractEngine } from "../Engines/abstractEngine.js";
14
+ import type { InternalTexture } from "../Materials/Textures/internalTexture.js";
14
15
  /**
15
16
  * Defines the options associated with the creation of a compute shader.
16
17
  */
@@ -106,6 +107,12 @@ export declare class ComputeShader {
106
107
  * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture
107
108
  */
108
109
  setTexture(name: string, texture: BaseTexture, bindSampler?: boolean): void;
110
+ /**
111
+ * Binds an internal texture to the shader
112
+ * @param name Binding name of the texture
113
+ * @param texture Texture to bind
114
+ */
115
+ setInternalTexture(name: string, texture: InternalTexture): void;
109
116
  /**
110
117
  * Binds a storage texture to the shader
111
118
  * @param name Binding name of the texture
@@ -97,6 +97,20 @@ export class ComputeShader {
97
97
  };
98
98
  this._contextIsDirty || (this._contextIsDirty = !current || current.object !== texture || current.type !== this._bindings[name].type);
99
99
  }
100
+ /**
101
+ * Binds an internal texture to the shader
102
+ * @param name Binding name of the texture
103
+ * @param texture Texture to bind
104
+ */
105
+ setInternalTexture(name, texture) {
106
+ const current = this._bindings[name];
107
+ this._bindings[name] = {
108
+ type: 8 /* ComputeBindingType.InternalTexture */,
109
+ object: texture,
110
+ indexInGroupEntries: current?.indexInGroupEntries,
111
+ };
112
+ this._contextIsDirty || (this._contextIsDirty = !current || current.object !== texture || current.type !== this._bindings[name].type);
113
+ }
100
114
  /**
101
115
  * Binds a storage texture to the shader
102
116
  * @param name Binding name of the texture
@@ -340,6 +354,7 @@ export class ComputeShader {
340
354
  }
341
355
  break;
342
356
  }
357
+ case 8 /* ComputeBindingType.InternalTexture */:
343
358
  case 2 /* ComputeBindingType.UniformBuffer */: {
344
359
  break;
345
360
  }
@@ -1 +1 @@
1
- {"version":3,"file":"computeShader.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/computeShader.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKlD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAItE,OAAO,EAAE,iBAAiB,EAAE,+CAA8C;AAE1E,OAAO,EAAE,kBAAkB,EAAE,+BAA8B;AA+B3D;;GAEG;AACH,MAAM,OAAO,aAAa;IAsBtB;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAyBD;;;;;;;;;;OAUG;IACH,YAAY,IAAY,EAAE,MAAsB,EAAE,UAAuC,EAAE,UAA0C,EAAE;QAhE/H,cAAS,GAA+B,EAAE,CAAC;QAC3C,cAAS,GAAsC,EAAE,CAAC;QAElD,oBAAe,GAAG,KAAK,CAAC;QA2BhC;;;WAGG;QAEI,aAAQ,GAAG,KAAK,CAAC;QAExB;;WAEG;QACI,eAAU,GAA8C,IAAI,CAAC;QAEpE;;WAEG;QACI,YAAO,GAA8D,IAAI,CAAC;QAoB7E,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,iBAAiB,C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CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAE7E,IAAI,OAAO,CAAC,IAAI,uCAA+B,EAAE,CAAC;gBAC9C,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACrC,CAAC;iBAAM,IAAI,OAAO,CAAC,IAAI,qDAA6C,EAAE,CAAC;gBACnE,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;IAES,MAAM,CAAC,mBAAmB,CAAC,MAAkD;QACnF,OAAQ,MAAqB,CAAC,kBAAkB,KAAK,SAAS,CAAC;IACnE,CAAC;CACJ;AAzbU;IADN,SAAS,EAAE;2CACQ;AAqBb;IADN,SAAS,EAAE;+CACY;AAsa5B,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { WebGPUEngine } from \"../Engines/webgpuEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { serialize } from \"../Misc/decorators\";\r\nimport { SerializationHelper } from \"../Misc/decorators.serialization\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\nimport type { ExternalTexture } from \"core/Materials/Textures/externalTexture\";\r\nimport type { VideoTexture } from \"core/Materials/Textures/videoTexture\";\r\nimport { WebGPUPerfCounter } from \"core/Engines/WebGPU/webgpuPerfCounter\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport { _RetryWithInterval } from \"core/Misc/timingTools\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: AbstractEngine;\r\n private _shaderPath: IComputeShaderPath | string;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * When set to true, dispatch won't call isReady anymore and won't check if the underlying GPU resources should be (re)created because of a change in the inputs (texture, uniform buffer, etc.)\r\n * If you know that your inputs did not change since last time dispatch was called and that isReady() returns true, set this flag to true to improve performance\r\n */\r\n @serialize()\r\n public fastMode = false;\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Gets the GPU time spent running the compute shader for the last frame rendered (in nanoseconds).\r\n * You have to enable the \"timestamp-query\" extension in the engine constructor options and set engine.enableGPUTimingMeasurements = true.\r\n */\r\n public readonly gpuTimeInFrame?: WebGPUPerfCounter;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: AbstractEngine, shaderPath: IComputeShaderPath | string, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n if ((engine as WebGPUEngine).enableGPUTimingMeasurements) {\r\n this.gpuTimeInFrame = new WebGPUPerfCounter();\r\n }\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds an external texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setExternalTexture(name: string, texture: ExternalTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.ExternalTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a video texture to the shader (by binding the external texture attached to this video)\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @returns true if the video texture was successfully bound, else false. false will be returned if the current engine does not support external textures\r\n */\r\n public setVideoTexture(name: string, texture: VideoTexture) {\r\n if (texture.externalTexture) {\r\n this.setExternalTexture(name, texture.externalTexture);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n const texture = object as ExternalTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.fastMode && !this._checkContext()) {\r\n return false;\r\n }\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping, this.gpuTimeInFrame);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader.\r\n * @param buffer Buffer containing the number of workgroups to execute on the X, Y and Z dimensions\r\n * @param offset Offset in the buffer where the workgroup counts are stored (default: 0)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatchIndirect(buffer: StorageBuffer | DataBuffer, offset: number = 0): boolean {\r\n if (!this.fastMode && !this._checkContext()) {\r\n return false;\r\n }\r\n const dataBuffer = ComputeShader._BufferIsDataBuffer(buffer) ? buffer : buffer.getBuffer();\r\n this._engine.computeDispatchIndirect(this._effect, this._context, this._bindings, dataBuffer, offset, this._options.bindingsMapping, this.gpuTimeInFrame);\r\n return true;\r\n }\r\n\r\n private _checkContext(): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n // we must recreate the bind groups each time if there's an external texture, because device.importExternalTexture must be called each frame\r\n this._contextIsDirty = true;\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public async dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return await new Promise((resolve) => {\r\n _RetryWithInterval(() => this.dispatch(x, y, z), resolve, undefined, delay);\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(\r\n () => new ComputeShader(source.name, scene.getEngine() as WebGPUEngine, source.shaderPath, source.options),\r\n source,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n\r\n protected static _BufferIsDataBuffer(buffer: UniformBuffer | StorageBuffer | DataBuffer): buffer is DataBuffer {\r\n return (buffer as DataBuffer).underlyingResource !== undefined;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
1
+ {"version":3,"file":"computeShader.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/computeShader.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAKlD,OAAO,EAAE,OAAO,EAAE,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AK,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACrC,MAAM,OAAO,GAAY,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAE7E,IAAI,OAAO,CAAC,IAAI,uCAA+B,EAAE,CAAC;gBAC9C,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACrC,CAAC;iBAAM,IAAI,OAAO,CAAC,IAAI,qDAA6C,EAAE,CAAC;gBACnE,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;IAES,MAAM,CAAC,mBAAmB,CAAC,MAAkD;QACnF,OAAQ,MAAqB,CAAC,kBAAkB,KAAK,SAAS,CAAC;IACnE,CAAC;CACJ;AA3cU;IADN,SAAS,EAAE;2CACQ;AAqBb;IADN,SAAS,EAAE;+CACY;AAwb5B,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { WebGPUEngine } from \"../Engines/webgpuEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { serialize } from \"../Misc/decorators\";\r\nimport { SerializationHelper } from \"../Misc/decorators.serialization\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\nimport type { ExternalTexture } from \"core/Materials/Textures/externalTexture\";\r\nimport type { VideoTexture } from \"core/Materials/Textures/videoTexture\";\r\nimport { WebGPUPerfCounter } from \"core/Engines/WebGPU/webgpuPerfCounter\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport { _RetryWithInterval } from \"core/Misc/timingTools\";\r\nimport type { InternalTexture } from \"core/Materials/Textures/internalTexture\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: AbstractEngine;\r\n private _shaderPath: IComputeShaderPath | string;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * When set to true, dispatch won't call isReady anymore and won't check if the underlying GPU resources should be (re)created because of a change in the inputs (texture, uniform buffer, etc.)\r\n * If you know that your inputs did not change since last time dispatch was called and that isReady() returns true, set this flag to true to improve performance\r\n */\r\n @serialize()\r\n public fastMode = false;\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Gets the GPU time spent running the compute shader for the last frame rendered (in nanoseconds).\r\n * You have to enable the \"timestamp-query\" extension in the engine constructor options and set engine.enableGPUTimingMeasurements = true.\r\n */\r\n public readonly gpuTimeInFrame?: WebGPUPerfCounter;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: AbstractEngine, shaderPath: IComputeShaderPath | string, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n if ((engine as WebGPUEngine).enableGPUTimingMeasurements) {\r\n this.gpuTimeInFrame = new WebGPUPerfCounter();\r\n }\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds an internal texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setInternalTexture(name: string, texture: InternalTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.InternalTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds an external texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setExternalTexture(name: string, texture: ExternalTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.ExternalTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a video texture to the shader (by binding the external texture attached to this video)\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @returns true if the video texture was successfully bound, else false. false will be returned if the current engine does not support external textures\r\n */\r\n public setVideoTexture(name: string, texture: VideoTexture) {\r\n if (texture.externalTexture) {\r\n this.setExternalTexture(name, texture.externalTexture);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer | DataBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeShader._BufferIsDataBuffer(buffer) ? ComputeBindingType.DataBuffer : ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n const texture = object as ExternalTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.fastMode && !this._checkContext()) {\r\n return false;\r\n }\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping, this.gpuTimeInFrame);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader.\r\n * @param buffer Buffer containing the number of workgroups to execute on the X, Y and Z dimensions\r\n * @param offset Offset in the buffer where the workgroup counts are stored (default: 0)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatchIndirect(buffer: StorageBuffer | DataBuffer, offset: number = 0): boolean {\r\n if (!this.fastMode && !this._checkContext()) {\r\n return false;\r\n }\r\n const dataBuffer = ComputeShader._BufferIsDataBuffer(buffer) ? buffer : buffer.getBuffer();\r\n this._engine.computeDispatchIndirect(this._effect, this._context, this._bindings, dataBuffer, offset, this._options.bindingsMapping, this.gpuTimeInFrame);\r\n return true;\r\n }\r\n\r\n private _checkContext(): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.ExternalTexture: {\r\n // we must recreate the bind groups each time if there's an external texture, because device.importExternalTexture must be called each frame\r\n this._contextIsDirty = true;\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public async dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return await new Promise((resolve) => {\r\n _RetryWithInterval(() => this.dispatch(x, y, z), resolve, undefined, delay);\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.InternalTexture:\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(\r\n () => new ComputeShader(source.name, scene.getEngine() as WebGPUEngine, source.shaderPath, source.options),\r\n source,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n\r\n protected static _BufferIsDataBuffer(buffer: UniformBuffer | StorageBuffer | DataBuffer): buffer is DataBuffer {\r\n return (buffer as DataBuffer).underlyingResource !== undefined;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
@@ -52,7 +52,8 @@ export declare enum ComputeBindingType {
52
52
  TextureWithoutSampler = 4,
53
53
  Sampler = 5,
54
54
  ExternalTexture = 6,
55
- DataBuffer = 7
55
+ DataBuffer = 7,
56
+ InternalTexture = 8
56
57
  }
57
58
  /** @internal */
58
59
  export type ComputeBindingList = {
@@ -11,6 +11,7 @@ export var ComputeBindingType;
11
11
  ComputeBindingType[ComputeBindingType["Sampler"] = 5] = "Sampler";
12
12
  ComputeBindingType[ComputeBindingType["ExternalTexture"] = 6] = "ExternalTexture";
13
13
  ComputeBindingType[ComputeBindingType["DataBuffer"] = 7] = "DataBuffer";
14
+ ComputeBindingType[ComputeBindingType["InternalTexture"] = 8] = "InternalTexture";
14
15
  })(ComputeBindingType || (ComputeBindingType = {}));
15
16
  ThinEngine.prototype.createComputeEffect = function (baseName, options) {
16
17
  throw new Error("createComputeEffect: This engine does not support compute shaders!");
@@ -1 +1 @@
1
- {"version":3,"file":"engine.computeShader.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Extensions/engine.computeShader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA2CnD,gBAAgB;AAChB,MAAM,CAAN,IAAkB,kBASjB;AATD,WAAkB,kBAAkB;IAChC,iEAAW,CAAA;IACX,+EAAkB,CAAA;IAClB,6EAAiB,CAAA;IACjB,6EAAiB,CAAA;IACjB,6FAAyB,CAAA;IACzB,iEAAW,CAAA;IACX,iFAAmB,CAAA;IACnB,uEAAc,CAAA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AC,CAAC;AACjB,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,qBAAqB,GAAG,UAAU,MAAqB,IAAS,CAAC,CAAC;AAEvF,UAAU,CAAC,SAAS,CAAC,6BAA6B,GAAG,UAAU,eAAwC,IAAS,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from \"../../Compute/computeEffect\";\r\nimport type { IComputeContext } from \"../../Compute/IComputeContext\";\r\nimport type { IComputePipelineContext } from \"../../Compute/IComputePipelineContext\";\r\nimport { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { AbstractEngine } from \"../abstractEngine\";\r\nimport type { WebGPUPerfCounter } from \"../WebGPU/webgpuPerfCounter\";\r\nimport type { DataBuffer } from \"../../Buffers/dataBuffer\";\r\n\r\n/**\r\n * Type used to locate a resource in a compute shader.\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingLocation = { group: number; binding: number };\r\n\r\n/**\r\n * Type used to lookup a resource and retrieve its binding location\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingMapping = { [key: string]: ComputeBindingLocation };\r\n\r\n/**\r\n * Types of messages that can be generated during compilation\r\n */\r\nexport type ComputeCompilationMessageType = \"error\" | \"warning\" | \"info\";\r\n\r\n/**\r\n * Messages generated during compilation\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface ComputeCompilationMessages {\r\n /**\r\n * Number of errors generated during compilation\r\n */\r\n numErrors: number;\r\n /**\r\n * List of messages generated during compilation\r\n */\r\n messages: {\r\n type: ComputeCompilationMessageType;\r\n text: string;\r\n line?: number;\r\n column?: number;\r\n length?: number;\r\n offset?: number;\r\n }[];\r\n}\r\n\r\n/** @internal */\r\nexport const enum ComputeBindingType {\r\n Texture = 0,\r\n StorageTexture = 1,\r\n UniformBuffer = 2,\r\n StorageBuffer = 3,\r\n TextureWithoutSampler = 4,\r\n Sampler = 5,\r\n ExternalTexture = 6,\r\n DataBuffer = 7,\r\n}\r\n\r\n/** @internal */\r\nexport type ComputeBindingList = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number } };\r\n\r\ndeclare module \"../../Engines/abstractEngine\" {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n export interface AbstractEngine {\r\n /**\r\n * Creates a new compute effect\r\n * @param baseName Name of the effect\r\n * @param options Options used to create the effect\r\n * @returns The new compute effect\r\n */\r\n createComputeEffect(\r\n baseName:\r\n | string\r\n | (IComputeShaderPath & {\r\n /**\r\n * @internal\r\n */\r\n computeToken?: string;\r\n }),\r\n options: IComputeEffectCreationOptions\r\n ): ComputeEffect;\r\n\r\n /**\r\n * Creates a new compute pipeline context\r\n * @returns the new pipeline\r\n */\r\n createComputePipelineContext(): IComputePipelineContext;\r\n\r\n /**\r\n * Creates a new compute context\r\n * @returns the new context\r\n */\r\n createComputeContext(): IComputeContext | undefined;\r\n\r\n /**\r\n * Dispatches a compute shader\r\n * @param effect The compute effect\r\n * @param context The compute context\r\n * @param bindings The list of resources to bind to the shader\r\n * @param x The number of workgroups to execute on the X dimension\r\n * @param y The number of workgroups to execute on the Y dimension\r\n * @param z The number of workgroups to execute on the Z dimension\r\n * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)\r\n * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object\r\n */\r\n computeDispatch(\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping,\r\n gpuPerfCounter?: WebGPUPerfCounter\r\n ): void;\r\n\r\n /**\r\n * Dispatches a compute shader\r\n * @param effect The compute effect\r\n * @param context The compute context\r\n * @param bindings The list of resources to bind to the shader\r\n * @param x The number of workgroups to execute on the X dimension\r\n * @param y The number of workgroups to execute on the Y dimension\r\n * @param z The number of workgroups to execute on the Z dimension\r\n * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)\r\n * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object\r\n */\r\n computeDispatchIndirect(\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n buffer: DataBuffer,\r\n offset?: number,\r\n bindingsMapping?: ComputeBindingMapping,\r\n gpuPerfCounter?: WebGPUPerfCounter\r\n ): void;\r\n\r\n /**\r\n * Gets a boolean indicating if all created compute effects are ready\r\n * @returns true if all effects are ready\r\n */\r\n areAllComputeEffectsReady(): boolean;\r\n\r\n /**\r\n * Forces the engine to release all cached compute effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled\r\n */\r\n releaseComputeEffects(): void;\r\n\r\n /** @internal */\r\n _prepareComputePipelineContext(\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n ): void;\r\n\r\n /** @internal */\r\n _rebuildComputeEffects(): void;\r\n\r\n /** @internal */\r\n _executeWhenComputeStateIsCompiled(pipelineContext: IComputePipelineContext, action: (messages: Nullable<ComputeCompilationMessages>) => void): void;\r\n\r\n /** @internal */\r\n _releaseComputeEffect(effect: ComputeEffect): void;\r\n\r\n /** @internal */\r\n _deleteComputePipelineContext(pipelineContext: IComputePipelineContext): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.createComputeEffect = function (baseName: IComputeShaderPath & { computeToken?: string }, options: IComputeEffectCreationOptions): ComputeEffect {\r\n throw new Error(\"createComputeEffect: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputePipelineContext = function (): IComputePipelineContext {\r\n throw new Error(\"createComputePipelineContext: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputeContext = function (): IComputeContext | undefined {\r\n return undefined;\r\n};\r\n\r\nThinEngine.prototype.computeDispatch = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n throw new Error(\"computeDispatch: This engine does not support compute shaders!\");\r\n};\r\nThinEngine.prototype.computeDispatchIndirect = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n buffer: DataBuffer,\r\n offset?: number,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n throw new Error(\"computeDispatchIndirect: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.areAllComputeEffectsReady = function (): boolean {\r\n return true;\r\n};\r\n\r\nThinEngine.prototype.releaseComputeEffects = function (): void {};\r\n\r\nThinEngine.prototype._prepareComputePipelineContext = function (\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n): void {};\r\n\r\nThinEngine.prototype._rebuildComputeEffects = function (): void {};\r\n\r\nAbstractEngine.prototype._executeWhenComputeStateIsCompiled = function (\r\n pipelineContext: IComputePipelineContext,\r\n action: (messages: Nullable<ComputeCompilationMessages>) => void\r\n): void {\r\n action(null);\r\n};\r\n\r\nThinEngine.prototype._releaseComputeEffect = function (effect: ComputeEffect): void {};\r\n\r\nThinEngine.prototype._deleteComputePipelineContext = function (pipelineContext: IComputePipelineContext): void {};\r\n"]}
1
+ {"version":3,"file":"engine.computeShader.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Extensions/engine.computeShader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AA2CnD,gBAAgB;AAChB,MAAM,CAAN,IAAkB,kBAUjB;AAVD,WAAkB,kBAAkB;IAChC,iEAAW,CAAA;IACX,+EAAkB,CAAA;IAClB,6EAAiB,CAAA;I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mB,CAAC,CAAC;AAEnE,cAAc,CAAC,SAAS,CAAC,kCAAkC,GAAG,UAC1D,eAAwC,EACxC,MAAgE;IAEhE,MAAM,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC,CAAC;AAEF,UAAU,CAAC,SAAS,CAAC,qBAAqB,GAAG,UAAU,MAAqB,IAAS,CAAC,CAAC;AAEvF,UAAU,CAAC,SAAS,CAAC,6BAA6B,GAAG,UAAU,eAAwC,IAAS,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\r\nimport type { ComputeEffect, IComputeEffectCreationOptions, IComputeShaderPath } from \"../../Compute/computeEffect\";\r\nimport type { IComputeContext } from \"../../Compute/IComputeContext\";\r\nimport type { IComputePipelineContext } from \"../../Compute/IComputePipelineContext\";\r\nimport { ThinEngine } from \"../../Engines/thinEngine\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { AbstractEngine } from \"../abstractEngine\";\r\nimport type { WebGPUPerfCounter } from \"../WebGPU/webgpuPerfCounter\";\r\nimport type { DataBuffer } from \"../../Buffers/dataBuffer\";\r\n\r\n/**\r\n * Type used to locate a resource in a compute shader.\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingLocation = { group: number; binding: number };\r\n\r\n/**\r\n * Type used to lookup a resource and retrieve its binding location\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\nexport type ComputeBindingMapping = { [key: string]: ComputeBindingLocation };\r\n\r\n/**\r\n * Types of messages that can be generated during compilation\r\n */\r\nexport type ComputeCompilationMessageType = \"error\" | \"warning\" | \"info\";\r\n\r\n/**\r\n * Messages generated during compilation\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport interface ComputeCompilationMessages {\r\n /**\r\n * Number of errors generated during compilation\r\n */\r\n numErrors: number;\r\n /**\r\n * List of messages generated during compilation\r\n */\r\n messages: {\r\n type: ComputeCompilationMessageType;\r\n text: string;\r\n line?: number;\r\n column?: number;\r\n length?: number;\r\n offset?: number;\r\n }[];\r\n}\r\n\r\n/** @internal */\r\nexport const enum ComputeBindingType {\r\n Texture = 0,\r\n StorageTexture = 1,\r\n UniformBuffer = 2,\r\n StorageBuffer = 3,\r\n TextureWithoutSampler = 4,\r\n Sampler = 5,\r\n ExternalTexture = 6,\r\n DataBuffer = 7,\r\n InternalTexture = 8,\r\n}\r\n\r\n/** @internal */\r\nexport type ComputeBindingList = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number } };\r\n\r\ndeclare module \"../../Engines/abstractEngine\" {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n export interface AbstractEngine {\r\n /**\r\n * Creates a new compute effect\r\n * @param baseName Name of the effect\r\n * @param options Options used to create the effect\r\n * @returns The new compute effect\r\n */\r\n createComputeEffect(\r\n baseName:\r\n | string\r\n | (IComputeShaderPath & {\r\n /**\r\n * @internal\r\n */\r\n computeToken?: string;\r\n }),\r\n options: IComputeEffectCreationOptions\r\n ): ComputeEffect;\r\n\r\n /**\r\n * Creates a new compute pipeline context\r\n * @returns the new pipeline\r\n */\r\n createComputePipelineContext(): IComputePipelineContext;\r\n\r\n /**\r\n * Creates a new compute context\r\n * @returns the new context\r\n */\r\n createComputeContext(): IComputeContext | undefined;\r\n\r\n /**\r\n * Dispatches a compute shader\r\n * @param effect The compute effect\r\n * @param context The compute context\r\n * @param bindings The list of resources to bind to the shader\r\n * @param x The number of workgroups to execute on the X dimension\r\n * @param y The number of workgroups to execute on the Y dimension\r\n * @param z The number of workgroups to execute on the Z dimension\r\n * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)\r\n * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object\r\n */\r\n computeDispatch(\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping,\r\n gpuPerfCounter?: WebGPUPerfCounter\r\n ): void;\r\n\r\n /**\r\n * Dispatches a compute shader\r\n * @param effect The compute effect\r\n * @param context The compute context\r\n * @param bindings The list of resources to bind to the shader\r\n * @param x The number of workgroups to execute on the X dimension\r\n * @param y The number of workgroups to execute on the Y dimension\r\n * @param z The number of workgroups to execute on the Z dimension\r\n * @param bindingsMapping list of bindings mapping (key is property name, value is binding location)\r\n * @param gpuPerfCounter GPU time computed for the compute shader will be assigned to this object\r\n */\r\n computeDispatchIndirect(\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n buffer: DataBuffer,\r\n offset?: number,\r\n bindingsMapping?: ComputeBindingMapping,\r\n gpuPerfCounter?: WebGPUPerfCounter\r\n ): void;\r\n\r\n /**\r\n * Gets a boolean indicating if all created compute effects are ready\r\n * @returns true if all effects are ready\r\n */\r\n areAllComputeEffectsReady(): boolean;\r\n\r\n /**\r\n * Forces the engine to release all cached compute effects. This means that next effect compilation will have to be done completely even if a similar effect was already compiled\r\n */\r\n releaseComputeEffects(): void;\r\n\r\n /** @internal */\r\n _prepareComputePipelineContext(\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n ): void;\r\n\r\n /** @internal */\r\n _rebuildComputeEffects(): void;\r\n\r\n /** @internal */\r\n _executeWhenComputeStateIsCompiled(pipelineContext: IComputePipelineContext, action: (messages: Nullable<ComputeCompilationMessages>) => void): void;\r\n\r\n /** @internal */\r\n _releaseComputeEffect(effect: ComputeEffect): void;\r\n\r\n /** @internal */\r\n _deleteComputePipelineContext(pipelineContext: IComputePipelineContext): void;\r\n }\r\n}\r\n\r\nThinEngine.prototype.createComputeEffect = function (baseName: IComputeShaderPath & { computeToken?: string }, options: IComputeEffectCreationOptions): ComputeEffect {\r\n throw new Error(\"createComputeEffect: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputePipelineContext = function (): IComputePipelineContext {\r\n throw new Error(\"createComputePipelineContext: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.createComputeContext = function (): IComputeContext | undefined {\r\n return undefined;\r\n};\r\n\r\nThinEngine.prototype.computeDispatch = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y?: number,\r\n z?: number,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n throw new Error(\"computeDispatch: This engine does not support compute shaders!\");\r\n};\r\nThinEngine.prototype.computeDispatchIndirect = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n buffer: DataBuffer,\r\n offset?: number,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n throw new Error(\"computeDispatchIndirect: This engine does not support compute shaders!\");\r\n};\r\n\r\nThinEngine.prototype.areAllComputeEffectsReady = function (): boolean {\r\n return true;\r\n};\r\n\r\nThinEngine.prototype.releaseComputeEffects = function (): void {};\r\n\r\nThinEngine.prototype._prepareComputePipelineContext = function (\r\n pipelineContext: IComputePipelineContext,\r\n computeSourceCode: string,\r\n rawComputeSourceCode: string,\r\n defines: Nullable<string>,\r\n entryPoint: string\r\n): void {};\r\n\r\nThinEngine.prototype._rebuildComputeEffects = function (): void {};\r\n\r\nAbstractEngine.prototype._executeWhenComputeStateIsCompiled = function (\r\n pipelineContext: IComputePipelineContext,\r\n action: (messages: Nullable<ComputeCompilationMessages>) => void\r\n): void {\r\n action(null);\r\n};\r\n\r\nThinEngine.prototype._releaseComputeEffect = function (effect: ComputeEffect): void {};\r\n\r\nThinEngine.prototype._deleteComputePipelineContext = function (pipelineContext: IComputePipelineContext): void {};\r\n"]}
@@ -1,7 +1,37 @@
1
- /** @internal */
1
+ /**
2
+ * Interface representing a draw context at the GPU level (draw call)
3
+ */
2
4
  export interface IDrawContext {
5
+ /**
6
+ * Unique identifier for the draw context.
7
+ */
3
8
  uniqueId: number;
9
+ /**
10
+ * True if instances are used in the draw calls
11
+ */
4
12
  useInstancing: boolean;
13
+ /**
14
+ * Indicates if the draw should be an indirect draw.
15
+ */
16
+ enableIndirectDraw: boolean;
17
+ /**
18
+ * Buffer used for the indirect draw call when enableIndirectDraw is true.
19
+ */
20
+ indirectDrawBuffer?: GPUBuffer;
21
+ /**
22
+ * Data for the indirect draw call (only used when enableIndirectDraw is true).
23
+ * @param indexOrVertexCount - The number of indices (if indexed draw) or vertices (if non-indexed draw).
24
+ * @param instanceCount - The number of instances to draw.
25
+ * @param firstIndexOrVertex - The index (if indexed draw) or vertex (if non-indexed draw) offset to start drawing from.
26
+ * @param forceUpdate - If true, forces the update of the indirect draw data even if instanceCount is the same as in the previous call.
27
+ */
28
+ setIndirectData(indexOrVertexCount: number, instanceCount: number, firstIndexOrVertex: number, forceUpdate?: boolean): void;
29
+ /**
30
+ * Resets the draw context to its initial state.
31
+ */
5
32
  reset(): void;
33
+ /**
34
+ * Disposes the draw context and its resources.
35
+ */
6
36
  dispose(): void;
7
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IDrawContext.js","sourceRoot":"","sources":["../../../../dev/core/src/Engines/IDrawContext.ts"],"names":[],"mappings":"","sourcesContent":["/** @internal */\r\nexport interface IDrawContext {\r\n uniqueId: number;\r\n useInstancing: boolean;\r\n\r\n reset(): void;\r\n dispose(): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"IDrawContext.js","sourceRoot":"","sources":["../../../../dev/core/src/Engines/IDrawContext.ts"],"names":[],"mappings":"","sourcesContent":["/**\r\n * Interface representing a draw context at the GPU level (draw call)\r\n */\r\nexport interface IDrawContext {\r\n /**\r\n * Unique identifier for the draw context.\r\n */\r\n uniqueId: number;\r\n /**\r\n * True if instances are used in the draw calls\r\n */\r\n useInstancing: boolean;\r\n /**\r\n * Indicates if the draw should be an indirect draw.\r\n */\r\n enableIndirectDraw: boolean;\r\n /**\r\n * Buffer used for the indirect draw call when enableIndirectDraw is true.\r\n */\r\n indirectDrawBuffer?: GPUBuffer;\r\n\r\n /**\r\n * Data for the indirect draw call (only used when enableIndirectDraw is true).\r\n * @param indexOrVertexCount - The number of indices (if indexed draw) or vertices (if non-indexed draw).\r\n * @param instanceCount - The number of instances to draw.\r\n * @param firstIndexOrVertex - The index (if indexed draw) or vertex (if non-indexed draw) offset to start drawing from.\r\n * @param forceUpdate - If true, forces the update of the indirect draw data even if instanceCount is the same as in the previous call.\r\n */\r\n setIndirectData(indexOrVertexCount: number, instanceCount: number, firstIndexOrVertex: number, forceUpdate?: boolean): void;\r\n /**\r\n * Resets the draw context to its initial state.\r\n */\r\n reset(): void;\r\n /**\r\n * Disposes the draw context and its resources.\r\n */\r\n dispose(): void;\r\n}\r\n"]}
@@ -1,5 +1,6 @@
1
1
  /** @internal */
2
2
  export interface IMaterialContext {
3
3
  uniqueId: number;
4
+ useVertexPulling: boolean;
4
5
  reset(): void;
5
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IMaterialContext.js","sourceRoot":"","sources":["../../../../dev/core/src/Engines/IMaterialContext.ts"],"names":[],"mappings":"","sourcesContent":["/** @internal */\r\nexport interface IMaterialContext {\r\n uniqueId: number;\r\n\r\n reset(): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"IMaterialContext.js","sourceRoot":"","sources":["../../../../dev/core/src/Engines/IMaterialContext.ts"],"names":[],"mappings":"","sourcesContent":["/** @internal */\r\nexport interface IMaterialContext {\r\n uniqueId: number;\r\n useVertexPulling: boolean;\r\n\r\n reset(): void;\r\n}\r\n"]}
@@ -60,7 +60,6 @@ export declare abstract class WebGPUCacheRenderPipeline {
60
60
  private _depthStencilState;
61
61
  private _vertexBuffers;
62
62
  private _overrideVertexBuffers;
63
- private _indexBuffer;
64
63
  private _textureState;
65
64
  private _useTextureStage;
66
65
  constructor(device: GPUDevice, emptyVertexBuffer: VertexBuffer);
@@ -74,6 +73,7 @@ export declare abstract class WebGPUCacheRenderPipeline {
74
73
  pipeline: Nullable<GPURenderPipeline>;
75
74
  }): void;
76
75
  readonly vertexBuffers: VertexBuffer[];
76
+ readonly indexBuffer: Nullable<DataBuffer>;
77
77
  get colorFormats(): (GPUTextureFormat | null)[];
78
78
  readonly mrtAttachments: number[];
79
79
  readonly mrtTextureArray: InternalTexture[];
@@ -330,7 +330,7 @@ export class WebGPUCacheRenderPipeline {
330
330
  setBuffers(vertexBuffers, indexBuffer, overrideVertexBuffers) {
331
331
  this._vertexBuffers = vertexBuffers;
332
332
  this._overrideVertexBuffers = overrideVertexBuffers;
333
- this._indexBuffer = indexBuffer;
333
+ this.indexBuffer = indexBuffer;
334
334
  }
335
335
  static _GetTopology(fillMode) {
336
336
  switch (fillMode) {
@@ -872,7 +872,7 @@ export class WebGPUCacheRenderPipeline {
872
872
  const topologyIsTriangle = topology === "triangle-list" /* WebGPUConstants.PrimitiveTopology.TriangleList */ || topology === "triangle-strip" /* WebGPUConstants.PrimitiveTopology.TriangleStrip */;
873
873
  let stripIndexFormat = undefined;
874
874
  if (topology === "line-strip" /* WebGPUConstants.PrimitiveTopology.LineStrip */ || topology === "triangle-strip" /* WebGPUConstants.PrimitiveTopology.TriangleStrip */) {
875
- stripIndexFormat = !this._indexBuffer || this._indexBuffer.is32Bits ? "uint32" /* WebGPUConstants.IndexFormat.Uint32 */ : "uint16" /* WebGPUConstants.IndexFormat.Uint16 */;
875
+ stripIndexFormat = !this.indexBuffer || this.indexBuffer.is32Bits ? "uint32" /* WebGPUConstants.IndexFormat.Uint32 */ : "uint16" /* WebGPUConstants.IndexFormat.Uint16 */;
876
876
  }
877
877
  const depthStencilFormatHasStencil = this._webgpuDepthStencilFormat ? WebGPUTextureHelper.HasStencilAspect(this._webgpuDepthStencilFormat) : false;
878
878
  return this._device.createRenderPipeline({