@babylonjs/core 7.5.0 → 7.6.1
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/Audio/sound.js +3 -0
- package/Audio/sound.js.map +1 -1
- package/Bones/bone.js +1 -1
- package/Bones/bone.js.map +1 -1
- package/Buffers/storageBuffer.d.ts +2 -2
- package/Buffers/storageBuffer.js.map +1 -1
- package/Cameras/arcRotateCamera.js +3 -0
- package/Cameras/arcRotateCamera.js.map +1 -1
- package/Cameras/camera.js +1 -1
- package/Cameras/camera.js.map +1 -1
- package/Cameras/flyCamera.js +3 -0
- package/Cameras/flyCamera.js.map +1 -1
- package/Cameras/followCamera.js +4 -0
- package/Cameras/followCamera.js.map +1 -1
- package/Cameras/freeCamera.js +3 -0
- package/Cameras/freeCamera.js.map +1 -1
- package/Engines/Extensions/index.d.ts +0 -3
- package/Engines/Extensions/index.js +0 -3
- package/Engines/Extensions/index.js.map +1 -1
- package/Engines/WebGPU/Extensions/index.d.ts +0 -3
- package/Engines/WebGPU/Extensions/index.js +0 -3
- package/Engines/WebGPU/Extensions/index.js.map +1 -1
- package/Engines/abstractEngine.d.ts +0 -51
- package/Engines/abstractEngine.js +7 -3
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.js +5 -2
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.js +2 -2
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.functions.d.ts +0 -10
- package/Engines/thinEngine.functions.js +0 -19
- package/Engines/thinEngine.functions.js.map +1 -1
- package/Engines/thinEngine.js +18 -1
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.d.ts +54 -2
- package/Engines/webgpuEngine.js +147 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/Inputs/scene.inputManager.d.ts +1 -0
- package/Inputs/scene.inputManager.js +1 -0
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Lights/directionalLight.js +3 -0
- package/Lights/directionalLight.js.map +1 -1
- package/Lights/hemisphericLight.js +3 -0
- package/Lights/hemisphericLight.js.map +1 -1
- package/Lights/light.js +1 -1
- package/Lights/light.js.map +1 -1
- package/Lights/pointLight.js +3 -0
- package/Lights/pointLight.js.map +1 -1
- package/Lights/spotLight.js +3 -0
- package/Lights/spotLight.js.map +1 -1
- package/Materials/Node/Blocks/Dual/clipPlanesBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/clipPlanesBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/fogBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/imageSourceBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/imageSourceBlock.js +9 -3
- package/Materials/Node/Blocks/Dual/imageSourceBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/textureBlock.d.ts +2 -2
- package/Materials/Node/Blocks/Dual/textureBlock.js +13 -3
- package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/screenSizeBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Fragment/screenSizeBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/shadowMapBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Fragment/shadowMapBlock.js.map +1 -1
- package/Materials/Node/Blocks/Input/animatedInputBlockTypes.d.ts +2 -1
- package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js +1 -0
- package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js.map +1 -1
- package/Materials/Node/Blocks/Input/inputBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Input/inputBlock.js +16 -0
- package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.d.ts +1 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +1 -1
- package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.d.ts +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.d.ts +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/refractionBlock.d.ts +1 -1
- package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/lightInformationBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Vertex/lightInformationBlock.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/vertexOutputBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Vertex/vertexOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/baseMathBlock.js +2 -4
- package/Materials/Node/Blocks/baseMathBlock.js.map +1 -1
- package/Materials/Node/Blocks/triPlanarBlock.d.ts +1 -1
- package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
- package/Materials/Node/Blocks/trigonometryBlock.d.ts +3 -1
- package/Materials/Node/Blocks/trigonometryBlock.js +6 -0
- package/Materials/Node/Blocks/trigonometryBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +6 -3
- package/Materials/Node/nodeMaterial.js +9 -6
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterialBlock.d.ts +1 -1
- package/Materials/Node/nodeMaterialBlock.js +1 -1
- package/Materials/Node/nodeMaterialBlock.js.map +1 -1
- package/Materials/Node/nodeMaterialBlockConnectionPoint.d.ts +34 -14
- package/Materials/Node/nodeMaterialBlockConnectionPoint.js +87 -9
- package/Materials/Node/nodeMaterialBlockConnectionPoint.js.map +1 -1
- package/Materials/Node/nodeMaterialBuildState.d.ts +1 -1
- package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
- package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -1
- package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
- package/Materials/Textures/htmlElementTexture.d.ts +0 -1
- package/Materials/Textures/htmlElementTexture.js +7 -2
- package/Materials/Textures/htmlElementTexture.js.map +1 -1
- package/Materials/Textures/videoTexture.js +4 -2
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Materials/effect.functions.d.ts +1 -1
- package/Materials/effect.functions.js +4 -4
- package/Materials/effect.functions.js.map +1 -1
- package/Materials/effect.js +1 -1
- package/Materials/effect.js.map +1 -1
- package/Materials/effect.webgl.functions.js +2 -2
- package/Materials/effect.webgl.functions.js.map +1 -1
- package/Materials/imageProcessingConfiguration.js +3 -0
- package/Materials/imageProcessingConfiguration.js.map +1 -1
- package/Materials/materialPluginBase.js +3 -0
- package/Materials/materialPluginBase.js.map +1 -1
- package/Materials/shaderMaterial.js +18 -8
- package/Materials/shaderMaterial.js.map +1 -1
- package/Maths/math.color.d.ts +85 -82
- package/Maths/math.color.js +34 -27
- package/Maths/math.color.js.map +1 -1
- package/Maths/math.vector.d.ts +202 -202
- package/Maths/math.vector.js +133 -130
- package/Maths/math.vector.js.map +1 -1
- package/Maths/tensor.d.ts +44 -42
- package/Maths/tensor.js.map +1 -1
- package/Meshes/Compression/dracoCompression.d.ts +7 -0
- package/Meshes/Compression/dracoCompression.js +14 -0
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/instancedMesh.js +3 -0
- package/Meshes/instancedMesh.js.map +1 -1
- package/Meshes/transformNode.js +1 -1
- package/Meshes/transformNode.js.map +1 -1
- package/Misc/dumpTools.js +11 -0
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/fileTools.d.ts +9 -9
- package/Misc/fileTools.js +17 -15
- package/Misc/fileTools.js.map +1 -1
- package/Misc/tools.d.ts +5 -0
- package/Misc/tools.js +9 -0
- package/Misc/tools.js.map +1 -1
- package/Misc/typeStore.d.ts +4 -0
- package/Misc/typeStore.js +11 -0
- package/Misc/typeStore.js.map +1 -1
- package/NOTICE.md +8 -0
- package/Particles/baseParticleSystem.js +3 -0
- package/Particles/baseParticleSystem.js.map +1 -1
- package/Particles/computeShaderParticleSystem.d.ts +2 -2
- package/Particles/computeShaderParticleSystem.js.map +1 -1
- package/Physics/v1/Plugins/ammoJSPlugin.js +39 -10
- package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +3 -0
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +4 -0
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.d.ts +7 -0
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +40 -20
- package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -1
- package/Rendering/prePassRenderer.js +3 -0
- package/Rendering/prePassRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/screenSpaceRayTrace.js +8 -0
- package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
- package/Shaders/fluidRenderingRender.fragment.js +11 -2
- package/Shaders/fluidRenderingRender.fragment.js.map +1 -1
- package/Shaders/screenSpaceReflection2.fragment.js +7 -1
- package/Shaders/screenSpaceReflection2.fragment.js.map +1 -1
- package/Shaders/sprites.fragment.d.ts +2 -0
- package/Shaders/sprites.fragment.js +8 -1
- package/Shaders/sprites.fragment.js.map +1 -1
- package/Shaders/sprites.vertex.d.ts +2 -0
- package/Shaders/sprites.vertex.js +4 -0
- package/Shaders/sprites.vertex.js.map +1 -1
- package/Shaders/ssao2.fragment.js +1 -1
- package/Shaders/ssao2.fragment.js.map +1 -1
- package/Sprites/spriteManager.d.ts +3 -0
- package/Sprites/spriteManager.js +11 -0
- package/Sprites/spriteManager.js.map +1 -1
- package/Sprites/spriteRenderer.d.ts +11 -3
- package/Sprites/spriteRenderer.js +49 -32
- package/Sprites/spriteRenderer.js.map +1 -1
- package/XR/features/WebXRNearInteraction.d.ts +6 -0
- package/XR/features/WebXRNearInteraction.js +14 -2
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/webXRManagedOutputCanvas.d.ts +2 -0
- package/XR/webXRManagedOutputCanvas.js +14 -6
- package/XR/webXRManagedOutputCanvas.js.map +1 -1
- package/abstractScene.js +3 -0
- package/abstractScene.js.map +1 -1
- package/assets/glslang/glslang.js +113 -0
- package/assets/glslang/glslang.wasm +0 -0
- package/assets/twgsl/twgsl.js +53 -0
- package/assets/twgsl/twgsl.wasm +0 -0
- package/node.d.ts +2 -1
- package/node.js +5 -1
- package/node.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +3 -0
- package/scene.js.map +1 -1
- package/Engines/Extensions/engine.externalTexture.d.ts +0 -18
- package/Engines/Extensions/engine.externalTexture.js +0 -10
- package/Engines/Extensions/engine.externalTexture.js.map +0 -1
- package/Engines/Extensions/engine.storageBuffer.d.ts +0 -39
- package/Engines/Extensions/engine.storageBuffer.js +0 -16
- package/Engines/Extensions/engine.storageBuffer.js.map +0 -1
- package/Engines/Extensions/engine.textureSampler.d.ts +0 -12
- package/Engines/Extensions/engine.textureSampler.js +0 -6
- package/Engines/Extensions/engine.textureSampler.js.map +0 -1
- package/Engines/WebGPU/Extensions/engine.externalTexture.d.ts +0 -28
- package/Engines/WebGPU/Extensions/engine.externalTexture.js +0 -18
- package/Engines/WebGPU/Extensions/engine.externalTexture.js.map +0 -1
- package/Engines/WebGPU/Extensions/engine.storageBuffer.d.ts +0 -50
- package/Engines/WebGPU/Extensions/engine.storageBuffer.js +0 -88
- package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +0 -1
- package/Engines/WebGPU/Extensions/engine.textureSampler.d.ts +0 -22
- package/Engines/WebGPU/Extensions/engine.textureSampler.js +0 -9
- package/Engines/WebGPU/Extensions/engine.textureSampler.js.map +0 -1
|
@@ -10,7 +10,8 @@ import type { BaseTexture } from "../Materials/Textures/baseTexture";
|
|
|
10
10
|
import type { IShaderProcessor } from "./Processors/iShaderProcessor";
|
|
11
11
|
import type { ShaderProcessingContext } from "./Processors/shaderProcessingOptions";
|
|
12
12
|
import { WebGPUTextureManager } from "./WebGPU/webgpuTextureManager";
|
|
13
|
-
import {
|
|
13
|
+
import { AbstractEngine } from "./abstractEngine";
|
|
14
|
+
import type { ISceneLike, AbstractEngineOptions } from "./abstractEngine";
|
|
14
15
|
import { WebGPUBufferManager } from "./WebGPU/webgpuBufferManager";
|
|
15
16
|
import type { HardwareTextureWrapper } from "../Materials/Textures/hardwareTextureWrapper";
|
|
16
17
|
import { WebGPUHardwareTexture } from "./WebGPU/webgpuHardwareTexture";
|
|
@@ -36,7 +37,6 @@ import type { RenderTargetTexture } from "../Materials/Textures/renderTargetText
|
|
|
36
37
|
import type { RenderTargetWrapper } from "./renderTargetWrapper";
|
|
37
38
|
import { WebGPUPerfCounter } from "./WebGPU/webgpuPerfCounter";
|
|
38
39
|
import type { Scene } from "../scene";
|
|
39
|
-
import type { AbstractEngineOptions } from "./abstractEngine";
|
|
40
40
|
import type { PostProcess } from "../PostProcesses/postProcess";
|
|
41
41
|
import { PerformanceMonitor } from "../Misc/performanceMonitor";
|
|
42
42
|
import "./AbstractEngine/abstractEngine.loadingScreen";
|
|
@@ -44,6 +44,8 @@ import "./AbstractEngine/abstractEngine.dom";
|
|
|
44
44
|
import "./AbstractEngine/abstractEngine.states";
|
|
45
45
|
import "./AbstractEngine/abstractEngine.renderPass";
|
|
46
46
|
import "../Audio/audioEngine";
|
|
47
|
+
import type { TextureSampler } from "../Materials/Textures/textureSampler";
|
|
48
|
+
import type { StorageBuffer } from "../Buffers/storageBuffer";
|
|
47
49
|
/** @internal */
|
|
48
50
|
interface IWebGPURenderPassWrapper {
|
|
49
51
|
renderPassDescriptor: Nullable<GPURenderPassDescriptor>;
|
|
@@ -1018,5 +1020,55 @@ export declare class WebGPUEngine extends AbstractEngine {
|
|
|
1018
1020
|
* @returns the error code
|
|
1019
1021
|
*/
|
|
1020
1022
|
getError(): number;
|
|
1023
|
+
/**
|
|
1024
|
+
* Creates an external texture
|
|
1025
|
+
* @param video video element
|
|
1026
|
+
* @returns the external texture, or null if external textures are not supported by the engine
|
|
1027
|
+
*/
|
|
1028
|
+
createExternalTexture(video: HTMLVideoElement): Nullable<ExternalTexture>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Sets an internal texture to the according uniform.
|
|
1031
|
+
* @param name The name of the uniform in the effect
|
|
1032
|
+
* @param texture The texture to apply
|
|
1033
|
+
*/
|
|
1034
|
+
setExternalTexture(name: string, texture: Nullable<ExternalTexture>): void;
|
|
1035
|
+
/**
|
|
1036
|
+
* Sets a texture sampler to the according uniform.
|
|
1037
|
+
* @param name The name of the uniform in the effect
|
|
1038
|
+
* @param sampler The sampler to apply
|
|
1039
|
+
*/
|
|
1040
|
+
setTextureSampler(name: string, sampler: Nullable<TextureSampler>): void;
|
|
1041
|
+
/**
|
|
1042
|
+
* Creates a storage buffer
|
|
1043
|
+
* @param data the data for the storage buffer or the size of the buffer
|
|
1044
|
+
* @param creationFlags flags to use when creating the buffer (see Constants.BUFFER_CREATIONFLAG_XXX). The BUFFER_CREATIONFLAG_STORAGE flag will be automatically added
|
|
1045
|
+
* @param label defines the label of the buffer (for debug purpose)
|
|
1046
|
+
* @returns the new buffer
|
|
1047
|
+
*/
|
|
1048
|
+
createStorageBuffer(data: DataArray | number, creationFlags: number, label?: string): DataBuffer;
|
|
1049
|
+
/**
|
|
1050
|
+
* Updates a storage buffer
|
|
1051
|
+
* @param buffer the storage buffer to update
|
|
1052
|
+
* @param data the data used to update the storage buffer
|
|
1053
|
+
* @param byteOffset the byte offset of the data
|
|
1054
|
+
* @param byteLength the byte length of the data
|
|
1055
|
+
*/
|
|
1056
|
+
updateStorageBuffer(buffer: DataBuffer, data: DataArray, byteOffset?: number, byteLength?: number): void;
|
|
1057
|
+
/**
|
|
1058
|
+
* Read data from a storage buffer
|
|
1059
|
+
* @param storageBuffer The storage buffer to read from
|
|
1060
|
+
* @param offset The offset in the storage buffer to start reading from (default: 0)
|
|
1061
|
+
* @param size The number of bytes to read from the storage buffer (default: capacity of the buffer)
|
|
1062
|
+
* @param buffer The buffer to write the data we have read from the storage buffer to (optional)
|
|
1063
|
+
* @param noDelay If true, a call to flushFramebuffer will be issued so that the data can be read back immediately and not in engine.onEndFrameObservable. This can speed up data retrieval, at the cost of a small perf penalty (default: false).
|
|
1064
|
+
* @returns If not undefined, returns the (promise) buffer (as provided by the 4th parameter) filled with the data, else it returns a (promise) Uint8Array with the data read from the storage buffer
|
|
1065
|
+
*/
|
|
1066
|
+
readFromStorageBuffer(storageBuffer: DataBuffer, offset?: number, size?: number, buffer?: ArrayBufferView, noDelay?: boolean): Promise<ArrayBufferView>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Sets a storage buffer in the shader
|
|
1069
|
+
* @param name Defines the name of the storage buffer as defined in the shader
|
|
1070
|
+
* @param buffer Defines the value to give to the uniform
|
|
1071
|
+
*/
|
|
1072
|
+
setStorageBuffer(name: string, buffer: Nullable<StorageBuffer>): void;
|
|
1021
1073
|
}
|
|
1022
1074
|
export {};
|
package/Engines/webgpuEngine.js
CHANGED
|
@@ -49,6 +49,7 @@ import "./AbstractEngine/abstractEngine.states.js";
|
|
|
49
49
|
import "./AbstractEngine/abstractEngine.renderPass.js";
|
|
50
50
|
import "../Audio/audioEngine.js";
|
|
51
51
|
import { resetCachedPipeline } from "../Materials/effect.functions.js";
|
|
52
|
+
import { WebGPUExternalTexture } from "./WebGPU/webgpuExternalTexture.js";
|
|
52
53
|
const viewDescriptorSwapChainAntialiasing = {
|
|
53
54
|
label: `TextureView_SwapChain_ResolveTarget`,
|
|
54
55
|
dimension: WebGPUConstants.TextureDimension.E2d,
|
|
@@ -3055,6 +3056,152 @@ export class WebGPUEngine extends AbstractEngine {
|
|
|
3055
3056
|
// TODO WEBGPU. from the webgpu errors.
|
|
3056
3057
|
return 0;
|
|
3057
3058
|
}
|
|
3059
|
+
//------------------------------------------------------------------------------
|
|
3060
|
+
// External Textures
|
|
3061
|
+
//------------------------------------------------------------------------------
|
|
3062
|
+
/**
|
|
3063
|
+
* Creates an external texture
|
|
3064
|
+
* @param video video element
|
|
3065
|
+
* @returns the external texture, or null if external textures are not supported by the engine
|
|
3066
|
+
*/
|
|
3067
|
+
createExternalTexture(video) {
|
|
3068
|
+
const texture = new WebGPUExternalTexture(video);
|
|
3069
|
+
return texture;
|
|
3070
|
+
}
|
|
3071
|
+
/**
|
|
3072
|
+
* Sets an internal texture to the according uniform.
|
|
3073
|
+
* @param name The name of the uniform in the effect
|
|
3074
|
+
* @param texture The texture to apply
|
|
3075
|
+
*/
|
|
3076
|
+
setExternalTexture(name, texture) {
|
|
3077
|
+
if (!texture) {
|
|
3078
|
+
this._currentMaterialContext.setTexture(name, null);
|
|
3079
|
+
return;
|
|
3080
|
+
}
|
|
3081
|
+
this._setInternalTexture(name, texture);
|
|
3082
|
+
}
|
|
3083
|
+
//------------------------------------------------------------------------------
|
|
3084
|
+
// Samplers
|
|
3085
|
+
//------------------------------------------------------------------------------
|
|
3086
|
+
/**
|
|
3087
|
+
* Sets a texture sampler to the according uniform.
|
|
3088
|
+
* @param name The name of the uniform in the effect
|
|
3089
|
+
* @param sampler The sampler to apply
|
|
3090
|
+
*/
|
|
3091
|
+
setTextureSampler(name, sampler) {
|
|
3092
|
+
this._currentMaterialContext?.setSampler(name, sampler);
|
|
3093
|
+
}
|
|
3094
|
+
//------------------------------------------------------------------------------
|
|
3095
|
+
// Storage Buffers
|
|
3096
|
+
//------------------------------------------------------------------------------
|
|
3097
|
+
/**
|
|
3098
|
+
* Creates a storage buffer
|
|
3099
|
+
* @param data the data for the storage buffer or the size of the buffer
|
|
3100
|
+
* @param creationFlags flags to use when creating the buffer (see undefined). The BUFFER_CREATIONFLAG_STORAGE flag will be automatically added
|
|
3101
|
+
* @param label defines the label of the buffer (for debug purpose)
|
|
3102
|
+
* @returns the new buffer
|
|
3103
|
+
*/
|
|
3104
|
+
createStorageBuffer(data, creationFlags, label) {
|
|
3105
|
+
return this._createBuffer(data, creationFlags | 32, label);
|
|
3106
|
+
}
|
|
3107
|
+
/**
|
|
3108
|
+
* Updates a storage buffer
|
|
3109
|
+
* @param buffer the storage buffer to update
|
|
3110
|
+
* @param data the data used to update the storage buffer
|
|
3111
|
+
* @param byteOffset the byte offset of the data
|
|
3112
|
+
* @param byteLength the byte length of the data
|
|
3113
|
+
*/
|
|
3114
|
+
updateStorageBuffer(buffer, data, byteOffset, byteLength) {
|
|
3115
|
+
const dataBuffer = buffer;
|
|
3116
|
+
if (byteOffset === undefined) {
|
|
3117
|
+
byteOffset = 0;
|
|
3118
|
+
}
|
|
3119
|
+
let view;
|
|
3120
|
+
if (byteLength === undefined) {
|
|
3121
|
+
if (data instanceof Array) {
|
|
3122
|
+
view = new Float32Array(data);
|
|
3123
|
+
}
|
|
3124
|
+
else if (data instanceof ArrayBuffer) {
|
|
3125
|
+
view = new Uint8Array(data);
|
|
3126
|
+
}
|
|
3127
|
+
else {
|
|
3128
|
+
view = data;
|
|
3129
|
+
}
|
|
3130
|
+
byteLength = view.byteLength;
|
|
3131
|
+
}
|
|
3132
|
+
else {
|
|
3133
|
+
if (data instanceof Array) {
|
|
3134
|
+
view = new Float32Array(data);
|
|
3135
|
+
}
|
|
3136
|
+
else if (data instanceof ArrayBuffer) {
|
|
3137
|
+
view = new Uint8Array(data);
|
|
3138
|
+
}
|
|
3139
|
+
else {
|
|
3140
|
+
view = data;
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
this._bufferManager.setSubData(dataBuffer, byteOffset, view, 0, byteLength);
|
|
3144
|
+
}
|
|
3145
|
+
/**
|
|
3146
|
+
* Read data from a storage buffer
|
|
3147
|
+
* @param storageBuffer The storage buffer to read from
|
|
3148
|
+
* @param offset The offset in the storage buffer to start reading from (default: 0)
|
|
3149
|
+
* @param size The number of bytes to read from the storage buffer (default: capacity of the buffer)
|
|
3150
|
+
* @param buffer The buffer to write the data we have read from the storage buffer to (optional)
|
|
3151
|
+
* @param noDelay If true, a call to flushFramebuffer will be issued so that the data can be read back immediately and not in engine.onEndFrameObservable. This can speed up data retrieval, at the cost of a small perf penalty (default: false).
|
|
3152
|
+
* @returns If not undefined, returns the (promise) buffer (as provided by the 4th parameter) filled with the data, else it returns a (promise) Uint8Array with the data read from the storage buffer
|
|
3153
|
+
*/
|
|
3154
|
+
readFromStorageBuffer(storageBuffer, offset, size, buffer, noDelay) {
|
|
3155
|
+
size = size || storageBuffer.capacity;
|
|
3156
|
+
const gpuBuffer = this._bufferManager.createRawBuffer(size, WebGPUConstants.BufferUsage.MapRead | WebGPUConstants.BufferUsage.CopyDst, undefined, "TempReadFromStorageBuffer");
|
|
3157
|
+
this._renderEncoder.copyBufferToBuffer(storageBuffer.underlyingResource, offset ?? 0, gpuBuffer, 0, size);
|
|
3158
|
+
return new Promise((resolve, reject) => {
|
|
3159
|
+
const readFromBuffer = () => {
|
|
3160
|
+
gpuBuffer.mapAsync(WebGPUConstants.MapMode.Read, 0, size).then(() => {
|
|
3161
|
+
const copyArrayBuffer = gpuBuffer.getMappedRange(0, size);
|
|
3162
|
+
let data = buffer;
|
|
3163
|
+
if (data === undefined) {
|
|
3164
|
+
data = new Uint8Array(size);
|
|
3165
|
+
data.set(new Uint8Array(copyArrayBuffer));
|
|
3166
|
+
}
|
|
3167
|
+
else {
|
|
3168
|
+
const ctor = data.constructor; // we want to create result data with the same type as buffer (Uint8Array, Float32Array, ...)
|
|
3169
|
+
data = new ctor(data.buffer);
|
|
3170
|
+
data.set(new ctor(copyArrayBuffer));
|
|
3171
|
+
}
|
|
3172
|
+
gpuBuffer.unmap();
|
|
3173
|
+
this._bufferManager.releaseBuffer(gpuBuffer);
|
|
3174
|
+
resolve(data);
|
|
3175
|
+
}, (reason) => {
|
|
3176
|
+
if (this.isDisposed) {
|
|
3177
|
+
resolve(new Uint8Array());
|
|
3178
|
+
}
|
|
3179
|
+
else {
|
|
3180
|
+
reject(reason);
|
|
3181
|
+
}
|
|
3182
|
+
});
|
|
3183
|
+
};
|
|
3184
|
+
if (noDelay) {
|
|
3185
|
+
this.flushFramebuffer();
|
|
3186
|
+
readFromBuffer();
|
|
3187
|
+
}
|
|
3188
|
+
else {
|
|
3189
|
+
// we are using onEndFrameObservable because we need to map the gpuBuffer AFTER the command buffers
|
|
3190
|
+
// have been submitted, else we get the error: "Buffer used in a submit while mapped"
|
|
3191
|
+
this.onEndFrameObservable.addOnce(() => {
|
|
3192
|
+
readFromBuffer();
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
});
|
|
3196
|
+
}
|
|
3197
|
+
/**
|
|
3198
|
+
* Sets a storage buffer in the shader
|
|
3199
|
+
* @param name Defines the name of the storage buffer as defined in the shader
|
|
3200
|
+
* @param buffer Defines the value to give to the uniform
|
|
3201
|
+
*/
|
|
3202
|
+
setStorageBuffer(name, buffer) {
|
|
3203
|
+
this._currentDrawContext?.setBuffer(name, buffer?.getBuffer() ?? null);
|
|
3204
|
+
}
|
|
3058
3205
|
}
|
|
3059
3206
|
// Default glslang options.
|
|
3060
3207
|
WebGPUEngine._GLSLslangDefaultOptions = {
|