@babylonjs/core 6.34.1 → 6.34.3
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.
- package/Cameras/Inputs/followCameraMouseWheelInput.js +12 -9
- package/Cameras/Inputs/followCameraMouseWheelInput.js.map +1 -1
- package/Cameras/Inputs/followCameraPointersInput.js +28 -9
- package/Cameras/Inputs/followCameraPointersInput.js.map +1 -1
- package/Cameras/followCameraInputsManager.js +2 -1
- package/Cameras/followCameraInputsManager.js.map +1 -1
- package/Compute/computeShader.d.ts +8 -2
- package/Compute/computeShader.js +5 -1
- package/Compute/computeShader.js.map +1 -1
- package/Debug/skeletonViewer.js +2 -1
- package/Debug/skeletonViewer.js.map +1 -1
- package/Engines/Extensions/engine.computeShader.d.ts +3 -1
- package/Engines/Extensions/engine.computeShader.js.map +1 -1
- package/Engines/Extensions/engine.multiRender.js +3 -2
- package/Engines/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/Processors/shaderCodeInliner.js +15 -14
- package/Engines/Processors/shaderCodeInliner.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.computeShader.js +13 -4
- package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.multiRender.js +3 -2
- package/Engines/WebGPU/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.storageBuffer.js +8 -1
- package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +1 -1
- package/Engines/WebGPU/webgpuBufferManager.d.ts +3 -1
- package/Engines/WebGPU/webgpuBufferManager.js +10 -2
- package/Engines/WebGPU/webgpuBufferManager.js.map +1 -1
- package/Engines/WebGPU/webgpuOcclusionQuery.js +1 -1
- package/Engines/WebGPU/webgpuOcclusionQuery.js.map +1 -1
- package/Engines/WebGPU/webgpuPerfCounter.d.ts +15 -0
- package/Engines/WebGPU/webgpuPerfCounter.js +31 -0
- package/Engines/WebGPU/webgpuPerfCounter.js.map +1 -0
- package/Engines/WebGPU/webgpuQuerySet.d.ts +3 -1
- package/Engines/WebGPU/webgpuQuerySet.js +37 -18
- package/Engines/WebGPU/webgpuQuerySet.js.map +1 -1
- package/Engines/WebGPU/webgpuRenderTargetWrapper.d.ts +20 -1
- package/Engines/WebGPU/webgpuRenderTargetWrapper.js +18 -1
- package/Engines/WebGPU/webgpuRenderTargetWrapper.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessor.js +2 -1
- package/Engines/WebGPU/webgpuShaderProcessor.js.map +1 -1
- package/Engines/WebGPU/webgpuTimestampQuery.d.ts +11 -2
- package/Engines/WebGPU/webgpuTimestampQuery.js +45 -7
- package/Engines/WebGPU/webgpuTimestampQuery.js.map +1 -1
- package/Engines/WebGPU/webgpuTintWASM.js +3 -2
- package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
- package/Engines/engine.d.ts +3 -5
- package/Engines/engine.js.map +1 -1
- package/Engines/index.d.ts +1 -0
- package/Engines/index.js +1 -0
- package/Engines/index.js.map +1 -1
- package/Engines/nativeEngine.js +4 -2
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +4 -4
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.d.ts +16 -1
- package/Engines/webgpuEngine.js +108 -54
- package/Engines/webgpuEngine.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js +2 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js.map +1 -1
- package/Gizmos/lightGizmo.js +2 -1
- package/Gizmos/lightGizmo.js.map +1 -1
- package/Gizmos/rotationGizmo.js +1 -1
- package/Gizmos/rotationGizmo.js.map +1 -1
- package/Lights/Shadows/cascadedShadowGenerator.js +1 -1
- package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js +2 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBlock.js +3 -2
- package/Materials/Node/Blocks/Dual/reflectionTextureBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragDepthBlock.js +2 -1
- package/Materials/Node/Blocks/Fragment/fragDepthBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js +2 -1
- package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js +2 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +3 -2
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js +2 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.js +9 -8
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterialBlock.js +2 -1
- package/Materials/Node/nodeMaterialBlock.js.map +1 -1
- package/Materials/Textures/multiRenderTarget.d.ts +4 -0
- package/Materials/Textures/multiRenderTarget.js +1 -0
- package/Materials/Textures/multiRenderTarget.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.js +1 -2
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/uniformBuffer.d.ts +1 -4
- package/Materials/uniformBuffer.js +2 -5
- package/Materials/uniformBuffer.js.map +1 -1
- package/Meshes/Builders/groundBuilder.d.ts +7 -1
- package/Meshes/Builders/groundBuilder.js +17 -8
- package/Meshes/Builders/groundBuilder.js.map +1 -1
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Node/nodeGeometryBlock.js +2 -1
- package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
- package/Meshes/mesh.d.ts +2 -1
- package/Meshes/mesh.js +3 -2
- package/Meshes/mesh.js.map +1 -1
- package/Misc/assetsManager.js +2 -2
- package/Misc/assetsManager.js.map +1 -1
- package/Misc/dds.js +1 -1
- package/Misc/dds.js.map +1 -1
- package/Misc/fileTools.js +4 -0
- package/Misc/fileTools.js.map +1 -1
- package/Misc/logger.d.ts +3 -3
- package/Misc/logger.js +8 -4
- package/Misc/logger.js.map +1 -1
- package/Misc/perfCounter.d.ts +2 -1
- package/Misc/perfCounter.js +1 -0
- package/Misc/perfCounter.js.map +1 -1
- package/Misc/sceneSerializer.js +2 -1
- package/Misc/sceneSerializer.js.map +1 -1
- package/Misc/tools.d.ts +2 -7
- package/Misc/tools.js.map +1 -1
- package/Navigation/Plugins/recastJSPlugin.js +3 -3
- package/Navigation/Plugins/recastJSPlugin.js.map +1 -1
- package/Particles/computeShaderParticleSystem.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.js +1 -1
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +5 -0
- package/Physics/v2/physicsBody.js +7 -0
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/ragdoll.d.ts +5 -10
- package/Physics/v2/ragdoll.js +29 -36
- package/Physics/v2/ragdoll.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +2 -2
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +3 -2
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
- package/PostProcesses/screenSpaceCurvaturePostProcess.js +1 -1
- package/PostProcesses/screenSpaceCurvaturePostProcess.js.map +1 -1
- package/PostProcesses/screenSpaceReflectionPostProcess.js +3 -2
- package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
- package/Rendering/GaussianSplatting/gaussianSplatting.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js +3 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/XR/features/WebXRControllerPhysics.js +2 -2
- package/XR/features/WebXRControllerPhysics.js.map +1 -1
- package/XR/features/WebXRMeshDetector.js +2 -1
- package/XR/features/WebXRMeshDetector.js.map +1 -1
- package/XR/features/WebXRWalkingLocomotion.js +1 -1
- package/XR/features/WebXRWalkingLocomotion.js.map +1 -1
- package/XR/motionController/webXRMotionControllerManager.js +1 -1
- package/XR/motionController/webXRMotionControllerManager.js.map +1 -1
- package/XR/webXRExperienceHelper.js +2 -2
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/assetContainer.js +2 -2
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +2 -4
- package/scene.js +2 -1
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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":"shaderCodeInliner.js","sourceRoot":"","sources":["../../../../../dev/core/src/Engines/Processors/shaderCodeInliner.ts"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,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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C,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,8 +1,10 @@
|
|
|
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";
|
|
4
5
|
import { WebGPUComputePipelineContext } from "../webgpuComputePipelineContext.js";
|
|
5
6
|
import * as WebGPUConstants from "../webgpuConstants.js";
|
|
7
|
+
const computePassDescriptor = {};
|
|
6
8
|
WebGPUEngine.prototype.createComputeContext = function () {
|
|
7
9
|
return new WebGPUComputeContext(this._device, this._cacheSampler);
|
|
8
10
|
};
|
|
@@ -32,7 +34,7 @@ WebGPUEngine.prototype.areAllComputeEffectsReady = function () {
|
|
|
32
34
|
}
|
|
33
35
|
return true;
|
|
34
36
|
};
|
|
35
|
-
WebGPUEngine.prototype.computeDispatch = function (effect, context, bindings, x, y = 1, z = 1, bindingsMapping) {
|
|
37
|
+
WebGPUEngine.prototype.computeDispatch = function (effect, context, bindings, x, y = 1, z = 1, bindingsMapping, gpuPerfCounter) {
|
|
36
38
|
this._endCurrentRenderPass();
|
|
37
39
|
const contextPipeline = effect._pipelineContext;
|
|
38
40
|
const computeContext = context;
|
|
@@ -42,7 +44,10 @@ WebGPUEngine.prototype.computeDispatch = function (effect, context, bindings, x,
|
|
|
42
44
|
compute: contextPipeline.stage,
|
|
43
45
|
});
|
|
44
46
|
}
|
|
45
|
-
|
|
47
|
+
if (gpuPerfCounter) {
|
|
48
|
+
this._timestampQuery.startPass(computePassDescriptor, this._timestampIndex);
|
|
49
|
+
}
|
|
50
|
+
const computePass = this._renderEncoder.beginComputePass(computePassDescriptor);
|
|
46
51
|
computePass.setPipeline(contextPipeline.computePipeline);
|
|
47
52
|
const bindGroups = computeContext.getBindGroups(bindings, contextPipeline.computePipeline, bindingsMapping);
|
|
48
53
|
for (let i = 0; i < bindGroups.length; ++i) {
|
|
@@ -56,6 +61,10 @@ WebGPUEngine.prototype.computeDispatch = function (effect, context, bindings, x,
|
|
|
56
61
|
computePass.dispatchWorkgroups(x, y, z);
|
|
57
62
|
}
|
|
58
63
|
computePass.end();
|
|
64
|
+
if (gpuPerfCounter) {
|
|
65
|
+
this._timestampQuery.endPass(this._timestampIndex, gpuPerfCounter);
|
|
66
|
+
this._timestampIndex += 2;
|
|
67
|
+
}
|
|
59
68
|
};
|
|
60
69
|
WebGPUEngine.prototype.releaseComputeEffects = function () {
|
|
61
70
|
for (const name in this._compiledComputeEffects) {
|
|
@@ -67,8 +76,8 @@ WebGPUEngine.prototype.releaseComputeEffects = function () {
|
|
|
67
76
|
WebGPUEngine.prototype._prepareComputePipelineContext = function (pipelineContext, computeSourceCode, rawComputeSourceCode, defines, entryPoint) {
|
|
68
77
|
const webGpuContext = pipelineContext;
|
|
69
78
|
if (this.dbgShowShaderCode) {
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
Logger.Log(defines);
|
|
80
|
+
Logger.Log(computeSourceCode);
|
|
72
81
|
}
|
|
73
82
|
webGpuContext.sources = {
|
|
74
83
|
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,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CAAC,CAAC;KACnG;AACL,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAC5C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,uBAAuB,EAAE;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,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;AAUtD,MAAM,qBAAqB,GAA6B,EAAE,CAAC;AAE3D,YAAY,CAAC,SAAS,CAAC,oBAAoB,GAAG;IAC1C,OAAO,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,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uBAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEjD,IAAI,CAAC,6BAA6B,CAAC,MAAM,CAAC,kBAAkB,EAAkC,CAAC,CAAC;KACnG;AACL,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,sBAAsB,GAAG;IAC5C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,uBAAuB,EAAE;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,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 { 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\nimport type { WebGPUPerfCounter } from \"../webgpuPerfCounter\";\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\nconst computePassDescriptor: GPUComputePassDescriptor = {};\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 gpuPerfCounter?: WebGPUPerfCounter\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 if (gpuPerfCounter) {\r\n this._timestampQuery.startPass(computePassDescriptor, this._timestampIndex);\r\n }\r\n\r\n const computePass = this._renderEncoder.beginComputePass(computePassDescriptor);\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 if (gpuPerfCounter) {\r\n this._timestampQuery.endPass(this._timestampIndex, gpuPerfCounter);\r\n this._timestampIndex += 2;\r\n }\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"]}
|
|
@@ -21,7 +21,7 @@ WebGPUEngine.prototype.unBindMultiColorAttachmentFramebuffer = function (rtWrapp
|
|
|
21
21
|
this._cacheRenderPipeline.setMRTAttachments(this._mrtAttachments);
|
|
22
22
|
};
|
|
23
23
|
WebGPUEngine.prototype.createMultipleRenderTarget = function (size, options, initializeBuffers) {
|
|
24
|
-
var _a, _b, _c;
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
25
|
let generateMipMaps = false;
|
|
26
26
|
let generateDepthBuffer = true;
|
|
27
27
|
let generateStencilBuffer = false;
|
|
@@ -76,6 +76,7 @@ WebGPUEngine.prototype.createMultipleRenderTarget = function (size, options, ini
|
|
|
76
76
|
}
|
|
77
77
|
labels = (_b = options.labels) !== null && _b !== void 0 ? _b : labels;
|
|
78
78
|
}
|
|
79
|
+
rtWrapper.label = (_c = options === null || options === void 0 ? void 0 : options.label) !== null && _c !== void 0 ? _c : "MultiRenderTargetWrapper";
|
|
79
80
|
const width = size.width || size;
|
|
80
81
|
const height = size.height || size;
|
|
81
82
|
let depthStencilTexture = null;
|
|
@@ -108,7 +109,7 @@ WebGPUEngine.prototype.createMultipleRenderTarget = function (size, options, ini
|
|
|
108
109
|
const format = formats[i] || defaultFormat;
|
|
109
110
|
const useSRGBBuffer = (useSRGBBuffers[i] || defaultUseSRGBBuffer) && this._caps.supportSRGBBuffers;
|
|
110
111
|
const target = targets[i] || defaultTarget;
|
|
111
|
-
const layerCount = (
|
|
112
|
+
const layerCount = (_d = layers[i]) !== null && _d !== void 0 ? _d : 1;
|
|
112
113
|
if (type === 1 && !this._caps.textureFloatLinearFiltering) {
|
|
113
114
|
// if floating point linear (FLOAT) then force to NEAREST_SAMPLINGMODE
|
|
114
115
|
samplingMode = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.multiRender.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Engines/WebGPU/Extensions/engine.multiRender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAErG,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,SA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AS,CAAC,oBAAoB,IAAI,CAAC,yBAAyB,EAAE;QAC9D,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,SAAS,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;QAC/E,SAAS,CAAC,oBAAoB,CAAC,OAAO,GAAG,OAAO,CAAC;KACpD;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,eAAe,GAAG,UAAU,WAAqB;IACpE,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;QACxD,OAAO;KACV;IAED,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC;IACnC,IAAI,IAAI,CAAC,kBAAkB,EAAE;QACzB,qHAAqH;QACrH,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;KAC5D;SAAM;QACH,uLAAuL;KAC1L;AACL,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,kBAAkB,GAAG,UAAU,aAAwB;IAC1E,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC3C,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;SACtB;aAAM;YACH,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAClB;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,uBAAuB,GAAG;IAC7C,mKAAmK;AACvK,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,sCAAsC,GAAG;IAC5D,oJAAoJ;AACxJ,CAAC,CAAC","sourcesContent":["import { InternalTexture, InternalTextureSource } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IMultiRenderTargetOptions } from \"../../../Materials/Textures/multiRenderTarget\";\r\nimport { Logger } from \"../../../Misc/logger\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { Constants } from \"../../constants\";\r\nimport type { TextureSize } from \"../../../Materials/Textures/textureCreationOptions\";\r\nimport type { RenderTargetWrapper } from \"../../renderTargetWrapper\";\r\nimport { WebGPUEngine } from \"../../webgpuEngine\";\r\nimport type { WebGPURenderTargetWrapper } from \"../webgpuRenderTargetWrapper\";\r\nimport type { WebGPUHardwareTexture } from \"../webgpuHardwareTexture\";\r\n\r\nWebGPUEngine.prototype.unBindMultiColorAttachmentFramebuffer = function (\r\n rtWrapper: RenderTargetWrapper,\r\n disableGenerateMipMaps: boolean = false,\r\n onBeforeUnbind?: () => void\r\n): void {\r\n if (onBeforeUnbind) {\r\n onBeforeUnbind();\r\n }\r\n\r\n const attachments = rtWrapper._attachments!;\r\n const count = attachments.length;\r\n\r\n this._endCurrentRenderPass();\r\n\r\n for (let i = 0; i < count; i++) {\r\n const texture = rtWrapper.textures![i];\r\n if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {\r\n this._generateMipmaps(texture);\r\n }\r\n }\r\n\r\n this._currentRenderTarget = null;\r\n\r\n this._mrtAttachments = [];\r\n this._cacheRenderPipeline.setMRT([]);\r\n this._cacheRenderPipeline.setMRTAttachments(this._mrtAttachments);\r\n};\r\n\r\nWebGPUEngine.prototype.createMultipleRenderTarget = function (size: TextureSize, options: IMultiRenderTargetOptions, initializeBuffers?: boolean): RenderTargetWrapper {\r\n let generateMipMaps = false;\r\n let generateDepthBuffer = true;\r\n let generateStencilBuffer = false;\r\n let generateDepthTexture = false;\r\n let depthTextureFormat = Constants.TEXTUREFORMAT_DEPTH16;\r\n let textureCount = 1;\r\n\r\n const defaultType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n const defaultSamplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;\r\n const defaultUseSRGBBuffer = false;\r\n const defaultFormat = Constants.TEXTUREFORMAT_RGBA;\r\n const defaultTarget = Constants.TEXTURE_2D;\r\n\r\n let types: number[] = [];\r\n let samplingModes: number[] = [];\r\n let useSRGBBuffers: boolean[] = [];\r\n let formats: number[] = [];\r\n let targets: number[] = [];\r\n let faceIndex: number[] = [];\r\n let layerIndex: number[] = [];\r\n let layers: number[] = [];\r\n let labels: string[] = [];\r\n\r\n const rtWrapper = this._createHardwareRenderTargetWrapper(true, false, size) as WebGPURenderTargetWrapper;\r\n\r\n if (options !== undefined) {\r\n generateMipMaps = options.generateMipMaps === undefined ? false : options.generateMipMaps;\r\n generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;\r\n generateStencilBuffer = options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;\r\n generateDepthTexture = options.generateDepthTexture === undefined ? false : options.generateDepthTexture;\r\n textureCount = options.textureCount || 1;\r\n depthTextureFormat = options.depthTextureFormat ?? Constants.TEXTUREFORMAT_DEPTH16;\r\n\r\n if (options.types) {\r\n types = options.types;\r\n }\r\n if (options.samplingModes) {\r\n samplingModes = options.samplingModes;\r\n }\r\n if (options.useSRGBBuffers) {\r\n useSRGBBuffers = options.useSRGBBuffers;\r\n }\r\n if (options.formats) {\r\n formats = options.formats;\r\n }\r\n if (options.targetTypes) {\r\n targets = options.targetTypes;\r\n }\r\n if (options.faceIndex) {\r\n faceIndex = options.faceIndex;\r\n }\r\n if (options.layerIndex) {\r\n layerIndex = options.layerIndex;\r\n }\r\n if (options.layerCounts) {\r\n layers = options.layerCounts;\r\n }\r\n\r\n labels = options.labels ?? labels;\r\n }\r\n\r\n const width = (<{ width: number; height: number }>size).width || <number>size;\r\n const height = (<{ width: number; height: number }>size).height || <number>size;\r\n\r\n let depthStencilTexture = null;\r\n if (generateDepthBuffer || generateStencilBuffer || generateDepthTexture) {\r\n if (!generateDepthTexture) {\r\n // The caller doesn't want a depth texture, so we are free to use the depth texture format we want.\r\n // So, we will align with what the WebGL engine does\r\n if (generateDepthBuffer && generateStencilBuffer) {\r\n depthTextureFormat = Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\r\n } else if (generateDepthBuffer) {\r\n depthTextureFormat = Constants.TEXTUREFORMAT_DEPTH32_FLOAT;\r\n } else {\r\n depthTextureFormat = Constants.TEXTUREFORMAT_STENCIL8;\r\n }\r\n }\r\n depthStencilTexture = rtWrapper.createDepthStencilTexture(0, false, generateStencilBuffer, 1, depthTextureFormat, \"MultipleRenderTargetDepthStencil\");\r\n }\r\n\r\n const textures: InternalTexture[] = [];\r\n const attachments: number[] = [];\r\n const defaultAttachments: number[] = [];\r\n\r\n rtWrapper._generateDepthBuffer = generateDepthBuffer;\r\n rtWrapper._generateStencilBuffer = generateStencilBuffer;\r\n rtWrapper._attachments = attachments;\r\n rtWrapper._defaultAttachments = defaultAttachments;\r\n\r\n for (let i = 0; i < textureCount; i++) {\r\n let samplingMode = samplingModes[i] || defaultSamplingMode;\r\n let type = types[i] || defaultType;\r\n\r\n const format = formats[i] || defaultFormat;\r\n const useSRGBBuffer = (useSRGBBuffers[i] || defaultUseSRGBBuffer) && this._caps.supportSRGBBuffers;\r\n\r\n const target = targets[i] || defaultTarget;\r\n const layerCount = layers[i] ?? 1;\r\n\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {\r\n // if floating point linear (FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n } else if (type === Constants.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {\r\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n }\r\n\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n Logger.Warn(\"Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type\");\r\n }\r\n\r\n attachments.push(i + 1);\r\n defaultAttachments.push(initializeBuffers ? i + 1 : i === 0 ? 1 : 0);\r\n\r\n if (target === -1) {\r\n continue;\r\n }\r\n\r\n const texture = new InternalTexture(this, InternalTextureSource.MultiRenderTarget);\r\n textures[i] = texture;\r\n\r\n switch (target) {\r\n case Constants.TEXTURE_CUBE_MAP:\r\n texture.isCube = true;\r\n break;\r\n case Constants.TEXTURE_3D:\r\n texture.is3D = true;\r\n texture.baseDepth = texture.depth = layerCount;\r\n break;\r\n case Constants.TEXTURE_2D_ARRAY:\r\n texture.is2DArray = true;\r\n texture.baseDepth = texture.depth = layerCount;\r\n break;\r\n }\r\n\r\n texture.baseWidth = width;\r\n texture.baseHeight = height;\r\n texture.width = width;\r\n texture.height = height;\r\n texture.isReady = true;\r\n texture.samples = 1;\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n texture.type = type;\r\n texture._cachedWrapU = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n texture._cachedWrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n texture._useSRGBBuffer = useSRGBBuffer;\r\n texture.format = format;\r\n texture.label = labels[i];\r\n\r\n this._internalTexturesCache.push(texture);\r\n\r\n this._textureHelper.createGPUTextureForInternalTexture(texture);\r\n }\r\n\r\n if (depthStencilTexture) {\r\n depthStencilTexture.incrementReferences();\r\n textures[textureCount] = depthStencilTexture;\r\n this._internalTexturesCache.push(depthStencilTexture);\r\n }\r\n\r\n rtWrapper.setTextures(textures);\r\n rtWrapper.setLayerAndFaceIndices(layerIndex, faceIndex);\r\n\r\n return rtWrapper;\r\n};\r\n\r\nWebGPUEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function (rtWrapper: Nullable<RenderTargetWrapper>, samples: number): number {\r\n if (!rtWrapper || !rtWrapper.textures || rtWrapper.textures[0].samples === samples) {\r\n return samples;\r\n }\r\n\r\n const count = rtWrapper.textures.length;\r\n\r\n if (count === 0) {\r\n return 1;\r\n }\r\n\r\n samples = Math.min(samples, this.getCaps().maxMSAASamples);\r\n\r\n for (let i = 0; i < count; ++i) {\r\n const texture = rtWrapper.textures[i];\r\n const gpuTextureWrapper = texture._hardwareTexture as Nullable<WebGPUHardwareTexture>;\r\n\r\n gpuTextureWrapper?.releaseMSAATexture();\r\n }\r\n\r\n // Note that rtWrapper.textures can't have null textures, lastTextureIsDepthTexture can't be true if rtWrapper._depthStencilTexture is null\r\n const lastTextureIsDepthTexture = rtWrapper._depthStencilTexture === rtWrapper.textures[count - 1];\r\n\r\n for (let i = 0; i < count; ++i) {\r\n const texture = rtWrapper.textures[i];\r\n this._textureHelper.createMSAATexture(texture, samples, false, i === count - 1 && lastTextureIsDepthTexture ? 0 : i);\r\n texture.samples = samples;\r\n }\r\n\r\n // Note that the last texture of textures is the depth texture if the depth texture has been generated by the MRT class and so the MSAA texture\r\n // will be recreated for this texture by the loop above: in that case, there's no need to create the MSAA texture for rtWrapper._depthStencilTexture\r\n // because rtWrapper._depthStencilTexture is the same texture than the depth texture\r\n if (rtWrapper._depthStencilTexture && !lastTextureIsDepthTexture) {\r\n this._textureHelper.createMSAATexture(rtWrapper._depthStencilTexture, samples);\r\n rtWrapper._depthStencilTexture.samples = samples;\r\n }\r\n\r\n return samples;\r\n};\r\n\r\nWebGPUEngine.prototype.bindAttachments = function (attachments: number[]): void {\r\n if (attachments.length === 0 || !this._currentRenderTarget) {\r\n return;\r\n }\r\n\r\n this._mrtAttachments = attachments;\r\n if (this._currentRenderPass) {\r\n // the render pass has already been created, we need to call setMRTAttachments to update the state of the attachments\r\n this._cacheRenderPipeline.setMRTAttachments(attachments);\r\n } else {\r\n // the render pass is not created yet so we don't need to call setMRTAttachments: it will be called as part of the render pass creation (see WebGPUEngine._startRenderTargetRenderPass)\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype.buildTextureLayout = function (textureStatus: boolean[]): number[] {\r\n const result = [];\r\n\r\n for (let i = 0; i < textureStatus.length; i++) {\r\n if (textureStatus[i]) {\r\n result.push(i + 1);\r\n } else {\r\n result.push(0);\r\n }\r\n }\r\n\r\n return result;\r\n};\r\n\r\nWebGPUEngine.prototype.restoreSingleAttachment = function (): void {\r\n // not sure what to do, probably nothing... This function and restoreSingleAttachmentForRenderTarget are not called in Babylon.js so it's hard to know the use case\r\n};\r\n\r\nWebGPUEngine.prototype.restoreSingleAttachmentForRenderTarget = function (): void {\r\n // not sure what to do, probably nothing... This function and restoreSingleAttachment are not called in Babylon.js so it's hard to know the use case\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"engine.multiRender.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Engines/WebGPU/Extensions/engine.multiRender.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAErG,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,YAAY,CAAC,SAAS,CAAC,qCAAqC,GAAG,UAC3D,SAA8B,EAC9B,yBAAkC,KAAK,EACvC,cAA2B;IAE3B,IAAI,cAAc,EAAE;QAChB,cAAc,EAAE,CAAC;KACpB;IAED,MAAM,WAAW,GAAG,SAAS,CAAC,YAAa,CAAC;IAC5C,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC;IAEjC,IAAI,CAAC,qBAAqB,EAAE,CAAC;IAE7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;QAC5B,MAAM,OAAO,GAAG,SAAS,CAAC,QAAS,CAAC,CAAC,CAAC,CAAC;QACvC,IAAI,OAAO,CAAC,eAAe,IAAI,CAAC,sBAAsB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACvE,IAAI,CAAC,gBAAgB,CAAC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W,CAAC,CAAC;KAC5D;SAAM;QACH,uLAAuL;KAC1L;AACL,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,kBAAkB,GAAG,UAAU,aAAwB;IAC1E,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC3C,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;SACtB;aAAM;YACH,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAClB;KACJ;IAED,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,uBAAuB,GAAG;IAC7C,mKAAmK;AACvK,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,sCAAsC,GAAG;IAC5D,oJAAoJ;AACxJ,CAAC,CAAC","sourcesContent":["import { InternalTexture, InternalTextureSource } from \"../../../Materials/Textures/internalTexture\";\r\nimport type { IMultiRenderTargetOptions } from \"../../../Materials/Textures/multiRenderTarget\";\r\nimport { Logger } from \"../../../Misc/logger\";\r\nimport type { Nullable } from \"../../../types\";\r\nimport { Constants } from \"../../constants\";\r\nimport type { TextureSize } from \"../../../Materials/Textures/textureCreationOptions\";\r\nimport type { RenderTargetWrapper } from \"../../renderTargetWrapper\";\r\nimport { WebGPUEngine } from \"../../webgpuEngine\";\r\nimport type { WebGPURenderTargetWrapper } from \"../webgpuRenderTargetWrapper\";\r\nimport type { WebGPUHardwareTexture } from \"../webgpuHardwareTexture\";\r\n\r\nWebGPUEngine.prototype.unBindMultiColorAttachmentFramebuffer = function (\r\n rtWrapper: RenderTargetWrapper,\r\n disableGenerateMipMaps: boolean = false,\r\n onBeforeUnbind?: () => void\r\n): void {\r\n if (onBeforeUnbind) {\r\n onBeforeUnbind();\r\n }\r\n\r\n const attachments = rtWrapper._attachments!;\r\n const count = attachments.length;\r\n\r\n this._endCurrentRenderPass();\r\n\r\n for (let i = 0; i < count; i++) {\r\n const texture = rtWrapper.textures![i];\r\n if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {\r\n this._generateMipmaps(texture);\r\n }\r\n }\r\n\r\n this._currentRenderTarget = null;\r\n\r\n this._mrtAttachments = [];\r\n this._cacheRenderPipeline.setMRT([]);\r\n this._cacheRenderPipeline.setMRTAttachments(this._mrtAttachments);\r\n};\r\n\r\nWebGPUEngine.prototype.createMultipleRenderTarget = function (size: TextureSize, options: IMultiRenderTargetOptions, initializeBuffers?: boolean): RenderTargetWrapper {\r\n let generateMipMaps = false;\r\n let generateDepthBuffer = true;\r\n let generateStencilBuffer = false;\r\n let generateDepthTexture = false;\r\n let depthTextureFormat = Constants.TEXTUREFORMAT_DEPTH16;\r\n let textureCount = 1;\r\n\r\n const defaultType = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n const defaultSamplingMode = Constants.TEXTURE_TRILINEAR_SAMPLINGMODE;\r\n const defaultUseSRGBBuffer = false;\r\n const defaultFormat = Constants.TEXTUREFORMAT_RGBA;\r\n const defaultTarget = Constants.TEXTURE_2D;\r\n\r\n let types: number[] = [];\r\n let samplingModes: number[] = [];\r\n let useSRGBBuffers: boolean[] = [];\r\n let formats: number[] = [];\r\n let targets: number[] = [];\r\n let faceIndex: number[] = [];\r\n let layerIndex: number[] = [];\r\n let layers: number[] = [];\r\n let labels: string[] = [];\r\n\r\n const rtWrapper = this._createHardwareRenderTargetWrapper(true, false, size) as WebGPURenderTargetWrapper;\r\n\r\n if (options !== undefined) {\r\n generateMipMaps = options.generateMipMaps === undefined ? false : options.generateMipMaps;\r\n generateDepthBuffer = options.generateDepthBuffer === undefined ? true : options.generateDepthBuffer;\r\n generateStencilBuffer = options.generateStencilBuffer === undefined ? false : options.generateStencilBuffer;\r\n generateDepthTexture = options.generateDepthTexture === undefined ? false : options.generateDepthTexture;\r\n textureCount = options.textureCount || 1;\r\n depthTextureFormat = options.depthTextureFormat ?? Constants.TEXTUREFORMAT_DEPTH16;\r\n\r\n if (options.types) {\r\n types = options.types;\r\n }\r\n if (options.samplingModes) {\r\n samplingModes = options.samplingModes;\r\n }\r\n if (options.useSRGBBuffers) {\r\n useSRGBBuffers = options.useSRGBBuffers;\r\n }\r\n if (options.formats) {\r\n formats = options.formats;\r\n }\r\n if (options.targetTypes) {\r\n targets = options.targetTypes;\r\n }\r\n if (options.faceIndex) {\r\n faceIndex = options.faceIndex;\r\n }\r\n if (options.layerIndex) {\r\n layerIndex = options.layerIndex;\r\n }\r\n if (options.layerCounts) {\r\n layers = options.layerCounts;\r\n }\r\n\r\n labels = options.labels ?? labels;\r\n }\r\n\r\n rtWrapper.label = options?.label ?? \"MultiRenderTargetWrapper\";\r\n\r\n const width = (<{ width: number; height: number }>size).width || <number>size;\r\n const height = (<{ width: number; height: number }>size).height || <number>size;\r\n\r\n let depthStencilTexture = null;\r\n if (generateDepthBuffer || generateStencilBuffer || generateDepthTexture) {\r\n if (!generateDepthTexture) {\r\n // The caller doesn't want a depth texture, so we are free to use the depth texture format we want.\r\n // So, we will align with what the WebGL engine does\r\n if (generateDepthBuffer && generateStencilBuffer) {\r\n depthTextureFormat = Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\r\n } else if (generateDepthBuffer) {\r\n depthTextureFormat = Constants.TEXTUREFORMAT_DEPTH32_FLOAT;\r\n } else {\r\n depthTextureFormat = Constants.TEXTUREFORMAT_STENCIL8;\r\n }\r\n }\r\n depthStencilTexture = rtWrapper.createDepthStencilTexture(0, false, generateStencilBuffer, 1, depthTextureFormat, \"MultipleRenderTargetDepthStencil\");\r\n }\r\n\r\n const textures: InternalTexture[] = [];\r\n const attachments: number[] = [];\r\n const defaultAttachments: number[] = [];\r\n\r\n rtWrapper._generateDepthBuffer = generateDepthBuffer;\r\n rtWrapper._generateStencilBuffer = generateStencilBuffer;\r\n rtWrapper._attachments = attachments;\r\n rtWrapper._defaultAttachments = defaultAttachments;\r\n\r\n for (let i = 0; i < textureCount; i++) {\r\n let samplingMode = samplingModes[i] || defaultSamplingMode;\r\n let type = types[i] || defaultType;\r\n\r\n const format = formats[i] || defaultFormat;\r\n const useSRGBBuffer = (useSRGBBuffers[i] || defaultUseSRGBBuffer) && this._caps.supportSRGBBuffers;\r\n\r\n const target = targets[i] || defaultTarget;\r\n const layerCount = layers[i] ?? 1;\r\n\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {\r\n // if floating point linear (FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n } else if (type === Constants.TEXTURETYPE_HALF_FLOAT && !this._caps.textureHalfFloatLinearFiltering) {\r\n // if floating point linear (HALF_FLOAT) then force to NEAREST_SAMPLINGMODE\r\n samplingMode = Constants.TEXTURE_NEAREST_SAMPLINGMODE;\r\n }\r\n\r\n if (type === Constants.TEXTURETYPE_FLOAT && !this._caps.textureFloat) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n Logger.Warn(\"Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type\");\r\n }\r\n\r\n attachments.push(i + 1);\r\n defaultAttachments.push(initializeBuffers ? i + 1 : i === 0 ? 1 : 0);\r\n\r\n if (target === -1) {\r\n continue;\r\n }\r\n\r\n const texture = new InternalTexture(this, InternalTextureSource.MultiRenderTarget);\r\n textures[i] = texture;\r\n\r\n switch (target) {\r\n case Constants.TEXTURE_CUBE_MAP:\r\n texture.isCube = true;\r\n break;\r\n case Constants.TEXTURE_3D:\r\n texture.is3D = true;\r\n texture.baseDepth = texture.depth = layerCount;\r\n break;\r\n case Constants.TEXTURE_2D_ARRAY:\r\n texture.is2DArray = true;\r\n texture.baseDepth = texture.depth = layerCount;\r\n break;\r\n }\r\n\r\n texture.baseWidth = width;\r\n texture.baseHeight = height;\r\n texture.width = width;\r\n texture.height = height;\r\n texture.isReady = true;\r\n texture.samples = 1;\r\n texture.generateMipMaps = generateMipMaps;\r\n texture.samplingMode = samplingMode;\r\n texture.type = type;\r\n texture._cachedWrapU = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n texture._cachedWrapV = Constants.TEXTURE_CLAMP_ADDRESSMODE;\r\n texture._useSRGBBuffer = useSRGBBuffer;\r\n texture.format = format;\r\n texture.label = labels[i];\r\n\r\n this._internalTexturesCache.push(texture);\r\n\r\n this._textureHelper.createGPUTextureForInternalTexture(texture);\r\n }\r\n\r\n if (depthStencilTexture) {\r\n depthStencilTexture.incrementReferences();\r\n textures[textureCount] = depthStencilTexture;\r\n this._internalTexturesCache.push(depthStencilTexture);\r\n }\r\n\r\n rtWrapper.setTextures(textures);\r\n rtWrapper.setLayerAndFaceIndices(layerIndex, faceIndex);\r\n\r\n return rtWrapper;\r\n};\r\n\r\nWebGPUEngine.prototype.updateMultipleRenderTargetTextureSampleCount = function (rtWrapper: Nullable<RenderTargetWrapper>, samples: number): number {\r\n if (!rtWrapper || !rtWrapper.textures || rtWrapper.textures[0].samples === samples) {\r\n return samples;\r\n }\r\n\r\n const count = rtWrapper.textures.length;\r\n\r\n if (count === 0) {\r\n return 1;\r\n }\r\n\r\n samples = Math.min(samples, this.getCaps().maxMSAASamples);\r\n\r\n for (let i = 0; i < count; ++i) {\r\n const texture = rtWrapper.textures[i];\r\n const gpuTextureWrapper = texture._hardwareTexture as Nullable<WebGPUHardwareTexture>;\r\n\r\n gpuTextureWrapper?.releaseMSAATexture();\r\n }\r\n\r\n // Note that rtWrapper.textures can't have null textures, lastTextureIsDepthTexture can't be true if rtWrapper._depthStencilTexture is null\r\n const lastTextureIsDepthTexture = rtWrapper._depthStencilTexture === rtWrapper.textures[count - 1];\r\n\r\n for (let i = 0; i < count; ++i) {\r\n const texture = rtWrapper.textures[i];\r\n this._textureHelper.createMSAATexture(texture, samples, false, i === count - 1 && lastTextureIsDepthTexture ? 0 : i);\r\n texture.samples = samples;\r\n }\r\n\r\n // Note that the last texture of textures is the depth texture if the depth texture has been generated by the MRT class and so the MSAA texture\r\n // will be recreated for this texture by the loop above: in that case, there's no need to create the MSAA texture for rtWrapper._depthStencilTexture\r\n // because rtWrapper._depthStencilTexture is the same texture than the depth texture\r\n if (rtWrapper._depthStencilTexture && !lastTextureIsDepthTexture) {\r\n this._textureHelper.createMSAATexture(rtWrapper._depthStencilTexture, samples);\r\n rtWrapper._depthStencilTexture.samples = samples;\r\n }\r\n\r\n return samples;\r\n};\r\n\r\nWebGPUEngine.prototype.bindAttachments = function (attachments: number[]): void {\r\n if (attachments.length === 0 || !this._currentRenderTarget) {\r\n return;\r\n }\r\n\r\n this._mrtAttachments = attachments;\r\n if (this._currentRenderPass) {\r\n // the render pass has already been created, we need to call setMRTAttachments to update the state of the attachments\r\n this._cacheRenderPipeline.setMRTAttachments(attachments);\r\n } else {\r\n // the render pass is not created yet so we don't need to call setMRTAttachments: it will be called as part of the render pass creation (see WebGPUEngine._startRenderTargetRenderPass)\r\n }\r\n};\r\n\r\nWebGPUEngine.prototype.buildTextureLayout = function (textureStatus: boolean[]): number[] {\r\n const result = [];\r\n\r\n for (let i = 0; i < textureStatus.length; i++) {\r\n if (textureStatus[i]) {\r\n result.push(i + 1);\r\n } else {\r\n result.push(0);\r\n }\r\n }\r\n\r\n return result;\r\n};\r\n\r\nWebGPUEngine.prototype.restoreSingleAttachment = function (): void {\r\n // not sure what to do, probably nothing... This function and restoreSingleAttachmentForRenderTarget are not called in Babylon.js so it's hard to know the use case\r\n};\r\n\r\nWebGPUEngine.prototype.restoreSingleAttachmentForRenderTarget = function (): void {\r\n // not sure what to do, probably nothing... This function and restoreSingleAttachment are not called in Babylon.js so it's hard to know the use case\r\n};\r\n"]}
|
|
@@ -60,7 +60,14 @@ WebGPUEngine.prototype.readFromStorageBuffer = function (storageBuffer, offset,
|
|
|
60
60
|
gpuBuffer.unmap();
|
|
61
61
|
this._bufferManager.releaseBuffer(gpuBuffer);
|
|
62
62
|
resolve(data);
|
|
63
|
-
}, (reason) =>
|
|
63
|
+
}, (reason) => {
|
|
64
|
+
if (this.isDisposed) {
|
|
65
|
+
resolve(new Uint8Array());
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
reject(reason);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
64
71
|
};
|
|
65
72
|
if (noDelay) {
|
|
66
73
|
this.flushFramebuffer();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.storageBuffer.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Engines/WebGPU/Extensions/engine.storageBuffer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAgBnD,MAAM,CAAC,SAAS,CAAC,gBAAgB,GAAG,UAAU,IAAY,EAAE,MAA+B;IACvF,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,mBAAmB,GAAG,UAAU,IAAwB,EAAE,aAAqB,EAAE,KAAc;IAClH,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;AAClG,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,mBAAmB,GAAG,UAAU,MAAkB,EAAE,IAAe,EAAE,UAAmB,EAAE,UAAmB;IAChI,MAAM,UAAU,GAAG,MAA0B,CAAC;IAC9C,IAAI,UAAU,KAAK,SAAS,EAAE;QAC1B,UAAU,GAAG,CAAC,CAAC;KAClB;IAED,IAAI,IAAqB,CAAC;IAC1B,IAAI,UAAU,KAAK,SAAS,E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,MAAM,cAAc,GAAG,GAAG,EAAE;YACxB,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAC1D,GAAG,EAAE;gBACD,MAAM,eAAe,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;gBAC1D,IAAI,IAAI,GAAgC,MAAM,CAAC;gBAC/C,IAAI,IAAI,KAAK,SAAS,EAAE;oBACpB,IAAI,GAAG,IAAI,UAAU,CAAC,IAAK,CAAC,CAAC;oBAC5B,IAAmB,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;iBAC7D;qBAAM;oBACH,MAAM,IAAI,GAAG,IAAI,CAAC,WAAkB,CAAC,CAAC,6FAA6F;oBACnI,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC5B,IAAY,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;iBAChD;gBACD,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;gBAC7C,OAAO,CAAC,IAAK,CAAC,CAAC;YACnB,CAAC,EACD,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"engine.storageBuffer.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Engines/WebGPU/Extensions/engine.storageBuffer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAgBnD,MAAM,CAAC,SAAS,CAAC,gBAAg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AC,eAAe,CAAC,CAAC,CAAC;iBAChD;gBACD,SAAS,CAAC,KAAK,EAAE,CAAC;gBAClB,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;gBAC7C,OAAO,CAAC,IAAK,CAAC,CAAC;YACnB,CAAC,EACD,CAAC,MAAM,EAAE,EAAE;gBACP,IAAI,IAAI,CAAC,UAAU,EAAE;oBACjB,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;iBAC7B;qBAAM;oBACH,MAAM,CAAC,MAAM,CAAC,CAAC;iBAClB;YACL,CAAC,CACJ,CAAC;QACN,CAAC,CAAC;QAEF,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxB,cAAc,EAAE,CAAC;SACpB;aAAM;YACH,mGAAmG;YACnG,qFAAqF;YACrF,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,GAAG,EAAE;gBACnC,cAAc,EAAE,CAAC;YACrB,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,YAAY,CAAC,SAAS,CAAC,gBAAgB,GAAG,UAAU,IAAY,EAAE,MAA+B;;IAC7F,MAAA,IAAI,CAAC,mBAAmB,0CAAE,SAAS,CAAC,IAAI,EAAE,MAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,EAAuB,mCAAI,IAAI,CAAC,CAAC;AACjG,CAAC,CAAC","sourcesContent":["import type { DataBuffer } from \"../../../Buffers/dataBuffer\";\r\nimport type { WebGPUDataBuffer } from \"../../../Meshes/WebGPU/webgpuDataBuffer\";\r\nimport type { DataArray, Nullable } from \"../../../types\";\r\nimport { Constants } from \"../../constants\";\r\nimport { WebGPUEngine } from \"../../webgpuEngine\";\r\nimport * as WebGPUConstants from \"../webgpuConstants\";\r\nimport { Effect } from \"../../../Materials/effect\";\r\n\r\nimport type { StorageBuffer } from \"../../../Buffers/storageBuffer\";\r\n\r\ndeclare module \"../../../Materials/effect\" {\r\n export interface Effect {\r\n /**\r\n * Sets a storage buffer on the engine to be used in the shader.\r\n * @param name Name of the storage buffer variable.\r\n * @param buffer Storage buffer to set.\r\n * @param label defines the label of the buffer (for debug purpose)\r\n */\r\n setStorageBuffer(name: string, buffer: Nullable<StorageBuffer>, label?: string): void;\r\n }\r\n}\r\n\r\nEffect.prototype.setStorageBuffer = function (name: string, buffer: Nullable<StorageBuffer>): void {\r\n this._engine.setStorageBuffer(name, buffer);\r\n};\r\n\r\nWebGPUEngine.prototype.createStorageBuffer = function (data: DataArray | number, creationFlags: number, label?: string): DataBuffer {\r\n return this._createBuffer(data, creationFlags | Constants.BUFFER_CREATIONFLAG_STORAGE, label);\r\n};\r\n\r\nWebGPUEngine.prototype.updateStorageBuffer = function (buffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void {\r\n const dataBuffer = buffer as WebGPUDataBuffer;\r\n if (byteOffset === undefined) {\r\n byteOffset = 0;\r\n }\r\n\r\n let view: ArrayBufferView;\r\n if (byteLength === undefined) {\r\n if (data instanceof Array) {\r\n view = new Float32Array(data);\r\n } else if (data instanceof ArrayBuffer) {\r\n view = new Uint8Array(data);\r\n } else {\r\n view = data;\r\n }\r\n byteLength = view.byteLength;\r\n } else {\r\n if (data instanceof Array) {\r\n view = new Float32Array(data);\r\n } else if (data instanceof ArrayBuffer) {\r\n view = new Uint8Array(data);\r\n } else {\r\n view = data;\r\n }\r\n }\r\n\r\n this._bufferManager.setSubData(dataBuffer, byteOffset, view, 0, byteLength);\r\n};\r\n\r\nWebGPUEngine.prototype.readFromStorageBuffer = function (\r\n storageBuffer: DataBuffer,\r\n offset?: number,\r\n size?: number,\r\n buffer?: ArrayBufferView,\r\n noDelay?: boolean\r\n): Promise<ArrayBufferView> {\r\n size = size || storageBuffer.capacity;\r\n\r\n const gpuBuffer = this._bufferManager.createRawBuffer(size, WebGPUConstants.BufferUsage.MapRead | WebGPUConstants.BufferUsage.CopyDst, undefined, \"TempReadFromStorageBuffer\");\r\n\r\n this._renderEncoder.copyBufferToBuffer(storageBuffer.underlyingResource, offset ?? 0, gpuBuffer, 0, size);\r\n\r\n return new Promise((resolve, reject) => {\r\n const readFromBuffer = () => {\r\n gpuBuffer.mapAsync(WebGPUConstants.MapMode.Read, 0, size).then(\r\n () => {\r\n const copyArrayBuffer = gpuBuffer.getMappedRange(0, size);\r\n let data: ArrayBufferView | undefined = buffer;\r\n if (data === undefined) {\r\n data = new Uint8Array(size!);\r\n (data as Uint8Array).set(new Uint8Array(copyArrayBuffer));\r\n } else {\r\n const ctor = data.constructor as any; // we want to create result data with the same type as buffer (Uint8Array, Float32Array, ...)\r\n data = new ctor(data.buffer);\r\n (data as any).set(new ctor(copyArrayBuffer));\r\n }\r\n gpuBuffer.unmap();\r\n this._bufferManager.releaseBuffer(gpuBuffer);\r\n resolve(data!);\r\n },\r\n (reason) => {\r\n if (this.isDisposed) {\r\n resolve(new Uint8Array());\r\n } else {\r\n reject(reason);\r\n }\r\n }\r\n );\r\n };\r\n\r\n if (noDelay) {\r\n this.flushFramebuffer();\r\n readFromBuffer();\r\n } else {\r\n // we are using onEndFrameObservable because we need to map the gpuBuffer AFTER the command buffers\r\n // have been submitted, else we get the error: \"Buffer used in a submit while mapped\"\r\n this.onEndFrameObservable.addOnce(() => {\r\n readFromBuffer();\r\n });\r\n }\r\n });\r\n};\r\n\r\nWebGPUEngine.prototype.setStorageBuffer = function (name: string, buffer: Nullable<StorageBuffer>): void {\r\n this._currentDrawContext?.setBuffer(name, (buffer?.getBuffer() as WebGPUDataBuffer) ?? null);\r\n};\r\n"]}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { DataBuffer } from "../../Buffers/dataBuffer";
|
|
2
2
|
import { WebGPUDataBuffer } from "../../Meshes/WebGPU/webgpuDataBuffer";
|
|
3
3
|
import type { Nullable } from "../../types";
|
|
4
|
+
import type { WebGPUEngine } from "../webgpuEngine";
|
|
4
5
|
/** @internal */
|
|
5
6
|
export declare class WebGPUBufferManager {
|
|
7
|
+
private _engine;
|
|
6
8
|
private _device;
|
|
7
9
|
private _deferredReleaseBuffers;
|
|
8
10
|
private static _IsGPUBuffer;
|
|
9
11
|
private static _FlagsToString;
|
|
10
|
-
constructor(device: GPUDevice);
|
|
12
|
+
constructor(engine: WebGPUEngine, device: GPUDevice);
|
|
11
13
|
createRawBuffer(viewOrSize: ArrayBufferView | number, flags: GPUBufferUsageFlags, mappedAtCreation?: boolean, label?: string): GPUBuffer;
|
|
12
14
|
createBuffer(viewOrSize: ArrayBufferView | number, flags: GPUBufferUsageFlags, label?: string): WebGPUDataBuffer;
|
|
13
15
|
setRawData(buffer: GPUBuffer, dstByteOffset: number, src: ArrayBufferView, srcByteOffset: number, byteLength: number): void;
|
|
@@ -20,8 +20,9 @@ export class WebGPUBufferManager {
|
|
|
20
20
|
}
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
|
-
constructor(device) {
|
|
23
|
+
constructor(engine, device) {
|
|
24
24
|
this._deferredReleaseBuffers = [];
|
|
25
|
+
this._engine = engine;
|
|
25
26
|
this._device = device;
|
|
26
27
|
}
|
|
27
28
|
createRawBuffer(viewOrSize, flags, mappedAtCreation = false, label) {
|
|
@@ -160,7 +161,14 @@ export class WebGPUBufferManager {
|
|
|
160
161
|
this.releaseBuffer(gpuBuffer);
|
|
161
162
|
}
|
|
162
163
|
resolve(data);
|
|
163
|
-
}, (reason) =>
|
|
164
|
+
}, (reason) => {
|
|
165
|
+
if (this._engine.isDisposed) {
|
|
166
|
+
resolve(new Uint8Array());
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
reject(reason);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
164
172
|
});
|
|
165
173
|
}
|
|
166
174
|
releaseBuffer(buffer) {
|