@babylonjs/core 6.34.1 → 6.34.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/Cameras/Inputs/followCameraMouseWheelInput.js +12 -9
  2. package/Cameras/Inputs/followCameraMouseWheelInput.js.map +1 -1
  3. package/Cameras/Inputs/followCameraPointersInput.js +28 -9
  4. package/Cameras/Inputs/followCameraPointersInput.js.map +1 -1
  5. package/Cameras/followCameraInputsManager.js +2 -1
  6. package/Cameras/followCameraInputsManager.js.map +1 -1
  7. package/Debug/skeletonViewer.js +2 -1
  8. package/Debug/skeletonViewer.js.map +1 -1
  9. package/Engines/Processors/shaderCodeInliner.js +15 -14
  10. package/Engines/Processors/shaderCodeInliner.js.map +1 -1
  11. package/Engines/WebGPU/Extensions/engine.computeShader.js +3 -2
  12. package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
  13. package/Engines/WebGPU/webgpuShaderProcessor.js +2 -1
  14. package/Engines/WebGPU/webgpuShaderProcessor.js.map +1 -1
  15. package/Engines/WebGPU/webgpuTintWASM.js +3 -2
  16. package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
  17. package/Engines/engine.d.ts +2 -4
  18. package/Engines/engine.js.map +1 -1
  19. package/Engines/nativeEngine.js +4 -2
  20. package/Engines/nativeEngine.js.map +1 -1
  21. package/Engines/thinEngine.js +4 -4
  22. package/Engines/thinEngine.js.map +1 -1
  23. package/Engines/webgpuEngine.js +75 -50
  24. package/Engines/webgpuEngine.js.map +1 -1
  25. package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js +2 -1
  26. package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js.map +1 -1
  27. package/Gizmos/lightGizmo.js +2 -1
  28. package/Gizmos/lightGizmo.js.map +1 -1
  29. package/Gizmos/rotationGizmo.js +1 -1
  30. package/Gizmos/rotationGizmo.js.map +1 -1
  31. package/Lights/Shadows/cascadedShadowGenerator.js +1 -1
  32. package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
  33. package/Materials/Node/Blocks/Dual/lightBlock.js +2 -1
  34. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  35. package/Materials/Node/Blocks/Dual/reflectionTextureBlock.js +3 -2
  36. package/Materials/Node/Blocks/Dual/reflectionTextureBlock.js.map +1 -1
  37. package/Materials/Node/Blocks/Fragment/fragDepthBlock.js +2 -1
  38. package/Materials/Node/Blocks/Fragment/fragDepthBlock.js.map +1 -1
  39. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js +2 -1
  40. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
  41. package/Materials/Node/Blocks/PBR/anisotropyBlock.js +2 -1
  42. package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
  43. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +3 -2
  44. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  45. package/Materials/Node/Blocks/PBR/reflectionBlock.js +2 -1
  46. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  47. package/Materials/Node/nodeMaterial.js +9 -8
  48. package/Materials/Node/nodeMaterial.js.map +1 -1
  49. package/Materials/Node/nodeMaterialBlock.js +2 -1
  50. package/Materials/Node/nodeMaterialBlock.js.map +1 -1
  51. package/Materials/Textures/renderTargetTexture.js +1 -2
  52. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  53. package/Materials/uniformBuffer.d.ts +1 -4
  54. package/Materials/uniformBuffer.js +2 -5
  55. package/Materials/uniformBuffer.js.map +1 -1
  56. package/Meshes/Builders/groundBuilder.d.ts +7 -1
  57. package/Meshes/Builders/groundBuilder.js +17 -8
  58. package/Meshes/Builders/groundBuilder.js.map +1 -1
  59. package/Meshes/Compression/dracoCompression.js.map +1 -1
  60. package/Meshes/Node/nodeGeometryBlock.js +2 -1
  61. package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
  62. package/Meshes/mesh.d.ts +2 -1
  63. package/Meshes/mesh.js +3 -2
  64. package/Meshes/mesh.js.map +1 -1
  65. package/Misc/assetsManager.js +2 -2
  66. package/Misc/assetsManager.js.map +1 -1
  67. package/Misc/dds.js +1 -1
  68. package/Misc/dds.js.map +1 -1
  69. package/Misc/fileTools.js +4 -0
  70. package/Misc/fileTools.js.map +1 -1
  71. package/Misc/logger.d.ts +3 -3
  72. package/Misc/logger.js +8 -4
  73. package/Misc/logger.js.map +1 -1
  74. package/Misc/sceneSerializer.js +2 -1
  75. package/Misc/sceneSerializer.js.map +1 -1
  76. package/Misc/tools.d.ts +2 -7
  77. package/Misc/tools.js.map +1 -1
  78. package/Navigation/Plugins/recastJSPlugin.js +3 -3
  79. package/Navigation/Plugins/recastJSPlugin.js.map +1 -1
  80. package/Physics/v2/Plugins/havokPlugin.js +1 -1
  81. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  82. package/Physics/v2/physicsBody.d.ts +5 -0
  83. package/Physics/v2/physicsBody.js +7 -0
  84. package/Physics/v2/physicsBody.js.map +1 -1
  85. package/Physics/v2/ragdoll.d.ts +5 -10
  86. package/Physics/v2/ragdoll.js +29 -36
  87. package/Physics/v2/ragdoll.js.map +1 -1
  88. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +2 -2
  89. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  90. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +3 -2
  91. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
  92. package/PostProcesses/screenSpaceCurvaturePostProcess.js +1 -1
  93. package/PostProcesses/screenSpaceCurvaturePostProcess.js.map +1 -1
  94. package/PostProcesses/screenSpaceReflectionPostProcess.js +3 -2
  95. package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
  96. package/Rendering/GaussianSplatting/gaussianSplatting.js.map +1 -1
  97. package/XR/features/WebXRControllerPhysics.js +2 -2
  98. package/XR/features/WebXRControllerPhysics.js.map +1 -1
  99. package/XR/features/WebXRMeshDetector.js +2 -1
  100. package/XR/features/WebXRMeshDetector.js.map +1 -1
  101. package/XR/features/WebXRWalkingLocomotion.js +1 -1
  102. package/XR/features/WebXRWalkingLocomotion.js.map +1 -1
  103. package/XR/motionController/webXRMotionControllerManager.js +1 -1
  104. package/XR/motionController/webXRMotionControllerManager.js.map +1 -1
  105. package/XR/webXRExperienceHelper.js +2 -2
  106. package/XR/webXRExperienceHelper.js.map +1 -1
  107. package/assetContainer.js +2 -2
  108. package/assetContainer.js.map +1 -1
  109. package/package.json +1 -1
  110. package/scene.d.ts +2 -4
  111. package/scene.js +2 -1
  112. package/scene.js.map +1 -1
@@ -1,3 +1,4 @@
1
+ import { Logger } from "../../Misc/logger.js";
1
2
  import { EscapeRegExp, ExtractBetweenMarkers, FindBackward, IsIdentifierChar, RemoveComments, SkipWhitespaces } from "../../Misc/codeStringParsingTools.js";
2
3
  /**
3
4
  * Class used to inline functions in shader code
@@ -25,12 +26,12 @@ export class ShaderCodeInliner {
25
26
  */
26
27
  processCode() {
27
28
  if (this.debug) {
28
- console.log(`Start inlining process (code size=${this._sourceCode.length})...`);
29
+ Logger.Log(`Start inlining process (code size=${this._sourceCode.length})...`);
29
30
  }
30
31
  this._collectFunctions();
31
32
  this._processInlining(this._numMaxIterations);
32
33
  if (this.debug) {
33
- console.log("End of inlining process.");
34
+ Logger.Log("End of inlining process.");
34
35
  }
35
36
  }
36
37
  _collectFunctions() {
@@ -44,7 +45,7 @@ export class ShaderCodeInliner {
44
45
  const funcParamsStartIndex = this._sourceCode.indexOf("(", inlineTokenIndex + this.inlineToken.length);
45
46
  if (funcParamsStartIndex < 0) {
46
47
  if (this.debug) {
47
- console.warn(`Could not find the opening parenthesis after the token. startIndex=${startIndex}`);
48
+ Logger.Warn(`Could not find the opening parenthesis after the token. startIndex=${startIndex}`);
48
49
  }
49
50
  startIndex = inlineTokenIndex + this.inlineToken.length;
50
51
  continue;
@@ -52,7 +53,7 @@ export class ShaderCodeInliner {
52
53
  const funcNameMatch = ShaderCodeInliner._RegexpFindFunctionNameAndType.exec(this._sourceCode.substring(inlineTokenIndex + this.inlineToken.length, funcParamsStartIndex));
53
54
  if (!funcNameMatch) {
54
55
  if (this.debug) {
55
- console.warn(`Could not extract the name/type of the function from: ${this._sourceCode.substring(inlineTokenIndex + this.inlineToken.length, funcParamsStartIndex)}`);
56
+ Logger.Warn(`Could not extract the name/type of the function from: ${this._sourceCode.substring(inlineTokenIndex + this.inlineToken.length, funcParamsStartIndex)}`);
56
57
  }
57
58
  startIndex = inlineTokenIndex + this.inlineToken.length;
58
59
  continue;
@@ -62,7 +63,7 @@ export class ShaderCodeInliner {
62
63
  const funcParamsEndIndex = ExtractBetweenMarkers("(", ")", this._sourceCode, funcParamsStartIndex);
63
64
  if (funcParamsEndIndex < 0) {
64
65
  if (this.debug) {
65
- console.warn(`Could not extract the parameters the function '${funcName}' (type=${funcType}). funcParamsStartIndex=${funcParamsStartIndex}`);
66
+ Logger.Warn(`Could not extract the parameters the function '${funcName}' (type=${funcType}). funcParamsStartIndex=${funcParamsStartIndex}`);
66
67
  }
67
68
  startIndex = inlineTokenIndex + this.inlineToken.length;
68
69
  continue;
@@ -72,7 +73,7 @@ export class ShaderCodeInliner {
72
73
  const funcBodyStartIndex = SkipWhitespaces(this._sourceCode, funcParamsEndIndex + 1);
73
74
  if (funcBodyStartIndex === this._sourceCode.length) {
74
75
  if (this.debug) {
75
- console.warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcParamsEndIndex=${funcParamsEndIndex}`);
76
+ Logger.Warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcParamsEndIndex=${funcParamsEndIndex}`);
76
77
  }
77
78
  startIndex = inlineTokenIndex + this.inlineToken.length;
78
79
  continue;
@@ -80,7 +81,7 @@ export class ShaderCodeInliner {
80
81
  const funcBodyEndIndex = ExtractBetweenMarkers("{", "}", this._sourceCode, funcBodyStartIndex);
81
82
  if (funcBodyEndIndex < 0) {
82
83
  if (this.debug) {
83
- console.warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcBodyStartIndex=${funcBodyStartIndex}`);
84
+ Logger.Warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcBodyStartIndex=${funcBodyStartIndex}`);
84
85
  }
85
86
  startIndex = inlineTokenIndex + this.inlineToken.length;
86
87
  continue;
@@ -116,7 +117,7 @@ export class ShaderCodeInliner {
116
117
  startIndex -= funcBodyEndIndex + 1 - inlineTokenIndex;
117
118
  }
118
119
  if (this.debug) {
119
- console.log(`Collect functions: ${this._functionDescr.length} functions found. functionDescr=`, this._functionDescr);
120
+ Logger.Log(`Collect functions: ${this._functionDescr.length} functions found. functionDescr=${this._functionDescr}`);
120
121
  }
121
122
  }
122
123
  _processInlining(numMaxIterations = 20) {
@@ -126,7 +127,7 @@ export class ShaderCodeInliner {
126
127
  }
127
128
  }
128
129
  if (this.debug) {
129
- console.log(`numMaxIterations is ${numMaxIterations} after inlining process`);
130
+ Logger.Log(`numMaxIterations is ${numMaxIterations} after inlining process`);
130
131
  }
131
132
  return numMaxIterations >= 0;
132
133
  }
@@ -156,7 +157,7 @@ export class ShaderCodeInliner {
156
157
  const callParamsEndIndex = ExtractBetweenMarkers("(", ")", this._sourceCode, callParamsStartIndex);
157
158
  if (callParamsEndIndex < 0) {
158
159
  if (this.debug) {
159
- console.warn(`Could not extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}`);
160
+ Logger.Warn(`Could not extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}`);
160
161
  }
161
162
  startIndex = functionCallIndex + name.length;
162
163
  continue;
@@ -190,7 +191,7 @@ export class ShaderCodeInliner {
190
191
  const params = splitParameterCall(RemoveComments(callParams));
191
192
  if (params === null) {
192
193
  if (this.debug) {
193
- console.warn(`Invalid function call: can't extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}, callParams=` +
194
+ Logger.Warn(`Invalid function call: can't extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}, callParams=` +
194
195
  callParams);
195
196
  }
196
197
  startIndex = functionCallIndex + name.length;
@@ -207,7 +208,7 @@ export class ShaderCodeInliner {
207
208
  }
208
209
  if (paramNames.length !== parameters.length) {
209
210
  if (this.debug) {
210
- console.warn(`Invalid function call: not the same number of parameters for the call than the number expected by the function. Function '${name}' (type=${type}). function parameters=${parameters}, call parameters=${paramNames}`);
211
+ Logger.Warn(`Invalid function call: not the same number of parameters for the call than the number expected by the function. Function '${name}' (type=${type}). function parameters=${parameters}, call parameters=${paramNames}`);
211
212
  }
212
213
  startIndex = functionCallIndex + name.length;
213
214
  continue;
@@ -227,7 +228,7 @@ export class ShaderCodeInliner {
227
228
  const partBetween = this._sourceCode.substring(injectDeclarationIndex + 1, functionCallIndex);
228
229
  this._sourceCode = partBefore + type + " " + retParamName + ";\n" + funcBody + "\n" + partBetween + retParamName + partAfter;
229
230
  if (this.debug) {
230
- console.log(`Replace function call by code. Function '${name}' (type=${type}). injectDeclarationIndex=${injectDeclarationIndex}, call parameters=${paramNames}`);
231
+ Logger.Log(`Replace function call by code. Function '${name}' (type=${type}). injectDeclarationIndex=${injectDeclarationIndex}, call parameters=${paramNames}`);
231
232
  }
232
233
  }
233
234
  else {
@@ -235,7 +236,7 @@ export class ShaderCodeInliner {
235
236
  this._sourceCode = partBefore + funcBody + partAfter;
236
237
  startIndex += funcBody.length - (callParamsEndIndex + 1 - functionCallIndex);
237
238
  if (this.debug) {
238
- console.log(`Replace function call by code. Function '${name}' (type=${type}). functionCallIndex=${functionCallIndex}, call parameters=${paramNames}`);
239
+ Logger.Log(`Replace function call by code. Function '${name}' (type=${type}). functionCallIndex=${functionCallIndex}, call parameters=${paramNames}`);
239
240
  }
240
241
  }
241
242
  doAgain = true;
@@ -1 +1 @@
1
- {"version":3,"file":"sh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AG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;gBAC3C,MAAM,MAAM,GAAW,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC/B,sHAAsH;gBACtH,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,EAAE;oBAChG,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;iBACrB;gBACD,OAAO,WAAW,CAAC;YACvB,CAAC,CAAC,CAAC;SACN;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AAvUuB,gDAA8B,GAAG,4BAA4B,AAA/B,CAAgC","sourcesContent":["import { EscapeRegExp, ExtractBetweenMarkers, FindBackward, IsIdentifierChar, RemoveComments, SkipWhitespaces } from \"../../Misc/codeStringParsingTools\";\r\n\r\ninterface IInlineFunctionDescr {\r\n name: string;\r\n type: string;\r\n parameters: string[];\r\n body: string;\r\n callIndex: number;\r\n}\r\n\r\n/**\r\n * Class used to inline functions in shader code\r\n */\r\nexport class ShaderCodeInliner {\r\n private static readonly _RegexpFindFunctionNameAndType = /((\\s+?)(\\w+)\\s+(\\w+)\\s*?)$/;\r\n\r\n private _sourceCode: string;\r\n private _functionDescr: IInlineFunctionDescr[];\r\n private _numMaxIterations: number;\r\n\r\n /** Gets or sets the token used to mark the functions to inline */\r\n public inlineToken: string;\r\n\r\n /** Gets or sets the debug mode */\r\n public debug: boolean = false;\r\n\r\n /** Gets the code after the inlining process */\r\n public get code(): string {\r\n return this._sourceCode;\r\n }\r\n\r\n /**\r\n * Initializes the inliner\r\n * @param sourceCode shader code source to inline\r\n * @param numMaxIterations maximum number of iterations (used to detect recursive calls)\r\n */\r\n constructor(sourceCode: string, numMaxIterations = 20) {\r\n this._sourceCode = sourceCode;\r\n this._numMaxIterations = numMaxIterations;\r\n this._functionDescr = [];\r\n this.inlineToken = \"#define inline\";\r\n }\r\n\r\n /**\r\n * Start the processing of the shader code\r\n */\r\n public processCode() {\r\n if (this.debug) {\r\n console.log(`Start inlining process (code size=${this._sourceCode.length})...`);\r\n }\r\n this._collectFunctions();\r\n this._processInlining(this._numMaxIterations);\r\n if (this.debug) {\r\n console.log(\"End of inlining process.\");\r\n }\r\n }\r\n\r\n private _collectFunctions() {\r\n let startIndex = 0;\r\n\r\n while (startIndex < this._sourceCode.length) {\r\n // locate the function to inline and extract its name\r\n const inlineTokenIndex = this._sourceCode.indexOf(this.inlineToken, startIndex);\r\n if (inlineTokenIndex < 0) {\r\n break;\r\n }\r\n\r\n const funcParamsStartIndex = this._sourceCode.indexOf(\"(\", inlineTokenIndex + this.inlineToken.length);\r\n if (funcParamsStartIndex < 0) {\r\n if (this.debug) {\r\n console.warn(`Could not find the opening parenthesis after the token. startIndex=${startIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n\r\n const funcNameMatch = ShaderCodeInliner._RegexpFindFunctionNameAndType.exec(\r\n this._sourceCode.substring(inlineTokenIndex + this.inlineToken.length, funcParamsStartIndex)\r\n );\r\n if (!funcNameMatch) {\r\n if (this.debug) {\r\n console.warn(\r\n `Could not extract the name/type of the function from: ${this._sourceCode.substring(inlineTokenIndex + this.inlineToken.length, funcParamsStartIndex)}`\r\n );\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n const [funcType, funcName] = [funcNameMatch[3], funcNameMatch[4]];\r\n\r\n // extract the parameters of the function as a whole string (without the leading / trailing parenthesis)\r\n const funcParamsEndIndex = ExtractBetweenMarkers(\"(\", \")\", this._sourceCode, funcParamsStartIndex);\r\n if (funcParamsEndIndex < 0) {\r\n if (this.debug) {\r\n console.warn(`Could not extract the parameters the function '${funcName}' (type=${funcType}). funcParamsStartIndex=${funcParamsStartIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n const funcParams = this._sourceCode.substring(funcParamsStartIndex + 1, funcParamsEndIndex);\r\n\r\n // extract the body of the function (with the curly brackets)\r\n const funcBodyStartIndex = SkipWhitespaces(this._sourceCode, funcParamsEndIndex + 1);\r\n if (funcBodyStartIndex === this._sourceCode.length) {\r\n if (this.debug) {\r\n console.warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcParamsEndIndex=${funcParamsEndIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n\r\n const funcBodyEndIndex = ExtractBetweenMarkers(\"{\", \"}\", this._sourceCode, funcBodyStartIndex);\r\n if (funcBodyEndIndex < 0) {\r\n if (this.debug) {\r\n console.warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcBodyStartIndex=${funcBodyStartIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n const funcBody = this._sourceCode.substring(funcBodyStartIndex, funcBodyEndIndex + 1);\r\n\r\n // process the parameters: extract each names\r\n const params = RemoveComments(funcParams).split(\",\");\r\n const paramNames = [];\r\n\r\n for (let p = 0; p < params.length; ++p) {\r\n const param = params[p].trim();\r\n const idx = param.lastIndexOf(\" \");\r\n\r\n if (idx >= 0) {\r\n paramNames.push(param.substring(idx + 1));\r\n }\r\n }\r\n\r\n if (funcType !== \"void\") {\r\n // for functions that return a value, we will replace \"return\" by \"tempvarname = \", tempvarname being a unique generated name\r\n paramNames.push(\"return\");\r\n }\r\n\r\n // collect the function\r\n this._functionDescr.push({\r\n name: funcName,\r\n type: funcType,\r\n parameters: paramNames,\r\n body: funcBody,\r\n callIndex: 0,\r\n });\r\n\r\n startIndex = funcBodyEndIndex + 1;\r\n\r\n // remove the function from the source code\r\n const partBefore = inlineTokenIndex > 0 ? this._sourceCode.substring(0, inlineTokenIndex) : \"\";\r\n const partAfter = funcBodyEndIndex + 1 < this._sourceCode.length - 1 ? this._sourceCode.substring(funcBodyEndIndex + 1) : \"\";\r\n\r\n this._sourceCode = partBefore + partAfter;\r\n\r\n startIndex -= funcBodyEndIndex + 1 - inlineTokenIndex;\r\n }\r\n\r\n if (this.debug) {\r\n console.log(`Collect functions: ${this._functionDescr.length} functions found. functionDescr=`, this._functionDescr);\r\n }\r\n }\r\n\r\n private _processInlining(numMaxIterations: number = 20): boolean {\r\n while (numMaxIterations-- >= 0) {\r\n if (!this._replaceFunctionCallsByCode()) {\r\n break;\r\n }\r\n }\r\n\r\n if (this.debug) {\r\n console.log(`numMaxIterations is ${numMaxIterations} after inlining process`);\r\n }\r\n\r\n return numMaxIterations >= 0;\r\n }\r\n\r\n private _replaceFunctionCallsByCode(): boolean {\r\n let doAgain = false;\r\n\r\n for (const func of this._functionDescr) {\r\n const { name, type, parameters, body } = func;\r\n\r\n let startIndex = 0;\r\n\r\n while (startIndex < this._sourceCode.length) {\r\n // Look for the function name in the source code\r\n const functionCallIndex = this._sourceCode.indexOf(name, startIndex);\r\n\r\n if (functionCallIndex < 0) {\r\n break;\r\n }\r\n\r\n // Make sure \"name\" is not part of a bigger string\r\n if (functionCallIndex === 0 || IsIdentifierChar(this._sourceCode.charAt(functionCallIndex - 1))) {\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n // Find the opening parenthesis\r\n const callParamsStartIndex = SkipWhitespaces(this._sourceCode, functionCallIndex + name.length);\r\n if (callParamsStartIndex === this._sourceCode.length || this._sourceCode.charAt(callParamsStartIndex) !== \"(\") {\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n // extract the parameters of the function call as a whole string (without the leading / trailing parenthesis)\r\n const callParamsEndIndex = ExtractBetweenMarkers(\"(\", \")\", this._sourceCode, callParamsStartIndex);\r\n if (callParamsEndIndex < 0) {\r\n if (this.debug) {\r\n console.warn(`Could not extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}`);\r\n }\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n const callParams = this._sourceCode.substring(callParamsStartIndex + 1, callParamsEndIndex);\r\n\r\n // process the parameter call: extract each names\r\n\r\n // this function split the parameter list used in the function call at ',' boundaries by taking care of potential parenthesis like in:\r\n // myfunc(a, vec2(1., 0.), 4.)\r\n const splitParameterCall = (s: string) => {\r\n const parameters = [];\r\n let curIdx = 0,\r\n startParamIdx = 0;\r\n while (curIdx < s.length) {\r\n if (s.charAt(curIdx) === \"(\") {\r\n const idx2 = ExtractBetweenMarkers(\"(\", \")\", s, curIdx);\r\n if (idx2 < 0) {\r\n return null;\r\n }\r\n curIdx = idx2;\r\n } else if (s.charAt(curIdx) === \",\") {\r\n parameters.push(s.substring(startParamIdx, curIdx));\r\n startParamIdx = curIdx + 1;\r\n }\r\n curIdx++;\r\n }\r\n if (startParamIdx < curIdx) {\r\n parameters.push(s.substring(startParamIdx, curIdx));\r\n }\r\n return parameters;\r\n };\r\n\r\n const params = splitParameterCall(RemoveComments(callParams));\r\n\r\n if (params === null) {\r\n if (this.debug) {\r\n console.warn(\r\n `Invalid function call: can't extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}, callParams=` +\r\n callParams\r\n );\r\n }\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n const paramNames = [];\r\n\r\n for (let p = 0; p < params.length; ++p) {\r\n const param = params[p].trim();\r\n paramNames.push(param);\r\n }\r\n\r\n const retParamName = type !== \"void\" ? name + \"_\" + func.callIndex++ : null;\r\n\r\n if (retParamName) {\r\n paramNames.push(retParamName + \" =\");\r\n }\r\n\r\n if (paramNames.length !== parameters.length) {\r\n if (this.debug) {\r\n console.warn(\r\n `Invalid function call: not the same number of parameters for the call than the number expected by the function. Function '${name}' (type=${type}). function parameters=${parameters}, call parameters=${paramNames}`\r\n );\r\n }\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n startIndex = callParamsEndIndex + 1;\r\n\r\n // replace the function call by the body function\r\n const funcBody = this._replaceNames(body, parameters, paramNames);\r\n\r\n let partBefore = functionCallIndex > 0 ? this._sourceCode.substring(0, functionCallIndex) : \"\";\r\n const partAfter = callParamsEndIndex + 1 < this._sourceCode.length - 1 ? this._sourceCode.substring(callParamsEndIndex + 1) : \"\";\r\n\r\n if (retParamName) {\r\n // case where the function returns a value. We generate:\r\n // FUNCTYPE retParamName;\r\n // {function body}\r\n // and replace the function call by retParamName\r\n const injectDeclarationIndex = FindBackward(this._sourceCode, functionCallIndex - 1, \"\\n\", \"{\");\r\n\r\n partBefore = this._sourceCode.substring(0, injectDeclarationIndex + 1);\r\n const partBetween = this._sourceCode.substring(injectDeclarationIndex + 1, functionCallIndex);\r\n\r\n this._sourceCode = partBefore + type + \" \" + retParamName + \";\\n\" + funcBody + \"\\n\" + partBetween + retParamName + partAfter;\r\n\r\n if (this.debug) {\r\n console.log(\r\n `Replace function call by code. Function '${name}' (type=${type}). injectDeclarationIndex=${injectDeclarationIndex}, call parameters=${paramNames}`\r\n );\r\n }\r\n } else {\r\n // simple case where the return value of the function is \"void\"\r\n this._sourceCode = partBefore + funcBody + partAfter;\r\n\r\n startIndex += funcBody.length - (callParamsEndIndex + 1 - functionCallIndex);\r\n\r\n if (this.debug) {\r\n console.log(`Replace function call by code. Function '${name}' (type=${type}). functionCallIndex=${functionCallIndex}, call parameters=${paramNames}`);\r\n }\r\n }\r\n\r\n doAgain = true;\r\n }\r\n }\r\n\r\n return doAgain;\r\n }\r\n\r\n private _replaceNames(code: string, sources: string[], destinations: string[]): string {\r\n for (let i = 0; i < sources.length; ++i) {\r\n const source = new RegExp(EscapeRegExp(sources[i]), \"g\"),\r\n sourceLen = sources[i].length,\r\n destination = destinations[i];\r\n\r\n code = code.replace(source, (match, ...args) => {\r\n const offset: number = args[0];\r\n // Make sure \"source\" is not part of a bigger identifier (for eg, if source=view and we matched it with viewDirection)\r\n if (IsIdentifierChar(code.charAt(offset - 1)) || IsIdentifierChar(code.charAt(offset + sourceLen))) {\r\n return sources[i];\r\n }\r\n return destination;\r\n });\r\n }\r\n\r\n return code;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"shaderCodeInliner.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Processors/shaderCodeInliner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,6BAAyB;AAC1C,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAUzJ;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAa1B,+CAA+C;IAC/C,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,YAAY,UAAkB,EAAE,gBAAgB,GAAG,EAAE;QAbrD,kCAAkC;QAC3B,UAAK,GAAY,KAAK,CAAC;QAa1B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;QAC1C,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,WAAW;QACd,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,MAAM,CAAC,GAAG,CAAC,qCAAqC,IAAI,CAAC,WAAW,CAAC,MAAM,MAAM,CAAC,CAAC;SAClF;QACD,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC9C,IAAI,IAAI,CAAC,KAAK,EAAE;YACZ,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;SAC1C;IACL,CAAC;IAEO,iBAAiB;QACrB,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,OAAO,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;YAC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AC,EAAE,GAAG,CAAC,EACpD,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAC7B,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YAElC,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;gBAC3C,MAAM,MAAM,GAAW,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC/B,sHAAsH;gBACtH,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,EAAE;oBAChG,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;iBACrB;gBACD,OAAO,WAAW,CAAC;YACvB,CAAC,CAAC,CAAC;SACN;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AAvUuB,gDAA8B,GAAG,4BAA4B,AAA/B,CAAgC","sourcesContent":["import { Logger } from \"core/Misc/logger\";\r\nimport { EscapeRegExp, ExtractBetweenMarkers, FindBackward, IsIdentifierChar, RemoveComments, SkipWhitespaces } from \"../../Misc/codeStringParsingTools\";\r\n\r\ninterface IInlineFunctionDescr {\r\n name: string;\r\n type: string;\r\n parameters: string[];\r\n body: string;\r\n callIndex: number;\r\n}\r\n\r\n/**\r\n * Class used to inline functions in shader code\r\n */\r\nexport class ShaderCodeInliner {\r\n private static readonly _RegexpFindFunctionNameAndType = /((\\s+?)(\\w+)\\s+(\\w+)\\s*?)$/;\r\n\r\n private _sourceCode: string;\r\n private _functionDescr: IInlineFunctionDescr[];\r\n private _numMaxIterations: number;\r\n\r\n /** Gets or sets the token used to mark the functions to inline */\r\n public inlineToken: string;\r\n\r\n /** Gets or sets the debug mode */\r\n public debug: boolean = false;\r\n\r\n /** Gets the code after the inlining process */\r\n public get code(): string {\r\n return this._sourceCode;\r\n }\r\n\r\n /**\r\n * Initializes the inliner\r\n * @param sourceCode shader code source to inline\r\n * @param numMaxIterations maximum number of iterations (used to detect recursive calls)\r\n */\r\n constructor(sourceCode: string, numMaxIterations = 20) {\r\n this._sourceCode = sourceCode;\r\n this._numMaxIterations = numMaxIterations;\r\n this._functionDescr = [];\r\n this.inlineToken = \"#define inline\";\r\n }\r\n\r\n /**\r\n * Start the processing of the shader code\r\n */\r\n public processCode() {\r\n if (this.debug) {\r\n Logger.Log(`Start inlining process (code size=${this._sourceCode.length})...`);\r\n }\r\n this._collectFunctions();\r\n this._processInlining(this._numMaxIterations);\r\n if (this.debug) {\r\n Logger.Log(\"End of inlining process.\");\r\n }\r\n }\r\n\r\n private _collectFunctions() {\r\n let startIndex = 0;\r\n\r\n while (startIndex < this._sourceCode.length) {\r\n // locate the function to inline and extract its name\r\n const inlineTokenIndex = this._sourceCode.indexOf(this.inlineToken, startIndex);\r\n if (inlineTokenIndex < 0) {\r\n break;\r\n }\r\n\r\n const funcParamsStartIndex = this._sourceCode.indexOf(\"(\", inlineTokenIndex + this.inlineToken.length);\r\n if (funcParamsStartIndex < 0) {\r\n if (this.debug) {\r\n Logger.Warn(`Could not find the opening parenthesis after the token. startIndex=${startIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n\r\n const funcNameMatch = ShaderCodeInliner._RegexpFindFunctionNameAndType.exec(\r\n this._sourceCode.substring(inlineTokenIndex + this.inlineToken.length, funcParamsStartIndex)\r\n );\r\n if (!funcNameMatch) {\r\n if (this.debug) {\r\n Logger.Warn(\r\n `Could not extract the name/type of the function from: ${this._sourceCode.substring(inlineTokenIndex + this.inlineToken.length, funcParamsStartIndex)}`\r\n );\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n const [funcType, funcName] = [funcNameMatch[3], funcNameMatch[4]];\r\n\r\n // extract the parameters of the function as a whole string (without the leading / trailing parenthesis)\r\n const funcParamsEndIndex = ExtractBetweenMarkers(\"(\", \")\", this._sourceCode, funcParamsStartIndex);\r\n if (funcParamsEndIndex < 0) {\r\n if (this.debug) {\r\n Logger.Warn(`Could not extract the parameters the function '${funcName}' (type=${funcType}). funcParamsStartIndex=${funcParamsStartIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n const funcParams = this._sourceCode.substring(funcParamsStartIndex + 1, funcParamsEndIndex);\r\n\r\n // extract the body of the function (with the curly brackets)\r\n const funcBodyStartIndex = SkipWhitespaces(this._sourceCode, funcParamsEndIndex + 1);\r\n if (funcBodyStartIndex === this._sourceCode.length) {\r\n if (this.debug) {\r\n Logger.Warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcParamsEndIndex=${funcParamsEndIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n\r\n const funcBodyEndIndex = ExtractBetweenMarkers(\"{\", \"}\", this._sourceCode, funcBodyStartIndex);\r\n if (funcBodyEndIndex < 0) {\r\n if (this.debug) {\r\n Logger.Warn(`Could not extract the body of the function '${funcName}' (type=${funcType}). funcBodyStartIndex=${funcBodyStartIndex}`);\r\n }\r\n startIndex = inlineTokenIndex + this.inlineToken.length;\r\n continue;\r\n }\r\n const funcBody = this._sourceCode.substring(funcBodyStartIndex, funcBodyEndIndex + 1);\r\n\r\n // process the parameters: extract each names\r\n const params = RemoveComments(funcParams).split(\",\");\r\n const paramNames = [];\r\n\r\n for (let p = 0; p < params.length; ++p) {\r\n const param = params[p].trim();\r\n const idx = param.lastIndexOf(\" \");\r\n\r\n if (idx >= 0) {\r\n paramNames.push(param.substring(idx + 1));\r\n }\r\n }\r\n\r\n if (funcType !== \"void\") {\r\n // for functions that return a value, we will replace \"return\" by \"tempvarname = \", tempvarname being a unique generated name\r\n paramNames.push(\"return\");\r\n }\r\n\r\n // collect the function\r\n this._functionDescr.push({\r\n name: funcName,\r\n type: funcType,\r\n parameters: paramNames,\r\n body: funcBody,\r\n callIndex: 0,\r\n });\r\n\r\n startIndex = funcBodyEndIndex + 1;\r\n\r\n // remove the function from the source code\r\n const partBefore = inlineTokenIndex > 0 ? this._sourceCode.substring(0, inlineTokenIndex) : \"\";\r\n const partAfter = funcBodyEndIndex + 1 < this._sourceCode.length - 1 ? this._sourceCode.substring(funcBodyEndIndex + 1) : \"\";\r\n\r\n this._sourceCode = partBefore + partAfter;\r\n\r\n startIndex -= funcBodyEndIndex + 1 - inlineTokenIndex;\r\n }\r\n\r\n if (this.debug) {\r\n Logger.Log(`Collect functions: ${this._functionDescr.length} functions found. functionDescr=${this._functionDescr}`);\r\n }\r\n }\r\n\r\n private _processInlining(numMaxIterations: number = 20): boolean {\r\n while (numMaxIterations-- >= 0) {\r\n if (!this._replaceFunctionCallsByCode()) {\r\n break;\r\n }\r\n }\r\n\r\n if (this.debug) {\r\n Logger.Log(`numMaxIterations is ${numMaxIterations} after inlining process`);\r\n }\r\n\r\n return numMaxIterations >= 0;\r\n }\r\n\r\n private _replaceFunctionCallsByCode(): boolean {\r\n let doAgain = false;\r\n\r\n for (const func of this._functionDescr) {\r\n const { name, type, parameters, body } = func;\r\n\r\n let startIndex = 0;\r\n\r\n while (startIndex < this._sourceCode.length) {\r\n // Look for the function name in the source code\r\n const functionCallIndex = this._sourceCode.indexOf(name, startIndex);\r\n\r\n if (functionCallIndex < 0) {\r\n break;\r\n }\r\n\r\n // Make sure \"name\" is not part of a bigger string\r\n if (functionCallIndex === 0 || IsIdentifierChar(this._sourceCode.charAt(functionCallIndex - 1))) {\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n // Find the opening parenthesis\r\n const callParamsStartIndex = SkipWhitespaces(this._sourceCode, functionCallIndex + name.length);\r\n if (callParamsStartIndex === this._sourceCode.length || this._sourceCode.charAt(callParamsStartIndex) !== \"(\") {\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n // extract the parameters of the function call as a whole string (without the leading / trailing parenthesis)\r\n const callParamsEndIndex = ExtractBetweenMarkers(\"(\", \")\", this._sourceCode, callParamsStartIndex);\r\n if (callParamsEndIndex < 0) {\r\n if (this.debug) {\r\n Logger.Warn(`Could not extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}`);\r\n }\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n const callParams = this._sourceCode.substring(callParamsStartIndex + 1, callParamsEndIndex);\r\n\r\n // process the parameter call: extract each names\r\n\r\n // this function split the parameter list used in the function call at ',' boundaries by taking care of potential parenthesis like in:\r\n // myfunc(a, vec2(1., 0.), 4.)\r\n const splitParameterCall = (s: string) => {\r\n const parameters = [];\r\n let curIdx = 0,\r\n startParamIdx = 0;\r\n while (curIdx < s.length) {\r\n if (s.charAt(curIdx) === \"(\") {\r\n const idx2 = ExtractBetweenMarkers(\"(\", \")\", s, curIdx);\r\n if (idx2 < 0) {\r\n return null;\r\n }\r\n curIdx = idx2;\r\n } else if (s.charAt(curIdx) === \",\") {\r\n parameters.push(s.substring(startParamIdx, curIdx));\r\n startParamIdx = curIdx + 1;\r\n }\r\n curIdx++;\r\n }\r\n if (startParamIdx < curIdx) {\r\n parameters.push(s.substring(startParamIdx, curIdx));\r\n }\r\n return parameters;\r\n };\r\n\r\n const params = splitParameterCall(RemoveComments(callParams));\r\n\r\n if (params === null) {\r\n if (this.debug) {\r\n Logger.Warn(\r\n `Invalid function call: can't extract the parameters of the function call. Function '${name}' (type=${type}). callParamsStartIndex=${callParamsStartIndex}, callParams=` +\r\n callParams\r\n );\r\n }\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n const paramNames = [];\r\n\r\n for (let p = 0; p < params.length; ++p) {\r\n const param = params[p].trim();\r\n paramNames.push(param);\r\n }\r\n\r\n const retParamName = type !== \"void\" ? name + \"_\" + func.callIndex++ : null;\r\n\r\n if (retParamName) {\r\n paramNames.push(retParamName + \" =\");\r\n }\r\n\r\n if (paramNames.length !== parameters.length) {\r\n if (this.debug) {\r\n Logger.Warn(\r\n `Invalid function call: not the same number of parameters for the call than the number expected by the function. Function '${name}' (type=${type}). function parameters=${parameters}, call parameters=${paramNames}`\r\n );\r\n }\r\n startIndex = functionCallIndex + name.length;\r\n continue;\r\n }\r\n\r\n startIndex = callParamsEndIndex + 1;\r\n\r\n // replace the function call by the body function\r\n const funcBody = this._replaceNames(body, parameters, paramNames);\r\n\r\n let partBefore = functionCallIndex > 0 ? this._sourceCode.substring(0, functionCallIndex) : \"\";\r\n const partAfter = callParamsEndIndex + 1 < this._sourceCode.length - 1 ? this._sourceCode.substring(callParamsEndIndex + 1) : \"\";\r\n\r\n if (retParamName) {\r\n // case where the function returns a value. We generate:\r\n // FUNCTYPE retParamName;\r\n // {function body}\r\n // and replace the function call by retParamName\r\n const injectDeclarationIndex = FindBackward(this._sourceCode, functionCallIndex - 1, \"\\n\", \"{\");\r\n\r\n partBefore = this._sourceCode.substring(0, injectDeclarationIndex + 1);\r\n const partBetween = this._sourceCode.substring(injectDeclarationIndex + 1, functionCallIndex);\r\n\r\n this._sourceCode = partBefore + type + \" \" + retParamName + \";\\n\" + funcBody + \"\\n\" + partBetween + retParamName + partAfter;\r\n\r\n if (this.debug) {\r\n Logger.Log(\r\n `Replace function call by code. Function '${name}' (type=${type}). injectDeclarationIndex=${injectDeclarationIndex}, call parameters=${paramNames}`\r\n );\r\n }\r\n } else {\r\n // simple case where the return value of the function is \"void\"\r\n this._sourceCode = partBefore + funcBody + partAfter;\r\n\r\n startIndex += funcBody.length - (callParamsEndIndex + 1 - functionCallIndex);\r\n\r\n if (this.debug) {\r\n Logger.Log(`Replace function call by code. Function '${name}' (type=${type}). functionCallIndex=${functionCallIndex}, call parameters=${paramNames}`);\r\n }\r\n }\r\n\r\n doAgain = true;\r\n }\r\n }\r\n\r\n return doAgain;\r\n }\r\n\r\n private _replaceNames(code: string, sources: string[], destinations: string[]): string {\r\n for (let i = 0; i < sources.length; ++i) {\r\n const source = new RegExp(EscapeRegExp(sources[i]), \"g\"),\r\n sourceLen = sources[i].length,\r\n destination = destinations[i];\r\n\r\n code = code.replace(source, (match, ...args) => {\r\n const offset: number = args[0];\r\n // Make sure \"source\" is not part of a bigger identifier (for eg, if source=view and we matched it with viewDirection)\r\n if (IsIdentifierChar(code.charAt(offset - 1)) || IsIdentifierChar(code.charAt(offset + sourceLen))) {\r\n return sources[i];\r\n }\r\n return destination;\r\n });\r\n }\r\n\r\n return code;\r\n }\r\n}\r\n"]}
@@ -1,3 +1,4 @@
1
+ import { Logger } from "../../../Misc/logger.js";
1
2
  import { ComputeEffect } from "../../../Compute/computeEffect.js";
2
3
  import { WebGPUEngine } from "../../webgpuEngine.js";
3
4
  import { WebGPUComputeContext } from "../webgpuComputeContext.js";
@@ -67,8 +68,8 @@ WebGPUEngine.prototype.releaseComputeEffects = function () {
67
68
  WebGPUEngine.prototype._prepareComputePipelineContext = function (pipelineContext, computeSourceCode, rawComputeSourceCode, defines, entryPoint) {
68
69
  const webGpuContext = pipelineContext;
69
70
  if (this.dbgShowShaderCode) {
70
- console.log(defines);
71
- console.log(computeSourceCode);
71
+ Logger.Log(defines);
72
+ Logger.Log(computeSourceCode);
72
73
  }
73
74
  webGpuContext.sources = {
74
75
  compute: computeSourceCode,
@@ -1 +1 @@
1
- {"version":3,"file":"engine.computeShader.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Engines/WebGPU/Extensions/engine.computeShader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAK/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAC;AAStD,YAAY,CAAC,SAAS,CAAC,oBAAoB,GAAG;IAC1C,OAAO,IAAI,oBAAoB,CAAC,I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C,uBAAuB,CAAC,GAAG,CAAC,CAAC;QAEjD,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC/B,MAAM,CAAC,mBAAmB,GAAG,KAAK,CAAC;QACnC,MAAM,CAAC,cAAc,EAAE,CAAC;KAC3B;AACL,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,6BAA6B,GAAG,UAAU,eAAwC;IACrG,MAAM,qBAAqB,GAAG,eAA+C,CAAC;IAC9E,IAAI,qBAAqB,EAAE;QACvB,eAAe,CAAC,OAAO,EAAE,CAAC;KAC7B;AACL,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,qCAAqC,GAAG,UAAU,aAAqB,EAAE,OAAyB,EAAE,UAAkB;IACzI,IAAI,OAAO,EAAE;QACT,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;KAC5D;SAAM;QACH,OAAO,GAAG,EAAE,CAAC;KAChB;IACD,OAAO;QACH,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;YACpC,IAAI,EAAE,OAAO,GAAG,aAAa;SAChC,CAAC;QACF,UAAU;KACb,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { IComputeEffectCreationOptions } from \"../../../Compute/computeEffect\";\r\nimport { ComputeEffect } from \"../../../Compute/computeEffect\";\r\nimport type { IComputeContext } from \"../../../Compute/IComputeContext\";\r\nimport type { IComputePipelineContext } from \"../../../Compute/IComputePipelineContext\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport type { ComputeBindingList, ComputeBindingMapping } from \"../../Extensions/engine.computeShader\";\r\nimport { WebGPUEngine } from \"../../webgpuEngine\";\r\nimport { WebGPUComputeContext } from \"../webgpuComputeContext\";\r\nimport { WebGPUComputePipelineContext } from \"../webgpuComputePipelineContext\";\r\nimport * as WebGPUConstants from \"../webgpuConstants\";\r\n\r\ndeclare module \"../../webgpuEngine\" {\r\n export interface WebGPUEngine {\r\n /** @internal */\r\n _createComputePipelineStageDescriptor(computeShader: string, defines: Nullable<string>, entryPoint: string): GPUProgrammableStage;\r\n }\r\n}\r\n\r\nWebGPUEngine.prototype.createComputeContext = function (): IComputeContext | undefined {\r\n return new WebGPUComputeContext(this._device, this._cacheSampler);\r\n};\r\n\r\nWebGPUEngine.prototype.createComputeEffect = function (baseName: any, options: IComputeEffectCreationOptions): ComputeEffect {\r\n const compute = baseName.computeElement || baseName.compute || baseName.computeToken || baseName.computeSource || baseName;\r\n\r\n const name = compute + \"@\" + options.defines;\r\n if (this._compiledComputeEffects[name]) {\r\n const compiledEffect = <ComputeEffect>this._compiledComputeEffects[name];\r\n if (options.onCompiled && compiledEffect.isReady()) {\r\n options.onCompiled(compiledEffect);\r\n }\r\n\r\n return compiledEffect;\r\n }\r\n const effect = new ComputeEffect(baseName, options, this, name);\r\n this._compiledComputeEffects[name] = effect;\r\n\r\n return effect;\r\n};\r\n\r\nWebGPUEngine.prototype.createComputePipelineContext = function (): IComputePipelineContext {\r\n return new WebGPUComputePipelineContext(this);\r\n};\r\n\r\nWebGPUEngine.prototype.areAllComputeEffectsReady = function (): boolean {\r\n for (const key in this._compiledComputeEffects) {\r\n const effect = this._compiledComputeEffects[key];\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n};\r\n\r\nWebGPUEngine.prototype.computeDispatch = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y = 1,\r\n z = 1,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n this._endCurrentRenderPass();\r\n\r\n const contextPipeline = effect._pipelineContext as WebGPUComputePipelineContext;\r\n const computeContext = context as WebGPUComputeContext;\r\n\r\n if (!contextPipeline.computePipeline) {\r\n contextPipeline.computePipeline = this._device.createComputePipeline({\r\n layout: WebGPUConstants.AutoLayoutMode.Auto,\r\n compute: contextPipeline.stage!,\r\n });\r\n }\r\n\r\n const computePass = this._renderEncoder.beginComputePass();\r\n\r\n computePass.setPipeline(contextPipeline.computePipeline);\r\n\r\n const bindGroups = computeContext.getBindGroups(bindings, contextPipeline.computePipeline, bindingsMapping);\r\n for (let i = 0; i < bindGroups.length; ++i) {\r\n const bindGroup = bindGroups[i];\r\n if (!bindGroup) {\r\n continue;\r\n }\r\n computePass.setBindGroup(i, bindGroup);\r\n }\r\n\r\n if (x + y + z > 0) {\r\n computePass.dispatchWorkgroups(x, y, z);\r\n }\r\n computePass.end();\r\n};\r\n\r\nWebGPUEngine.prototype.releaseComputeEffects = function () {\r\n for (const name in this._compiledComputeEffects) {\r\n const webGPUPipelineContextCompute = this._compiledComputeEffects[name].getPipelineContext() as WebGPUComputePipelineContext;\r\n this._deleteComputePipelineContext(webGPUPipelineContextCompute);\r\n }\r\n\r\n this._compiledComputeEffects = {};\r\n};\r\n\r\nWebGPUEngine.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 const webGpuContext = pipelineContext as WebGPUComputePipelineContext;\r\n\r\n if (this.dbgShowShaderCode) {\r\n console.log(defines);\r\n console.log(computeSourceCode);\r\n }\r\n\r\n webGpuContext.sources = {\r\n compute: computeSourceCode,\r\n rawCompute: rawComputeSourceCode,\r\n };\r\n\r\n webGpuContext.stage = this._createComputePipelineStageDescriptor(computeSourceCode, defines, entryPoint);\r\n};\r\n\r\nWebGPUEngine.prototype._releaseComputeEffect = function (effect: ComputeEffect): void {\r\n if (this._compiledComputeEffects[effect._key]) {\r\n delete this._compiledComputeEffects[effect._key];\r\n\r\n this._deleteComputePipelineContext(effect.getPipelineContext() as WebGPUComputePipelineContext);\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype._rebuildComputeEffects = function (): void {\r\n for (const key in this._compiledComputeEffects) {\r\n const effect = this._compiledComputeEffects[key];\r\n\r\n effect._pipelineContext = null;\r\n effect._wasPreviouslyReady = false;\r\n effect._prepareEffect();\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype._deleteComputePipelineContext = function (pipelineContext: IComputePipelineContext): void {\r\n const webgpuPipelineContext = pipelineContext as WebGPUComputePipelineContext;\r\n if (webgpuPipelineContext) {\r\n pipelineContext.dispose();\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype._createComputePipelineStageDescriptor = function (computeShader: string, defines: Nullable<string>, entryPoint: string): GPUProgrammableStage {\r\n if (defines) {\r\n defines = \"//\" + defines.split(\"\\n\").join(\"\\n//\") + \"\\n\";\r\n } else {\r\n defines = \"\";\r\n }\r\n return {\r\n module: this._device.createShaderModule({\r\n code: defines + computeShader,\r\n }),\r\n entryPoint,\r\n };\r\n};\r\n"]}
1
+ {"version":3,"file":"engine.computeShader.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Engines/WebGPU/Extensions/engine.computeShader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,gCAAyB;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAK/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAC;AAStD,YAAY,CAAC,SAAS,CAAC,oBAAoB,GAAG;IAC1C,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;AACtE,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,mBAAmB,GAAG,UAAU,QAAa,EAAE,OAAsC;IACxG,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,IAAI,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,YAAY,IAAI,QAA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;IACrG,MAAM,qBAAqB,GAAG,eAA+C,CAAC;IAC9E,IAAI,qBAAqB,EAAE;QACvB,eAAe,CAAC,OAAO,EAAE,CAAC;KAC7B;AACL,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,qCAAqC,GAAG,UAAU,aAAqB,EAAE,OAAyB,EAAE,UAAkB;IACzI,IAAI,OAAO,EAAE;QACT,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;KAC5D;SAAM;QACH,OAAO,GAAG,EAAE,CAAC;KAChB;IACD,OAAO;QACH,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC;YACpC,IAAI,EAAE,OAAO,GAAG,aAAa;SAChC,CAAC;QACF,UAAU;KACb,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { Logger } from \"core/Misc/logger\";\r\nimport type { IComputeEffectCreationOptions } from \"../../../Compute/computeEffect\";\r\nimport { ComputeEffect } from \"../../../Compute/computeEffect\";\r\nimport type { IComputeContext } from \"../../../Compute/IComputeContext\";\r\nimport type { IComputePipelineContext } from \"../../../Compute/IComputePipelineContext\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport type { ComputeBindingList, ComputeBindingMapping } from \"../../Extensions/engine.computeShader\";\r\nimport { WebGPUEngine } from \"../../webgpuEngine\";\r\nimport { WebGPUComputeContext } from \"../webgpuComputeContext\";\r\nimport { WebGPUComputePipelineContext } from \"../webgpuComputePipelineContext\";\r\nimport * as WebGPUConstants from \"../webgpuConstants\";\r\n\r\ndeclare module \"../../webgpuEngine\" {\r\n export interface WebGPUEngine {\r\n /** @internal */\r\n _createComputePipelineStageDescriptor(computeShader: string, defines: Nullable<string>, entryPoint: string): GPUProgrammableStage;\r\n }\r\n}\r\n\r\nWebGPUEngine.prototype.createComputeContext = function (): IComputeContext | undefined {\r\n return new WebGPUComputeContext(this._device, this._cacheSampler);\r\n};\r\n\r\nWebGPUEngine.prototype.createComputeEffect = function (baseName: any, options: IComputeEffectCreationOptions): ComputeEffect {\r\n const compute = baseName.computeElement || baseName.compute || baseName.computeToken || baseName.computeSource || baseName;\r\n\r\n const name = compute + \"@\" + options.defines;\r\n if (this._compiledComputeEffects[name]) {\r\n const compiledEffect = <ComputeEffect>this._compiledComputeEffects[name];\r\n if (options.onCompiled && compiledEffect.isReady()) {\r\n options.onCompiled(compiledEffect);\r\n }\r\n\r\n return compiledEffect;\r\n }\r\n const effect = new ComputeEffect(baseName, options, this, name);\r\n this._compiledComputeEffects[name] = effect;\r\n\r\n return effect;\r\n};\r\n\r\nWebGPUEngine.prototype.createComputePipelineContext = function (): IComputePipelineContext {\r\n return new WebGPUComputePipelineContext(this);\r\n};\r\n\r\nWebGPUEngine.prototype.areAllComputeEffectsReady = function (): boolean {\r\n for (const key in this._compiledComputeEffects) {\r\n const effect = this._compiledComputeEffects[key];\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n};\r\n\r\nWebGPUEngine.prototype.computeDispatch = function (\r\n effect: ComputeEffect,\r\n context: IComputeContext,\r\n bindings: ComputeBindingList,\r\n x: number,\r\n y = 1,\r\n z = 1,\r\n bindingsMapping?: ComputeBindingMapping\r\n): void {\r\n this._endCurrentRenderPass();\r\n\r\n const contextPipeline = effect._pipelineContext as WebGPUComputePipelineContext;\r\n const computeContext = context as WebGPUComputeContext;\r\n\r\n if (!contextPipeline.computePipeline) {\r\n contextPipeline.computePipeline = this._device.createComputePipeline({\r\n layout: WebGPUConstants.AutoLayoutMode.Auto,\r\n compute: contextPipeline.stage!,\r\n });\r\n }\r\n\r\n const computePass = this._renderEncoder.beginComputePass();\r\n\r\n computePass.setPipeline(contextPipeline.computePipeline);\r\n\r\n const bindGroups = computeContext.getBindGroups(bindings, contextPipeline.computePipeline, bindingsMapping);\r\n for (let i = 0; i < bindGroups.length; ++i) {\r\n const bindGroup = bindGroups[i];\r\n if (!bindGroup) {\r\n continue;\r\n }\r\n computePass.setBindGroup(i, bindGroup);\r\n }\r\n\r\n if (x + y + z > 0) {\r\n computePass.dispatchWorkgroups(x, y, z);\r\n }\r\n computePass.end();\r\n};\r\n\r\nWebGPUEngine.prototype.releaseComputeEffects = function () {\r\n for (const name in this._compiledComputeEffects) {\r\n const webGPUPipelineContextCompute = this._compiledComputeEffects[name].getPipelineContext() as WebGPUComputePipelineContext;\r\n this._deleteComputePipelineContext(webGPUPipelineContextCompute);\r\n }\r\n\r\n this._compiledComputeEffects = {};\r\n};\r\n\r\nWebGPUEngine.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 const webGpuContext = pipelineContext as WebGPUComputePipelineContext;\r\n\r\n if (this.dbgShowShaderCode) {\r\n Logger.Log(defines!);\r\n Logger.Log(computeSourceCode);\r\n }\r\n\r\n webGpuContext.sources = {\r\n compute: computeSourceCode,\r\n rawCompute: rawComputeSourceCode,\r\n };\r\n\r\n webGpuContext.stage = this._createComputePipelineStageDescriptor(computeSourceCode, defines, entryPoint);\r\n};\r\n\r\nWebGPUEngine.prototype._releaseComputeEffect = function (effect: ComputeEffect): void {\r\n if (this._compiledComputeEffects[effect._key]) {\r\n delete this._compiledComputeEffects[effect._key];\r\n\r\n this._deleteComputePipelineContext(effect.getPipelineContext() as WebGPUComputePipelineContext);\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype._rebuildComputeEffects = function (): void {\r\n for (const key in this._compiledComputeEffects) {\r\n const effect = this._compiledComputeEffects[key];\r\n\r\n effect._pipelineContext = null;\r\n effect._wasPreviouslyReady = false;\r\n effect._prepareEffect();\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype._deleteComputePipelineContext = function (pipelineContext: IComputePipelineContext): void {\r\n const webgpuPipelineContext = pipelineContext as WebGPUComputePipelineContext;\r\n if (webgpuPipelineContext) {\r\n pipelineContext.dispose();\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype._createComputePipelineStageDescriptor = function (computeShader: string, defines: Nullable<string>, entryPoint: string): GPUProgrammableStage {\r\n if (defines) {\r\n defines = \"//\" + defines.split(\"\\n\").join(\"\\n//\") + \"\\n\";\r\n } else {\r\n defines = \"\";\r\n }\r\n return {\r\n module: this._device.createShaderModule({\r\n code: defines + computeShader,\r\n }),\r\n entryPoint,\r\n };\r\n};\r\n"]}
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable babylonjs/available */
2
2
  /* eslint-disable jsdoc/require-jsdoc */
3
+ import { Logger } from "../../Misc/logger.js";
3
4
  import { ShaderLanguage } from "../../Materials/shaderLanguage.js";
4
5
  import * as WebGPUConstants from "./webgpuConstants.js";
5
6
  /** @internal */
@@ -195,7 +196,7 @@ export class WebGPUShaderProcessor {
195
196
  _injectStartingAndEndingCode(code, mainFuncDecl, startingCode, endingCode) {
196
197
  let idx = code.indexOf(mainFuncDecl);
197
198
  if (idx < 0) {
198
- console.error(`No "main" function found in shader code! Processing aborted.`);
199
+ Logger.Error(`No "main" function found in shader code! Processing aborted.`);
199
200
  return code;
200
201
  }
201
202
  if (startingCode) {
@@ -1 +1 @@
1
- {"version":3,"file":"webgpuShaderProcessor.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/WebGPU/webgpuShaderProcessor.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,wCAAwC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AAGrD,gBAAgB;AAChB,MAAM,OAAgB,qBAAqB;IAA3C;QA4EW,mBAAc,GAAG,cAAc,CAAC,IAAI,CAAC;QAE5C,sKAAsK;QACtK,qDAAqD;QAC9C,yCAAoC,GAA+B,EAAE,CAAC;IAsOjF,CAAC;IA/Na,wBAAwB,CAAC,IAAY,EAAE,WAAmB,EAAE,aAAwC;QAC1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zByB,CAyBxB;AAEF,gEAAgE;AAC/C,wDAAkC,GAA8B;IAC7E,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,gBAAgB;IAChC,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;CACzB,AAPkD,CAOjD;AAEF,gEAAgE;AAC/C,oDAA8B,GAA8B;IACzE,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,gBAAgB;IAChC,eAAe,EAAE,WAAW;IAC5B,oBAAoB,EAAE,gBAAgB;IACtC,WAAW,EAAE,aAAa;IAC1B,gBAAgB,EAAE,kBAAkB;IACpC,SAAS,EAAE,WAAW;CACzB,AAR8C,CAQ7C;AAEF,gEAAgE;AAC/C,iEAA2C,GAA+C;IACvG,WAAW,EAAE,eAAe,CAAC,oBAAoB,CAAC,IAAI;IACtD,gBAAgB,EAAE,eAAe,CAAC,oBAAoB,CAAC,SAAS;IAChE,SAAS,EAAE,eAAe,CAAC,oBAAoB,CAAC,GAAG;IACnD,cAAc,EAAE,eAAe,CAAC,oBAAoB,CAAC,QAAQ;IAC7D,SAAS,EAAE,eAAe,CAAC,oBAAoB,CAAC,GAAG;CACtD,AAN2D,CAM1D;AAEF,uFAAuF;AACvF,gEAAgE;AAC/C,oDAA8B,GAA8B;IACzE,eAAe,EAAE,eAAe;IAChC,oBAAoB,EAAE,eAAe;CACxC,AAH8C,CAG7C;AAEF,gEAAgE;AAC/C,6DAAuC,GAA+B;IACnF,aAAa,EAAE,IAAI;IACnB,kBAAkB,EAAE,IAAI;IACxB,OAAO,EAAE,KAAK;CACjB,AAJuD,CAItD","sourcesContent":["/* eslint-disable babylonjs/available */\r\n/* eslint-disable jsdoc/require-jsdoc */\r\nimport { ShaderLanguage } from \"../../Materials/shaderLanguage\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IShaderProcessor } from \"../Processors/iShaderProcessor\";\r\nimport * as WebGPUConstants from \"./webgpuConstants\";\r\nimport type { WebGPUSamplerDescription, WebGPUShaderProcessingContext, WebGPUTextureDescription, WebGPUBufferDescription } from \"./webgpuShaderProcessingContext\";\r\n\r\n/** @internal */\r\nexport abstract class WebGPUShaderProcessor implements IShaderProcessor {\r\n public static readonly AutoSamplerSuffix = \"Sampler\";\r\n public static readonly LeftOvertUBOName = \"LeftOver\";\r\n public static readonly InternalsUBOName = \"Internals\";\r\n\r\n public static UniformSizes: { [type: string]: number } = {\r\n // GLSL types\r\n bool: 1,\r\n int: 1,\r\n float: 1,\r\n vec2: 2,\r\n ivec2: 2,\r\n uvec2: 2,\r\n vec3: 3,\r\n ivec3: 3,\r\n uvec3: 3,\r\n vec4: 4,\r\n ivec4: 4,\r\n uvec4: 4,\r\n mat2: 4,\r\n mat3: 12,\r\n mat4: 16,\r\n\r\n // WGSL types\r\n i32: 1,\r\n u32: 1,\r\n f32: 1,\r\n mat2x2: 4,\r\n mat3x3: 12,\r\n mat4x4: 16,\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _SamplerFunctionByWebGLSamplerType: { [key: string]: string } = {\r\n sampler2D: \"sampler2D\",\r\n sampler2DArray: \"sampler2DArray\",\r\n sampler2DShadow: \"sampler2DShadow\",\r\n sampler2DArrayShadow: \"sampler2DArrayShadow\",\r\n samplerCube: \"samplerCube\",\r\n sampler3D: \"sampler3D\",\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _TextureTypeByWebGLSamplerType: { [key: string]: string } = {\r\n sampler2D: \"texture2D\",\r\n sampler2DArray: \"texture2DArray\",\r\n sampler2DShadow: \"texture2D\",\r\n sampler2DArrayShadow: \"texture2DArray\",\r\n samplerCube: \"textureCube\",\r\n samplerCubeArray: \"textureCubeArray\",\r\n sampler3D: \"texture3D\",\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _GpuTextureViewDimensionByWebGPUTextureType: { [key: string]: GPUTextureViewDimension } = {\r\n textureCube: WebGPUConstants.TextureViewDimension.Cube,\r\n textureCubeArray: WebGPUConstants.TextureViewDimension.CubeArray,\r\n texture2D: WebGPUConstants.TextureViewDimension.E2d,\r\n texture2DArray: WebGPUConstants.TextureViewDimension.E2dArray,\r\n texture3D: WebGPUConstants.TextureViewDimension.E3d,\r\n };\r\n\r\n // if the webgl sampler type is not listed in this array, \"sampler\" is taken by default\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _SamplerTypeByWebGLSamplerType: { [key: string]: string } = {\r\n sampler2DShadow: \"samplerShadow\",\r\n sampler2DArrayShadow: \"samplerShadow\",\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _IsComparisonSamplerByWebGPUSamplerType: { [key: string]: boolean } = {\r\n samplerShadow: true,\r\n samplerArrayShadow: true,\r\n sampler: false,\r\n };\r\n\r\n public shaderLanguage = ShaderLanguage.GLSL;\r\n\r\n // this object is populated only with vertex kinds known by the engine (position, uv, ...) and only if the type of the corresponding vertex buffer is an integer type)\r\n // if the type is a signed type, the value is negated\r\n public vertexBufferKindToNumberOfComponents: { [kind: string]: number } = {};\r\n\r\n protected _webgpuProcessingContext: WebGPUShaderProcessingContext;\r\n\r\n protected abstract _getArraySize(name: string, type: string, preProcessors: { [key: string]: string }): [string, string, number];\r\n protected abstract _generateLeftOverUBOCode(name: string, uniformBufferDescription: WebGPUBufferDescription): string;\r\n\r\n protected _addUniformToLeftOverUBO(name: string, uniformType: string, preProcessors: { [key: string]: string }): void {\r\n let length = 0;\r\n\r\n [name, uniformType, length] = this._getArraySize(name, uniformType, preProcessors);\r\n\r\n for (let i = 0; i < this._webgpuProcessingContext.leftOverUniforms.length; i++) {\r\n if (this._webgpuProcessingContext.leftOverUniforms[i].name === name) {\r\n return;\r\n }\r\n }\r\n\r\n this._webgpuProcessingContext.leftOverUniforms.push({\r\n name,\r\n type: uniformType,\r\n length,\r\n });\r\n }\r\n\r\n protected _buildLeftOverUBO(): string {\r\n if (!this._webgpuProcessingContext.leftOverUniforms.length) {\r\n return \"\";\r\n }\r\n const name = WebGPUShaderProcessor.LeftOvertUBOName;\r\n let availableUBO = this._webgpuProcessingContext.availableBuffers[name];\r\n if (!availableUBO) {\r\n availableUBO = {\r\n binding: this._webgpuProcessingContext.getNextFreeUBOBinding(),\r\n };\r\n this._webgpuProcessingContext.availableBuffers[name] = availableUBO;\r\n this._addBufferBindingDescription(name, availableUBO, WebGPUConstants.BufferBindingType.Uniform, true);\r\n this._addBufferBindingDescription(name, availableUBO, WebGPUConstants.BufferBindingType.Uniform, false);\r\n }\r\n\r\n return this._generateLeftOverUBOCode(name, availableUBO);\r\n }\r\n\r\n protected _collectBindingNames(): void {\r\n // collect all the binding names for faster processing in WebGPUCacheBindGroup\r\n for (let i = 0; i < this._webgpuProcessingContext.bindGroupLayoutEntries.length; i++) {\r\n const setDefinition = this._webgpuProcessingContext.bindGroupLayoutEntries[i];\r\n if (setDefinition === undefined) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[i] = [];\r\n continue;\r\n }\r\n for (let j = 0; j < setDefinition.length; j++) {\r\n const entry = this._webgpuProcessingContext.bindGroupLayoutEntries[i][j];\r\n const name = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[i][entry.binding].name;\r\n const nameInArrayOfTexture = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[i][entry.binding].nameInArrayOfTexture;\r\n if (entry) {\r\n if (entry.texture || entry.externalTexture || entry.storageTexture) {\r\n this._webgpuProcessingContext.textureNames.push(nameInArrayOfTexture!);\r\n } else if (entry.sampler) {\r\n this._webgpuProcessingContext.samplerNames.push(name);\r\n } else if (entry.buffer) {\r\n this._webgpuProcessingContext.bufferNames.push(name);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected _preCreateBindGroupEntries(): void {\r\n const bindGroupEntries = this._webgpuProcessingContext.bindGroupEntries;\r\n\r\n for (let i = 0; i < this._webgpuProcessingContext.bindGroupLayoutEntries.length; i++) {\r\n const setDefinition = this._webgpuProcessingContext.bindGroupLayoutEntries[i];\r\n\r\n const entries: GPUBindGroupEntry[] = [];\r\n for (let j = 0; j < setDefinition.length; j++) {\r\n const entry = this._webgpuProcessingContext.bindGroupLayoutEntries[i][j];\r\n\r\n if (entry.sampler || entry.texture || entry.storageTexture || entry.externalTexture) {\r\n entries.push({\r\n binding: entry.binding,\r\n resource: undefined as any,\r\n });\r\n } else if (entry.buffer) {\r\n entries.push({\r\n binding: entry.binding,\r\n resource: {\r\n buffer: undefined as any,\r\n offset: 0,\r\n size: 0,\r\n },\r\n });\r\n }\r\n }\r\n\r\n bindGroupEntries[i] = entries;\r\n }\r\n }\r\n\r\n protected _addTextureBindingDescription(\r\n name: string,\r\n textureInfo: WebGPUTextureDescription,\r\n textureIndex: number,\r\n dimension: Nullable<GPUTextureViewDimension>,\r\n format: Nullable<GPUTextureFormat>,\r\n isVertex: boolean\r\n ): void {\r\n // eslint-disable-next-line prefer-const\r\n let { groupIndex, bindingIndex } = textureInfo.textures[textureIndex];\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex]) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex] = [];\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex] = [];\r\n }\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex]) {\r\n let len;\r\n if (dimension === null) {\r\n len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n externalTexture: {},\r\n });\r\n } else if (format) {\r\n len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n storageTexture: {\r\n access: WebGPUConstants.StorageTextureAccess.WriteOnly,\r\n format,\r\n viewDimension: dimension,\r\n },\r\n });\r\n } else {\r\n len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n texture: {\r\n sampleType: textureInfo.sampleType,\r\n viewDimension: dimension,\r\n multisampled: false,\r\n },\r\n });\r\n }\r\n const textureName = textureInfo.isTextureArray ? name + textureIndex : name;\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex] = { name, index: len - 1, nameInArrayOfTexture: textureName };\r\n }\r\n\r\n bindingIndex = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex].index;\r\n if (isVertex) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Vertex;\r\n } else {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Fragment;\r\n }\r\n }\r\n\r\n protected _addSamplerBindingDescription(name: string, samplerInfo: WebGPUSamplerDescription, isVertex: boolean): void {\r\n // eslint-disable-next-line prefer-const\r\n let { groupIndex, bindingIndex } = samplerInfo.binding;\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex]) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex] = [];\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex] = [];\r\n }\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex]) {\r\n const len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n sampler: {\r\n type: samplerInfo.type,\r\n },\r\n });\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex] = { name, index: len - 1 };\r\n }\r\n\r\n bindingIndex = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex].index;\r\n if (isVertex) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Vertex;\r\n } else {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Fragment;\r\n }\r\n }\r\n\r\n protected _addBufferBindingDescription(name: string, uniformBufferInfo: WebGPUBufferDescription, bufferType: GPUBufferBindingType, isVertex: boolean): void {\r\n // eslint-disable-next-line prefer-const\r\n let { groupIndex, bindingIndex } = uniformBufferInfo.binding;\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex]) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex] = [];\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex] = [];\r\n }\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex]) {\r\n const len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n buffer: {\r\n type: bufferType,\r\n },\r\n });\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex] = { name, index: len - 1 };\r\n }\r\n\r\n bindingIndex = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex].index;\r\n if (isVertex) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Vertex;\r\n } else {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Fragment;\r\n }\r\n }\r\n\r\n protected _injectStartingAndEndingCode(code: string, mainFuncDecl: string, startingCode?: string, endingCode?: string): string {\r\n let idx = code.indexOf(mainFuncDecl);\r\n if (idx < 0) {\r\n console.error(`No \"main\" function found in shader code! Processing aborted.`);\r\n return code;\r\n }\r\n if (startingCode) {\r\n // eslint-disable-next-line no-empty\r\n while (idx++ < code.length && code.charAt(idx) != \"{\") {}\r\n if (idx < code.length) {\r\n const part1 = code.substring(0, idx + 1);\r\n const part2 = code.substring(idx + 1);\r\n code = part1 + startingCode + part2;\r\n }\r\n }\r\n\r\n if (endingCode) {\r\n const lastClosingCurly = code.lastIndexOf(\"}\");\r\n code = code.substring(0, lastClosingCurly);\r\n code += endingCode + \"\\n}\";\r\n }\r\n\r\n return code;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webgpuShaderProcessor.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/WebGPU/webgpuShaderProcessor.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,wCAAwC;AACxC,OAAO,EAAE,MAAM,EAAE,6BAAyB;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AAGrD,gBAAgB;AAChB,MAAM,OAAgB,qBAAqB;IAA3C;QA4EW,mBAAc,GAAG,cAAc,CAAC,IAAI,CAAC;QAE5C,sKAAsK;QACtK,qDAAqD;QAC9C,yCAAoC,GAA+B,EAAE,CAAC;IAsOjF,CAAC;IA/Na,wBAAwB,CAAC,IAAY,EAAE,WAAmB,EAAE,aAAwC;QAC1G,IAAI,MAAM,GAAG,CAAC,CAAC;QAEf,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;QAEnF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC5E,IAAI,IAAI,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;gBACjE,OAAO;aACV;SACJ;QAED,IAAI,CAAC,wBAAwB,CAAC,gBAAgB,CAAC,IAAI,CAAC;YAChD,IAAI;YACJ,IAAI,EAAE,WAAW;YACjB,MAAM;SACT,CAAC,CAAC;IACP,CAAC;IAES,iBAAiB;QACvB,IAA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I;IACtD,gBAAgB,EAAE,eAAe,CAAC,oBAAoB,CAAC,SAAS;IAChE,SAAS,EAAE,eAAe,CAAC,oBAAoB,CAAC,GAAG;IACnD,cAAc,EAAE,eAAe,CAAC,oBAAoB,CAAC,QAAQ;IAC7D,SAAS,EAAE,eAAe,CAAC,oBAAoB,CAAC,GAAG;CACtD,AAN2D,CAM1D;AAEF,uFAAuF;AACvF,gEAAgE;AAC/C,oDAA8B,GAA8B;IACzE,eAAe,EAAE,eAAe;IAChC,oBAAoB,EAAE,eAAe;CACxC,AAH8C,CAG7C;AAEF,gEAAgE;AAC/C,6DAAuC,GAA+B;IACnF,aAAa,EAAE,IAAI;IACnB,kBAAkB,EAAE,IAAI;IACxB,OAAO,EAAE,KAAK;CACjB,AAJuD,CAItD","sourcesContent":["/* eslint-disable babylonjs/available */\r\n/* eslint-disable jsdoc/require-jsdoc */\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { ShaderLanguage } from \"../../Materials/shaderLanguage\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IShaderProcessor } from \"../Processors/iShaderProcessor\";\r\nimport * as WebGPUConstants from \"./webgpuConstants\";\r\nimport type { WebGPUSamplerDescription, WebGPUShaderProcessingContext, WebGPUTextureDescription, WebGPUBufferDescription } from \"./webgpuShaderProcessingContext\";\r\n\r\n/** @internal */\r\nexport abstract class WebGPUShaderProcessor implements IShaderProcessor {\r\n public static readonly AutoSamplerSuffix = \"Sampler\";\r\n public static readonly LeftOvertUBOName = \"LeftOver\";\r\n public static readonly InternalsUBOName = \"Internals\";\r\n\r\n public static UniformSizes: { [type: string]: number } = {\r\n // GLSL types\r\n bool: 1,\r\n int: 1,\r\n float: 1,\r\n vec2: 2,\r\n ivec2: 2,\r\n uvec2: 2,\r\n vec3: 3,\r\n ivec3: 3,\r\n uvec3: 3,\r\n vec4: 4,\r\n ivec4: 4,\r\n uvec4: 4,\r\n mat2: 4,\r\n mat3: 12,\r\n mat4: 16,\r\n\r\n // WGSL types\r\n i32: 1,\r\n u32: 1,\r\n f32: 1,\r\n mat2x2: 4,\r\n mat3x3: 12,\r\n mat4x4: 16,\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _SamplerFunctionByWebGLSamplerType: { [key: string]: string } = {\r\n sampler2D: \"sampler2D\",\r\n sampler2DArray: \"sampler2DArray\",\r\n sampler2DShadow: \"sampler2DShadow\",\r\n sampler2DArrayShadow: \"sampler2DArrayShadow\",\r\n samplerCube: \"samplerCube\",\r\n sampler3D: \"sampler3D\",\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _TextureTypeByWebGLSamplerType: { [key: string]: string } = {\r\n sampler2D: \"texture2D\",\r\n sampler2DArray: \"texture2DArray\",\r\n sampler2DShadow: \"texture2D\",\r\n sampler2DArrayShadow: \"texture2DArray\",\r\n samplerCube: \"textureCube\",\r\n samplerCubeArray: \"textureCubeArray\",\r\n sampler3D: \"texture3D\",\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _GpuTextureViewDimensionByWebGPUTextureType: { [key: string]: GPUTextureViewDimension } = {\r\n textureCube: WebGPUConstants.TextureViewDimension.Cube,\r\n textureCubeArray: WebGPUConstants.TextureViewDimension.CubeArray,\r\n texture2D: WebGPUConstants.TextureViewDimension.E2d,\r\n texture2DArray: WebGPUConstants.TextureViewDimension.E2dArray,\r\n texture3D: WebGPUConstants.TextureViewDimension.E3d,\r\n };\r\n\r\n // if the webgl sampler type is not listed in this array, \"sampler\" is taken by default\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _SamplerTypeByWebGLSamplerType: { [key: string]: string } = {\r\n sampler2DShadow: \"samplerShadow\",\r\n sampler2DArrayShadow: \"samplerShadow\",\r\n };\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n protected static _IsComparisonSamplerByWebGPUSamplerType: { [key: string]: boolean } = {\r\n samplerShadow: true,\r\n samplerArrayShadow: true,\r\n sampler: false,\r\n };\r\n\r\n public shaderLanguage = ShaderLanguage.GLSL;\r\n\r\n // this object is populated only with vertex kinds known by the engine (position, uv, ...) and only if the type of the corresponding vertex buffer is an integer type)\r\n // if the type is a signed type, the value is negated\r\n public vertexBufferKindToNumberOfComponents: { [kind: string]: number } = {};\r\n\r\n protected _webgpuProcessingContext: WebGPUShaderProcessingContext;\r\n\r\n protected abstract _getArraySize(name: string, type: string, preProcessors: { [key: string]: string }): [string, string, number];\r\n protected abstract _generateLeftOverUBOCode(name: string, uniformBufferDescription: WebGPUBufferDescription): string;\r\n\r\n protected _addUniformToLeftOverUBO(name: string, uniformType: string, preProcessors: { [key: string]: string }): void {\r\n let length = 0;\r\n\r\n [name, uniformType, length] = this._getArraySize(name, uniformType, preProcessors);\r\n\r\n for (let i = 0; i < this._webgpuProcessingContext.leftOverUniforms.length; i++) {\r\n if (this._webgpuProcessingContext.leftOverUniforms[i].name === name) {\r\n return;\r\n }\r\n }\r\n\r\n this._webgpuProcessingContext.leftOverUniforms.push({\r\n name,\r\n type: uniformType,\r\n length,\r\n });\r\n }\r\n\r\n protected _buildLeftOverUBO(): string {\r\n if (!this._webgpuProcessingContext.leftOverUniforms.length) {\r\n return \"\";\r\n }\r\n const name = WebGPUShaderProcessor.LeftOvertUBOName;\r\n let availableUBO = this._webgpuProcessingContext.availableBuffers[name];\r\n if (!availableUBO) {\r\n availableUBO = {\r\n binding: this._webgpuProcessingContext.getNextFreeUBOBinding(),\r\n };\r\n this._webgpuProcessingContext.availableBuffers[name] = availableUBO;\r\n this._addBufferBindingDescription(name, availableUBO, WebGPUConstants.BufferBindingType.Uniform, true);\r\n this._addBufferBindingDescription(name, availableUBO, WebGPUConstants.BufferBindingType.Uniform, false);\r\n }\r\n\r\n return this._generateLeftOverUBOCode(name, availableUBO);\r\n }\r\n\r\n protected _collectBindingNames(): void {\r\n // collect all the binding names for faster processing in WebGPUCacheBindGroup\r\n for (let i = 0; i < this._webgpuProcessingContext.bindGroupLayoutEntries.length; i++) {\r\n const setDefinition = this._webgpuProcessingContext.bindGroupLayoutEntries[i];\r\n if (setDefinition === undefined) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[i] = [];\r\n continue;\r\n }\r\n for (let j = 0; j < setDefinition.length; j++) {\r\n const entry = this._webgpuProcessingContext.bindGroupLayoutEntries[i][j];\r\n const name = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[i][entry.binding].name;\r\n const nameInArrayOfTexture = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[i][entry.binding].nameInArrayOfTexture;\r\n if (entry) {\r\n if (entry.texture || entry.externalTexture || entry.storageTexture) {\r\n this._webgpuProcessingContext.textureNames.push(nameInArrayOfTexture!);\r\n } else if (entry.sampler) {\r\n this._webgpuProcessingContext.samplerNames.push(name);\r\n } else if (entry.buffer) {\r\n this._webgpuProcessingContext.bufferNames.push(name);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n protected _preCreateBindGroupEntries(): void {\r\n const bindGroupEntries = this._webgpuProcessingContext.bindGroupEntries;\r\n\r\n for (let i = 0; i < this._webgpuProcessingContext.bindGroupLayoutEntries.length; i++) {\r\n const setDefinition = this._webgpuProcessingContext.bindGroupLayoutEntries[i];\r\n\r\n const entries: GPUBindGroupEntry[] = [];\r\n for (let j = 0; j < setDefinition.length; j++) {\r\n const entry = this._webgpuProcessingContext.bindGroupLayoutEntries[i][j];\r\n\r\n if (entry.sampler || entry.texture || entry.storageTexture || entry.externalTexture) {\r\n entries.push({\r\n binding: entry.binding,\r\n resource: undefined as any,\r\n });\r\n } else if (entry.buffer) {\r\n entries.push({\r\n binding: entry.binding,\r\n resource: {\r\n buffer: undefined as any,\r\n offset: 0,\r\n size: 0,\r\n },\r\n });\r\n }\r\n }\r\n\r\n bindGroupEntries[i] = entries;\r\n }\r\n }\r\n\r\n protected _addTextureBindingDescription(\r\n name: string,\r\n textureInfo: WebGPUTextureDescription,\r\n textureIndex: number,\r\n dimension: Nullable<GPUTextureViewDimension>,\r\n format: Nullable<GPUTextureFormat>,\r\n isVertex: boolean\r\n ): void {\r\n // eslint-disable-next-line prefer-const\r\n let { groupIndex, bindingIndex } = textureInfo.textures[textureIndex];\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex]) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex] = [];\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex] = [];\r\n }\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex]) {\r\n let len;\r\n if (dimension === null) {\r\n len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n externalTexture: {},\r\n });\r\n } else if (format) {\r\n len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n storageTexture: {\r\n access: WebGPUConstants.StorageTextureAccess.WriteOnly,\r\n format,\r\n viewDimension: dimension,\r\n },\r\n });\r\n } else {\r\n len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n texture: {\r\n sampleType: textureInfo.sampleType,\r\n viewDimension: dimension,\r\n multisampled: false,\r\n },\r\n });\r\n }\r\n const textureName = textureInfo.isTextureArray ? name + textureIndex : name;\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex] = { name, index: len - 1, nameInArrayOfTexture: textureName };\r\n }\r\n\r\n bindingIndex = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex].index;\r\n if (isVertex) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Vertex;\r\n } else {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Fragment;\r\n }\r\n }\r\n\r\n protected _addSamplerBindingDescription(name: string, samplerInfo: WebGPUSamplerDescription, isVertex: boolean): void {\r\n // eslint-disable-next-line prefer-const\r\n let { groupIndex, bindingIndex } = samplerInfo.binding;\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex]) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex] = [];\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex] = [];\r\n }\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex]) {\r\n const len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n sampler: {\r\n type: samplerInfo.type,\r\n },\r\n });\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex] = { name, index: len - 1 };\r\n }\r\n\r\n bindingIndex = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex].index;\r\n if (isVertex) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Vertex;\r\n } else {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Fragment;\r\n }\r\n }\r\n\r\n protected _addBufferBindingDescription(name: string, uniformBufferInfo: WebGPUBufferDescription, bufferType: GPUBufferBindingType, isVertex: boolean): void {\r\n // eslint-disable-next-line prefer-const\r\n let { groupIndex, bindingIndex } = uniformBufferInfo.binding;\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex]) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex] = [];\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex] = [];\r\n }\r\n if (!this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex]) {\r\n const len = this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex].push({\r\n binding: bindingIndex,\r\n visibility: 0,\r\n buffer: {\r\n type: bufferType,\r\n },\r\n });\r\n this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex] = { name, index: len - 1 };\r\n }\r\n\r\n bindingIndex = this._webgpuProcessingContext.bindGroupLayoutEntryInfo[groupIndex][bindingIndex].index;\r\n if (isVertex) {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Vertex;\r\n } else {\r\n this._webgpuProcessingContext.bindGroupLayoutEntries[groupIndex][bindingIndex].visibility |= WebGPUConstants.ShaderStage.Fragment;\r\n }\r\n }\r\n\r\n protected _injectStartingAndEndingCode(code: string, mainFuncDecl: string, startingCode?: string, endingCode?: string): string {\r\n let idx = code.indexOf(mainFuncDecl);\r\n if (idx < 0) {\r\n Logger.Error(`No \"main\" function found in shader code! Processing aborted.`);\r\n return code;\r\n }\r\n if (startingCode) {\r\n // eslint-disable-next-line no-empty\r\n while (idx++ < code.length && code.charAt(idx) != \"{\") {}\r\n if (idx < code.length) {\r\n const part1 = code.substring(0, idx + 1);\r\n const part2 = code.substring(idx + 1);\r\n code = part1 + startingCode + part2;\r\n }\r\n }\r\n\r\n if (endingCode) {\r\n const lastClosingCurly = code.lastIndexOf(\"}\");\r\n code = code.substring(0, lastClosingCurly);\r\n code += endingCode + \"\\n}\";\r\n }\r\n\r\n return code;\r\n }\r\n}\r\n"]}
@@ -1,3 +1,4 @@
1
+ import { Logger } from "../../Misc/logger.js";
1
2
  import { Tools } from "../../Misc/tools.js";
2
3
  /** @internal */
3
4
  export class WebGPUTintWASM {
@@ -23,8 +24,8 @@ export class WebGPUTintWASM {
23
24
  convertSpirV2WGSL(code, disableUniformityAnalysis = false) {
24
25
  const ccode = WebGPUTintWASM._twgsl.convertSpirV2WGSL(code, WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis);
25
26
  if (WebGPUTintWASM.ShowWGSLShaderCode) {
26
- console.log(ccode);
27
- console.log("***********************************************");
27
+ Logger.Log(ccode);
28
+ Logger.Log("***********************************************");
28
29
  }
29
30
  return WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis ? "diagnostic(off, derivative_uniformity);\n" + ccode : ccode;
30
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"webgpuTintWASM.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/WebGPU/webgpuTintWASM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAoBzC,gBAAgB;AAChB,MAAM,OAAO,cAAc;IAahB,KAAK,CAAC,SAAS,CAAC,YAA2B;QAC9C,IAAI,cAAc,CAAC,MAAM,EAAE;YACvB,OAAO;SACV;QAED,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;QAClC,YAAY,mCACL,cAAc,CAAC,oBAAoB,GACnC,YAAY,CAClB,CAAC;QAEF,IAAI,YAAY,CAAC,KAAK,EAAE;YACpB,cAAc,CAAC,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC;YAC3C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC5B;QAED,IAAI,YAAY,CAAC,MAAM,IAAI,YAAY,CAAC,QAAQ,EAAE;YAC9C,MAAM,KAAK,CAAC,sBAAsB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;SAC3D;QAED,IAAK,IAAY,CAAC,KAAK,EAAE;YACrB,cAAc,CAAC,MAAM,GAAG,MAAO,IAAY,CAAC,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,YAAa,CAAC,QAAS,CAAC,CAAC,CAAC;YACtG,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC5B;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC;IACrD,CAAC;IAEM,iBAAiB,CAAC,IAAiB,EAAE,yBAAyB,GAAG,KAAK;QACzE,MAAM,KAAK,GAAG,cAAc,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC,yBAAyB,IAAI,yBAAyB,CAAC,CAAC;QACnI,IAAI,cAAc,CAAC,kBAAkB,EAAE;YACnC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACnB,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;SAClE;QACD,OAAO,cAAc,CAAC,yBAAyB,IAAI,yBAAyB,CAAC,CAAC,CAAC,2CAA2C,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/I,CAAC;;AA/CD,yBAAyB;AACD,mCAAoB,GAAiB;IACzD,MAAM,EAAE,GAAG,KAAK,CAAC,cAAc,iBAAiB;IAChD,QAAQ,EAAE,GAAG,KAAK,CAAC,cAAc,mBAAmB;CACvD,CAAC;AAEY,iCAAkB,GAAG,KAAK,CAAC;AAE3B,wCAAyB,GAAG,KAAK,CAAC;AAEjC,qBAAM,GAAQ,IAAI,CAAC","sourcesContent":["import { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Options to load the associated Twgsl library\r\n */\r\nexport interface TwgslOptions {\r\n /**\r\n * Defines an existing instance of Twgsl (useful in modules who do not access the global instance).\r\n */\r\n twgsl?: any;\r\n /**\r\n * Defines the URL of the twgsl JS File.\r\n */\r\n jsPath?: string;\r\n /**\r\n * Defines the URL of the twgsl WASM File.\r\n */\r\n wasmPath?: string;\r\n}\r\n\r\n/** @internal */\r\nexport class WebGPUTintWASM {\r\n // Default twgsl options.\r\n private static readonly _TWgslDefaultOptions: TwgslOptions = {\r\n jsPath: `${Tools._DefaultCdnUrl}/twgsl/twgsl.js`,\r\n wasmPath: `${Tools._DefaultCdnUrl}/twgsl/twgsl.wasm`,\r\n };\r\n\r\n public static ShowWGSLShaderCode = false;\r\n\r\n public static DisableUniformityAnalysis = false;\r\n\r\n private static _twgsl: any = null;\r\n\r\n public async initTwgsl(twgslOptions?: TwgslOptions): Promise<void> {\r\n if (WebGPUTintWASM._twgsl) {\r\n return;\r\n }\r\n\r\n twgslOptions = twgslOptions || {};\r\n twgslOptions = {\r\n ...WebGPUTintWASM._TWgslDefaultOptions,\r\n ...twgslOptions,\r\n };\r\n\r\n if (twgslOptions.twgsl) {\r\n WebGPUTintWASM._twgsl = twgslOptions.twgsl;\r\n return Promise.resolve();\r\n }\r\n\r\n if (twgslOptions.jsPath && twgslOptions.wasmPath) {\r\n await Tools.LoadBabylonScriptAsync(twgslOptions.jsPath);\r\n }\r\n\r\n if ((self as any).twgsl) {\r\n WebGPUTintWASM._twgsl = await (self as any).twgsl(Tools.GetBabylonScriptURL(twgslOptions!.wasmPath!));\r\n return Promise.resolve();\r\n }\r\n\r\n return Promise.reject(\"twgsl is not available.\");\r\n }\r\n\r\n public convertSpirV2WGSL(code: Uint32Array, disableUniformityAnalysis = false): string {\r\n const ccode = WebGPUTintWASM._twgsl.convertSpirV2WGSL(code, WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis);\r\n if (WebGPUTintWASM.ShowWGSLShaderCode) {\r\n console.log(ccode);\r\n console.log(\"***********************************************\");\r\n }\r\n return WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis ? \"diagnostic(off, derivative_uniformity);\\n\" + ccode : ccode;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"webgpuTintWASM.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/WebGPU/webgpuTintWASM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,6BAAyB;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAoBzC,gBAAgB;AAChB,MAAM,OAAO,cAAc;IAahB,KAAK,CAAC,SAAS,CAAC,YAA2B;QAC9C,IAAI,cAAc,CAAC,MAAM,EAAE;YACvB,OAAO;SACV;QAED,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;QAClC,YAAY,mCACL,cAAc,CAAC,oBAAoB,GACnC,YAAY,CAClB,CAAC;QAEF,IAAI,YAAY,CAAC,KAAK,EAAE;YACpB,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misc/logger\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Options to load the associated Twgsl library\r\n */\r\nexport interface TwgslOptions {\r\n /**\r\n * Defines an existing instance of Twgsl (useful in modules who do not access the global instance).\r\n */\r\n twgsl?: any;\r\n /**\r\n * Defines the URL of the twgsl JS File.\r\n */\r\n jsPath?: string;\r\n /**\r\n * Defines the URL of the twgsl WASM File.\r\n */\r\n wasmPath?: string;\r\n}\r\n\r\n/** @internal */\r\nexport class WebGPUTintWASM {\r\n // Default twgsl options.\r\n private static readonly _TWgslDefaultOptions: TwgslOptions = {\r\n jsPath: `${Tools._DefaultCdnUrl}/twgsl/twgsl.js`,\r\n wasmPath: `${Tools._DefaultCdnUrl}/twgsl/twgsl.wasm`,\r\n };\r\n\r\n public static ShowWGSLShaderCode = false;\r\n\r\n public static DisableUniformityAnalysis = false;\r\n\r\n private static _twgsl: any = null;\r\n\r\n public async initTwgsl(twgslOptions?: TwgslOptions): Promise<void> {\r\n if (WebGPUTintWASM._twgsl) {\r\n return;\r\n }\r\n\r\n twgslOptions = twgslOptions || {};\r\n twgslOptions = {\r\n ...WebGPUTintWASM._TWgslDefaultOptions,\r\n ...twgslOptions,\r\n };\r\n\r\n if (twgslOptions.twgsl) {\r\n WebGPUTintWASM._twgsl = twgslOptions.twgsl;\r\n return Promise.resolve();\r\n }\r\n\r\n if (twgslOptions.jsPath && twgslOptions.wasmPath) {\r\n await Tools.LoadBabylonScriptAsync(twgslOptions.jsPath);\r\n }\r\n\r\n if ((self as any).twgsl) {\r\n WebGPUTintWASM._twgsl = await (self as any).twgsl(Tools.GetBabylonScriptURL(twgslOptions!.wasmPath!));\r\n return Promise.resolve();\r\n }\r\n\r\n return Promise.reject(\"twgsl is not available.\");\r\n }\r\n\r\n public convertSpirV2WGSL(code: Uint32Array, disableUniformityAnalysis = false): string {\r\n const ccode = WebGPUTintWASM._twgsl.convertSpirV2WGSL(code, WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis);\r\n if (WebGPUTintWASM.ShowWGSLShaderCode) {\r\n Logger.Log(ccode);\r\n Logger.Log(\"***********************************************\");\r\n }\r\n return WebGPUTintWASM.DisableUniformityAnalysis || disableUniformityAnalysis ? \"diagnostic(off, derivative_uniformity);\\n\" + ccode : ccode;\r\n }\r\n}\r\n"]}
@@ -644,10 +644,8 @@ export declare class Engine extends ThinEngine {
644
644
  * @internal
645
645
  */
646
646
  _reportDrawCall(numDrawCalls?: number): void;
647
- /**
648
- * @internal
649
- */
650
- _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean): Promise<string | ArrayBuffer>;
647
+ _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: false): Promise<string>;
648
+ _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: true): Promise<ArrayBuffer>;
651
649
  /**
652
650
  * Gets the source code of the vertex shader associated with a specific webGL program
653
651
  * @param program defines the program to use