@babylonjs/core 6.36.0 → 6.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cameras/Inputs/arcRotateCameraGamepadInput.js +4 -0
- package/Cameras/Inputs/arcRotateCameraGamepadInput.js.map +1 -1
- package/Engines/Extensions/engine.dynamicTexture.d.ts +2 -2
- package/Engines/Extensions/engine.dynamicTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.dynamicTexture.js +28 -3
- package/Engines/WebGPU/Extensions/engine.dynamicTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.rawTexture.js +4 -0
- package/Engines/WebGPU/Extensions/engine.rawTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuBufferManager.js +6 -2
- package/Engines/WebGPU/webgpuBufferManager.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheBindGroups.d.ts +1 -0
- package/Engines/WebGPU/webgpuCacheBindGroups.js +12 -0
- package/Engines/WebGPU/webgpuCacheBindGroups.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js +2 -1
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheRenderPipelineTree.d.ts +2 -2
- package/Engines/WebGPU/webgpuCacheRenderPipelineTree.js +5 -2
- package/Engines/WebGPU/webgpuCacheRenderPipelineTree.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheSampler.js +3 -0
- package/Engines/WebGPU/webgpuCacheSampler.js.map +1 -1
- package/Engines/WebGPU/webgpuClearQuad.js +2 -1
- package/Engines/WebGPU/webgpuClearQuad.js.map +1 -1
- package/Engines/WebGPU/webgpuHardwareTexture.d.ts +1 -1
- package/Engines/WebGPU/webgpuHardwareTexture.js +23 -5
- package/Engines/WebGPU/webgpuHardwareTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuPipelineContext.js +4 -5
- package/Engines/WebGPU/webgpuPipelineContext.js.map +1 -1
- package/Engines/WebGPU/webgpuQuerySet.js +10 -4
- package/Engines/WebGPU/webgpuQuerySet.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.d.ts +8 -53
- package/Engines/WebGPU/webgpuTextureHelper.js +4 -996
- package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureManager.d.ts +56 -0
- package/Engines/WebGPU/webgpuTextureManager.js +1012 -0
- package/Engines/WebGPU/webgpuTextureManager.js.map +1 -0
- package/Engines/engine.d.ts +1 -0
- package/Engines/engine.js +9 -2
- package/Engines/engine.js.map +1 -1
- package/Engines/renderTargetWrapper.d.ts +1 -0
- package/Engines/renderTargetWrapper.js +5 -1
- package/Engines/renderTargetWrapper.js.map +1 -1
- package/Engines/thinEngine.d.ts +1 -0
- package/Engines/thinEngine.js +11 -7
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.d.ts +9 -2
- package/Engines/webgpuEngine.js +75 -3
- package/Engines/webgpuEngine.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphGetPropertyBlock.d.ts +23 -6
- package/FlowGraph/Blocks/Data/flowGraphGetPropertyBlock.js +14 -3
- package/FlowGraph/Blocks/Data/flowGraphGetPropertyBlock.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.d.ts +14 -3
- package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.js +12 -11
- package/FlowGraph/Blocks/Event/flowGraphMeshPickEventBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPauseAnimationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.d.ts +22 -7
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js +15 -9
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPlayAudioBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPlayAudioBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphPlayAudioBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphStopAudioBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphStopAudioBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/Audio/flowGraphStopAudioBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphCounterBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphCounterBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphCounterBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDebounceBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDebounceBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDebounceBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphDoNBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphThrottleBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphThrottleBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphThrottleBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphWaitAllBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphWaitAllBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphWaitAllBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphWhileLoopBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphWhileLoopBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphWhileLoopBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSendCustomEventBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSendCustomEventBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSendCustomEventBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.d.ts +13 -5
- package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.js +9 -5
- package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.js +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.js.map +1 -1
- package/FlowGraph/flowGraph.d.ts +24 -6
- package/FlowGraph/flowGraph.js +12 -12
- package/FlowGraph/flowGraph.js.map +1 -1
- package/FlowGraph/flowGraphBlock.d.ts +31 -2
- package/FlowGraph/flowGraphBlock.js +8 -3
- package/FlowGraph/flowGraphBlock.js.map +1 -1
- package/FlowGraph/flowGraphContext.d.ts +5 -1
- package/FlowGraph/flowGraphContext.js +4 -2
- package/FlowGraph/flowGraphContext.js.map +1 -1
- package/FlowGraph/flowGraphCoordinator.d.ts +22 -2
- package/FlowGraph/flowGraphCoordinator.js +7 -11
- package/FlowGraph/flowGraphCoordinator.js.map +1 -1
- package/FlowGraph/{flowGraphWithOnDoneExecutionBlock.js → flowGraphExecutionBlockWithOutSignal.js} +1 -1
- package/FlowGraph/flowGraphExecutionBlockWithOutSignal.js.map +1 -0
- package/FlowGraph/flowGraphPathConverter.d.ts +13 -0
- package/FlowGraph/flowGraphPathConverter.js +31 -0
- package/FlowGraph/flowGraphPathConverter.js.map +1 -0
- package/FlowGraph/flowGraphPathConverterComponent.d.ts +19 -0
- package/FlowGraph/flowGraphPathConverterComponent.js +31 -0
- package/FlowGraph/flowGraphPathConverterComponent.js.map +1 -0
- package/FlowGraph/index.d.ts +0 -1
- package/FlowGraph/index.js +0 -1
- package/FlowGraph/index.js.map +1 -1
- package/FlowGraph/serialization.d.ts +8 -0
- package/FlowGraph/serialization.js +12 -4
- package/FlowGraph/serialization.js.map +1 -1
- package/FlowGraph/typeDefinitions.d.ts +86 -1
- package/FlowGraph/typeDefinitions.js.map +1 -1
- package/Materials/Textures/dynamicTexture.js +2 -1
- package/Materials/Textures/dynamicTexture.js.map +1 -1
- package/Materials/Textures/hardwareTextureWrapper.d.ts +1 -1
- package/Materials/Textures/hardwareTextureWrapper.js.map +1 -1
- package/Materials/Textures/internalTexture.d.ts +6 -2
- package/Materials/Textures/internalTexture.js +6 -4
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.js +10 -10
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/material.d.ts +1 -1
- package/Materials/material.js +3 -1
- package/Materials/material.js.map +1 -1
- package/Materials/shaderMaterial.js +2 -2
- package/Materials/shaderMaterial.js.map +1 -1
- package/Materials/uniformBuffer.d.ts +2 -0
- package/Materials/uniformBuffer.js +16 -0
- package/Materials/uniformBuffer.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineMesh.d.ts +2 -1
- package/Meshes/GreasedLine/greasedLineMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.d.ts +2 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
- package/Meshes/WebGPU/webgpuDataBuffer.d.ts +1 -0
- package/Meshes/WebGPU/webgpuDataBuffer.js +2 -0
- package/Meshes/WebGPU/webgpuDataBuffer.js.map +1 -1
- package/Meshes/geometry.js +3 -3
- package/Meshes/geometry.js.map +1 -1
- package/Misc/brdfTextureTools.js +9 -7
- package/Misc/brdfTextureTools.js.map +1 -1
- package/Misc/rgbdTextureTools.js +37 -37
- package/Misc/rgbdTextureTools.js.map +1 -1
- package/ObjectModel/index.d.ts +1 -0
- package/ObjectModel/index.js +2 -0
- package/ObjectModel/index.js.map +1 -0
- package/ObjectModel/objectModelInterfaces.d.ts +21 -0
- package/ObjectModel/objectModelInterfaces.js +2 -0
- package/ObjectModel/objectModelInterfaces.js.map +1 -0
- package/Particles/computeShaderParticleSystem.js +2 -2
- package/Particles/computeShaderParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.js +1 -1
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particleSystem.js +2 -5
- package/Particles/particleSystem.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderer.js +1 -6
- package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -1
- package/Rendering/renderingManager.js +1 -1
- package/Rendering/renderingManager.js.map +1 -1
- package/XR/features/WebXRControllerTeleportation.d.ts +9 -1
- package/XR/features/WebXRControllerTeleportation.js +10 -0
- package/XR/features/WebXRControllerTeleportation.js.map +1 -1
- package/XR/webXRCamera.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +5 -1
- package/types.js +0 -2
- package/types.js.map +1 -1
- package/FlowGraph/flowGraphPath.d.ts +0 -45
- package/FlowGraph/flowGraphPath.js +0 -156
- package/FlowGraph/flowGraphPath.js.map +0 -1
- package/FlowGraph/flowGraphPathComponent.d.ts +0 -42
- package/FlowGraph/flowGraphPathComponent.js +0 -51
- package/FlowGraph/flowGraphPathComponent.js.map +0 -1
- package/FlowGraph/flowGraphWithOnDoneExecutionBlock.js.map +0 -1
- /package/FlowGraph/{flowGraphWithOnDoneExecutionBlock.d.ts → flowGraphExecutionBlockWithOutSignal.d.ts} +0 -0
|
@@ -1,399 +1,13 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
1
|
/* eslint-disable babylonjs/available */
|
|
3
|
-
|
|
4
|
-
// License for the mipmap generation code:
|
|
5
|
-
//
|
|
6
|
-
// Copyright 2020 Brandon Jones
|
|
7
|
-
//
|
|
8
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
// in the Software without restriction, including without limitation the rights
|
|
11
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
// furnished to do so, subject to the following conditions:
|
|
14
|
-
// The above copyright notice and this permission notice shall be included in
|
|
15
|
-
// all copies or substantial portions of the Software.
|
|
16
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
// SOFTWARE.
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
3
|
import * as WebGPUConstants from "./webgpuConstants.js";
|
|
24
4
|
import { Scalar } from "../../Maths/math.scalar.js";
|
|
25
5
|
|
|
26
|
-
import { InternalTextureSource } from "../../Materials/Textures/internalTexture.js";
|
|
27
|
-
import { WebGPUHardwareTexture } from "./webgpuHardwareTexture.js";
|
|
28
|
-
// TODO WEBGPU improve mipmap generation by using compute shaders
|
|
29
|
-
// TODO WEBGPU use WGSL instead of GLSL
|
|
30
|
-
const mipmapVertexSource = `
|
|
31
|
-
const vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));
|
|
32
|
-
const vec2 tex[4] = vec2[4](vec2(0.0f, 0.0f), vec2(1.0f, 0.0f), vec2(0.0f, 1.0f), vec2(1.0f, 1.0f));
|
|
33
|
-
|
|
34
|
-
layout(location = 0) out vec2 vTex;
|
|
35
|
-
|
|
36
|
-
void main() {
|
|
37
|
-
vTex = tex[gl_VertexIndex];
|
|
38
|
-
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
41
|
-
const mipmapFragmentSource = `
|
|
42
|
-
layout(set = 0, binding = 0) uniform sampler imgSampler;
|
|
43
|
-
layout(set = 0, binding = 1) uniform texture2D img;
|
|
44
|
-
|
|
45
|
-
layout(location = 0) in vec2 vTex;
|
|
46
|
-
layout(location = 0) out vec4 outColor;
|
|
47
|
-
|
|
48
|
-
void main() {
|
|
49
|
-
outColor = texture(sampler2D(img, imgSampler), vTex);
|
|
50
|
-
}
|
|
51
|
-
`;
|
|
52
|
-
const invertYPreMultiplyAlphaVertexSource = `
|
|
53
|
-
#extension GL_EXT_samplerless_texture_functions : enable
|
|
54
|
-
|
|
55
|
-
const vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));
|
|
56
|
-
const vec2 tex[4] = vec2[4](vec2(0.0f, 0.0f), vec2(1.0f, 0.0f), vec2(0.0f, 1.0f), vec2(1.0f, 1.0f));
|
|
57
|
-
|
|
58
|
-
layout(set = 0, binding = 0) uniform texture2D img;
|
|
59
|
-
|
|
60
|
-
#ifdef INVERTY
|
|
61
|
-
layout(location = 0) out flat ivec2 vTextureSize;
|
|
62
|
-
#endif
|
|
63
|
-
|
|
64
|
-
void main() {
|
|
65
|
-
#ifdef INVERTY
|
|
66
|
-
vTextureSize = textureSize(img, 0);
|
|
67
|
-
#endif
|
|
68
|
-
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
|
69
|
-
}
|
|
70
|
-
`;
|
|
71
|
-
const invertYPreMultiplyAlphaFragmentSource = `
|
|
72
|
-
#extension GL_EXT_samplerless_texture_functions : enable
|
|
73
|
-
|
|
74
|
-
layout(set = 0, binding = 0) uniform texture2D img;
|
|
75
|
-
|
|
76
|
-
#ifdef INVERTY
|
|
77
|
-
layout(location = 0) in flat ivec2 vTextureSize;
|
|
78
|
-
#endif
|
|
79
|
-
layout(location = 0) out vec4 outColor;
|
|
80
|
-
|
|
81
|
-
void main() {
|
|
82
|
-
#ifdef INVERTY
|
|
83
|
-
vec4 color = texelFetch(img, ivec2(gl_FragCoord.x, vTextureSize.y - gl_FragCoord.y), 0);
|
|
84
|
-
#else
|
|
85
|
-
vec4 color = texelFetch(img, ivec2(gl_FragCoord.xy), 0);
|
|
86
|
-
#endif
|
|
87
|
-
#ifdef PREMULTIPLYALPHA
|
|
88
|
-
color.rgb *= color.a;
|
|
89
|
-
#endif
|
|
90
|
-
outColor = color;
|
|
91
|
-
}
|
|
92
|
-
`;
|
|
93
|
-
const invertYPreMultiplyAlphaWithOfstVertexSource = invertYPreMultiplyAlphaVertexSource;
|
|
94
|
-
const invertYPreMultiplyAlphaWithOfstFragmentSource = `
|
|
95
|
-
#extension GL_EXT_samplerless_texture_functions : enable
|
|
96
|
-
|
|
97
|
-
layout(set = 0, binding = 0) uniform texture2D img;
|
|
98
|
-
layout(set = 0, binding = 1) uniform Params {
|
|
99
|
-
float ofstX;
|
|
100
|
-
float ofstY;
|
|
101
|
-
float width;
|
|
102
|
-
float height;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
#ifdef INVERTY
|
|
106
|
-
layout(location = 0) in flat ivec2 vTextureSize;
|
|
107
|
-
#endif
|
|
108
|
-
layout(location = 0) out vec4 outColor;
|
|
109
|
-
|
|
110
|
-
void main() {
|
|
111
|
-
if (gl_FragCoord.x < ofstX || gl_FragCoord.x >= ofstX + width) {
|
|
112
|
-
discard;
|
|
113
|
-
}
|
|
114
|
-
if (gl_FragCoord.y < ofstY || gl_FragCoord.y >= ofstY + height) {
|
|
115
|
-
discard;
|
|
116
|
-
}
|
|
117
|
-
#ifdef INVERTY
|
|
118
|
-
vec4 color = texelFetch(img, ivec2(gl_FragCoord.x, ofstY + height - (gl_FragCoord.y - ofstY)), 0);
|
|
119
|
-
#else
|
|
120
|
-
vec4 color = texelFetch(img, ivec2(gl_FragCoord.xy), 0);
|
|
121
|
-
#endif
|
|
122
|
-
#ifdef PREMULTIPLYALPHA
|
|
123
|
-
color.rgb *= color.a;
|
|
124
|
-
#endif
|
|
125
|
-
outColor = color;
|
|
126
|
-
}
|
|
127
|
-
`;
|
|
128
|
-
const clearVertexSource = `
|
|
129
|
-
const vec2 pos[4] = vec2[4](vec2(-1.0f, 1.0f), vec2(1.0f, 1.0f), vec2(-1.0f, -1.0f), vec2(1.0f, -1.0f));
|
|
130
|
-
|
|
131
|
-
void main() {
|
|
132
|
-
gl_Position = vec4(pos[gl_VertexIndex], 0.0, 1.0);
|
|
133
|
-
}
|
|
134
|
-
`;
|
|
135
|
-
const clearFragmentSource = `
|
|
136
|
-
layout(set = 0, binding = 0) uniform Uniforms {
|
|
137
|
-
uniform vec4 color;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
layout(location = 0) out vec4 outColor;
|
|
141
|
-
|
|
142
|
-
void main() {
|
|
143
|
-
outColor = color;
|
|
144
|
-
}
|
|
145
|
-
`;
|
|
146
|
-
const copyVideoToTextureVertexSource = `
|
|
147
|
-
struct VertexOutput {
|
|
148
|
-
@builtin(position) Position : vec4<f32>,
|
|
149
|
-
@location(0) fragUV : vec2<f32>
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
@vertex
|
|
153
|
-
fn main(
|
|
154
|
-
@builtin(vertex_index) VertexIndex : u32
|
|
155
|
-
) -> VertexOutput {
|
|
156
|
-
var pos = array<vec2<f32>, 4>(
|
|
157
|
-
vec2(-1.0, 1.0),
|
|
158
|
-
vec2( 1.0, 1.0),
|
|
159
|
-
vec2(-1.0, -1.0),
|
|
160
|
-
vec2( 1.0, -1.0)
|
|
161
|
-
);
|
|
162
|
-
var tex = array<vec2<f32>, 4>(
|
|
163
|
-
vec2(0.0, 0.0),
|
|
164
|
-
vec2(1.0, 0.0),
|
|
165
|
-
vec2(0.0, 1.0),
|
|
166
|
-
vec2(1.0, 1.0)
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
var output: VertexOutput;
|
|
170
|
-
|
|
171
|
-
output.Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
|
|
172
|
-
output.fragUV = tex[VertexIndex];
|
|
173
|
-
|
|
174
|
-
return output;
|
|
175
|
-
}
|
|
176
|
-
`;
|
|
177
|
-
const copyVideoToTextureFragmentSource = `
|
|
178
|
-
@group(0) @binding(0) var videoSampler: sampler;
|
|
179
|
-
@group(0) @binding(1) var videoTexture: texture_external;
|
|
180
|
-
|
|
181
|
-
@fragment
|
|
182
|
-
fn main(
|
|
183
|
-
@location(0) fragUV: vec2<f32>
|
|
184
|
-
) -> @location(0) vec4<f32> {
|
|
185
|
-
return textureSampleBaseClampToEdge(videoTexture, videoSampler, fragUV);
|
|
186
|
-
}
|
|
187
|
-
`;
|
|
188
|
-
const copyVideoToTextureInvertYFragmentSource = `
|
|
189
|
-
@group(0) @binding(0) var videoSampler: sampler;
|
|
190
|
-
@group(0) @binding(1) var videoTexture: texture_external;
|
|
191
|
-
|
|
192
|
-
@fragment
|
|
193
|
-
fn main(
|
|
194
|
-
@location(0) fragUV: vec2<f32>
|
|
195
|
-
) -> @location(0) vec4<f32> {
|
|
196
|
-
return textureSampleBaseClampToEdge(videoTexture, videoSampler, vec2<f32>(fragUV.x, 1.0 - fragUV.y));
|
|
197
|
-
}
|
|
198
|
-
`;
|
|
199
|
-
var PipelineType;
|
|
200
|
-
(function (PipelineType) {
|
|
201
|
-
PipelineType[PipelineType["MipMap"] = 0] = "MipMap";
|
|
202
|
-
PipelineType[PipelineType["InvertYPremultiplyAlpha"] = 1] = "InvertYPremultiplyAlpha";
|
|
203
|
-
PipelineType[PipelineType["Clear"] = 2] = "Clear";
|
|
204
|
-
PipelineType[PipelineType["InvertYPremultiplyAlphaWithOfst"] = 3] = "InvertYPremultiplyAlphaWithOfst";
|
|
205
|
-
})(PipelineType || (PipelineType = {}));
|
|
206
|
-
var VideoPipelineType;
|
|
207
|
-
(function (VideoPipelineType) {
|
|
208
|
-
VideoPipelineType[VideoPipelineType["DontInvertY"] = 0] = "DontInvertY";
|
|
209
|
-
VideoPipelineType[VideoPipelineType["InvertY"] = 1] = "InvertY";
|
|
210
|
-
})(VideoPipelineType || (VideoPipelineType = {}));
|
|
211
|
-
const shadersForPipelineType = [
|
|
212
|
-
{ vertex: mipmapVertexSource, fragment: mipmapFragmentSource },
|
|
213
|
-
{ vertex: invertYPreMultiplyAlphaVertexSource, fragment: invertYPreMultiplyAlphaFragmentSource },
|
|
214
|
-
{ vertex: clearVertexSource, fragment: clearFragmentSource },
|
|
215
|
-
{ vertex: invertYPreMultiplyAlphaWithOfstVertexSource, fragment: invertYPreMultiplyAlphaWithOfstFragmentSource },
|
|
216
|
-
];
|
|
217
|
-
/**
|
|
218
|
-
* Map a (renderable) texture format (GPUTextureFormat) to an index for fast lookup (in caches for eg)
|
|
219
|
-
* The number of entries should not go over 64! Else, the code in WebGPUCacheRenderPipeline.setMRT should be updated
|
|
220
|
-
*/
|
|
221
|
-
export const renderableTextureFormatToIndex = {
|
|
222
|
-
"": 0,
|
|
223
|
-
r8unorm: 1,
|
|
224
|
-
r8uint: 2,
|
|
225
|
-
r8sint: 3,
|
|
226
|
-
r16uint: 4,
|
|
227
|
-
r16sint: 5,
|
|
228
|
-
r16float: 6,
|
|
229
|
-
rg8unorm: 7,
|
|
230
|
-
rg8uint: 8,
|
|
231
|
-
rg8sint: 9,
|
|
232
|
-
r32uint: 10,
|
|
233
|
-
r32sint: 11,
|
|
234
|
-
r32float: 12,
|
|
235
|
-
rg16uint: 13,
|
|
236
|
-
rg16sint: 14,
|
|
237
|
-
rg16float: 15,
|
|
238
|
-
rgba8unorm: 16,
|
|
239
|
-
"rgba8unorm-srgb": 17,
|
|
240
|
-
rgba8uint: 18,
|
|
241
|
-
rgba8sint: 19,
|
|
242
|
-
bgra8unorm: 20,
|
|
243
|
-
"bgra8unorm-srgb": 21,
|
|
244
|
-
rgb10a2uint: 22,
|
|
245
|
-
rgb10a2unorm: 23,
|
|
246
|
-
/* rg11b10ufloat: this entry is dynamically added if the "RG11B10UFloatRenderable" extension is supported */
|
|
247
|
-
rg32uint: 24,
|
|
248
|
-
rg32sint: 25,
|
|
249
|
-
rg32float: 26,
|
|
250
|
-
rgba16uint: 27,
|
|
251
|
-
rgba16sint: 28,
|
|
252
|
-
rgba16float: 29,
|
|
253
|
-
rgba32uint: 30,
|
|
254
|
-
rgba32sint: 31,
|
|
255
|
-
rgba32float: 32,
|
|
256
|
-
stencil8: 33,
|
|
257
|
-
depth16unorm: 34,
|
|
258
|
-
depth24plus: 35,
|
|
259
|
-
"depth24plus-stencil8": 36,
|
|
260
|
-
depth32float: 37,
|
|
261
|
-
"depth32float-stencil8": 38,
|
|
262
|
-
};
|
|
263
6
|
/** @internal */
|
|
264
7
|
export class WebGPUTextureHelper {
|
|
265
8
|
static ComputeNumMipmapLevels(width, height) {
|
|
266
9
|
return Scalar.ILog2(Math.max(width, height)) + 1;
|
|
267
10
|
}
|
|
268
|
-
//------------------------------------------------------------------------------
|
|
269
|
-
// Initialization / Helpers
|
|
270
|
-
//------------------------------------------------------------------------------
|
|
271
|
-
constructor(device, glslang, tintWASM, bufferManager, enabledExtensions) {
|
|
272
|
-
this._pipelines = {};
|
|
273
|
-
this._compiledShaders = [];
|
|
274
|
-
this._videoPipelines = {};
|
|
275
|
-
this._videoCompiledShaders = [];
|
|
276
|
-
this._deferredReleaseTextures = [];
|
|
277
|
-
this._device = device;
|
|
278
|
-
this._glslang = glslang;
|
|
279
|
-
this._tintWASM = tintWASM;
|
|
280
|
-
this._bufferManager = bufferManager;
|
|
281
|
-
if (enabledExtensions.indexOf(WebGPUConstants.FeatureName.RG11B10UFloatRenderable) !== -1) {
|
|
282
|
-
const keys = Object.keys(renderableTextureFormatToIndex);
|
|
283
|
-
renderableTextureFormatToIndex[WebGPUConstants.TextureFormat.RG11B10UFloat] = renderableTextureFormatToIndex[keys[keys.length - 1]] + 1;
|
|
284
|
-
}
|
|
285
|
-
this._mipmapSampler = device.createSampler({ minFilter: WebGPUConstants.FilterMode.Linear });
|
|
286
|
-
this._videoSampler = device.createSampler({ minFilter: WebGPUConstants.FilterMode.Linear });
|
|
287
|
-
this._ubCopyWithOfst = this._bufferManager.createBuffer(4 * 4, WebGPUConstants.BufferUsage.Uniform | WebGPUConstants.BufferUsage.CopyDst, "UBCopyWithOffset").underlyingResource;
|
|
288
|
-
this._getPipeline(WebGPUConstants.TextureFormat.RGBA8Unorm);
|
|
289
|
-
this._getVideoPipeline(WebGPUConstants.TextureFormat.RGBA8Unorm);
|
|
290
|
-
}
|
|
291
|
-
_getPipeline(format, type = PipelineType.MipMap, params) {
|
|
292
|
-
const index = type === PipelineType.MipMap
|
|
293
|
-
? 1 << 0
|
|
294
|
-
: type === PipelineType.InvertYPremultiplyAlpha
|
|
295
|
-
? ((params.invertY ? 1 : 0) << 1) + ((params.premultiplyAlpha ? 1 : 0) << 2)
|
|
296
|
-
: type === PipelineType.Clear
|
|
297
|
-
? 1 << 3
|
|
298
|
-
: type === PipelineType.InvertYPremultiplyAlphaWithOfst
|
|
299
|
-
? ((params.invertY ? 1 : 0) << 4) + ((params.premultiplyAlpha ? 1 : 0) << 5)
|
|
300
|
-
: 0;
|
|
301
|
-
if (!this._pipelines[format]) {
|
|
302
|
-
this._pipelines[format] = [];
|
|
303
|
-
}
|
|
304
|
-
let pipelineAndBGL = this._pipelines[format][index];
|
|
305
|
-
if (!pipelineAndBGL) {
|
|
306
|
-
let defines = "#version 450\n";
|
|
307
|
-
if (type === PipelineType.InvertYPremultiplyAlpha || type === PipelineType.InvertYPremultiplyAlphaWithOfst) {
|
|
308
|
-
if (params.invertY) {
|
|
309
|
-
defines += "#define INVERTY\n";
|
|
310
|
-
}
|
|
311
|
-
if (params.premultiplyAlpha) {
|
|
312
|
-
defines += "#define PREMULTIPLYALPHA\n";
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
let modules = this._compiledShaders[index];
|
|
316
|
-
if (!modules) {
|
|
317
|
-
let vertexCode = this._glslang.compileGLSL(defines + shadersForPipelineType[type].vertex, "vertex");
|
|
318
|
-
let fragmentCode = this._glslang.compileGLSL(defines + shadersForPipelineType[type].fragment, "fragment");
|
|
319
|
-
if (this._tintWASM) {
|
|
320
|
-
vertexCode = this._tintWASM.convertSpirV2WGSL(vertexCode);
|
|
321
|
-
fragmentCode = this._tintWASM.convertSpirV2WGSL(fragmentCode);
|
|
322
|
-
}
|
|
323
|
-
const vertexModule = this._device.createShaderModule({
|
|
324
|
-
code: vertexCode,
|
|
325
|
-
});
|
|
326
|
-
const fragmentModule = this._device.createShaderModule({
|
|
327
|
-
code: fragmentCode,
|
|
328
|
-
});
|
|
329
|
-
modules = this._compiledShaders[index] = [vertexModule, fragmentModule];
|
|
330
|
-
}
|
|
331
|
-
const pipeline = this._device.createRenderPipeline({
|
|
332
|
-
layout: WebGPUConstants.AutoLayoutMode.Auto,
|
|
333
|
-
vertex: {
|
|
334
|
-
module: modules[0],
|
|
335
|
-
entryPoint: "main",
|
|
336
|
-
},
|
|
337
|
-
fragment: {
|
|
338
|
-
module: modules[1],
|
|
339
|
-
entryPoint: "main",
|
|
340
|
-
targets: [
|
|
341
|
-
{
|
|
342
|
-
format,
|
|
343
|
-
},
|
|
344
|
-
],
|
|
345
|
-
},
|
|
346
|
-
primitive: {
|
|
347
|
-
topology: WebGPUConstants.PrimitiveTopology.TriangleStrip,
|
|
348
|
-
stripIndexFormat: WebGPUConstants.IndexFormat.Uint16,
|
|
349
|
-
},
|
|
350
|
-
});
|
|
351
|
-
pipelineAndBGL = this._pipelines[format][index] = [pipeline, pipeline.getBindGroupLayout(0)];
|
|
352
|
-
}
|
|
353
|
-
return pipelineAndBGL;
|
|
354
|
-
}
|
|
355
|
-
_getVideoPipeline(format, type = VideoPipelineType.DontInvertY) {
|
|
356
|
-
const index = type === VideoPipelineType.InvertY ? 1 << 0 : 0;
|
|
357
|
-
if (!this._videoPipelines[format]) {
|
|
358
|
-
this._videoPipelines[format] = [];
|
|
359
|
-
}
|
|
360
|
-
let pipelineAndBGL = this._videoPipelines[format][index];
|
|
361
|
-
if (!pipelineAndBGL) {
|
|
362
|
-
let modules = this._videoCompiledShaders[index];
|
|
363
|
-
if (!modules) {
|
|
364
|
-
const vertexModule = this._device.createShaderModule({
|
|
365
|
-
code: copyVideoToTextureVertexSource,
|
|
366
|
-
});
|
|
367
|
-
const fragmentModule = this._device.createShaderModule({
|
|
368
|
-
code: index === 0 ? copyVideoToTextureFragmentSource : copyVideoToTextureInvertYFragmentSource,
|
|
369
|
-
});
|
|
370
|
-
modules = this._videoCompiledShaders[index] = [vertexModule, fragmentModule];
|
|
371
|
-
}
|
|
372
|
-
const pipeline = this._device.createRenderPipeline({
|
|
373
|
-
label: `CopyVideoToTexture_${format}_${index === 0 ? "DontInvertY" : "InvertY"}`,
|
|
374
|
-
layout: WebGPUConstants.AutoLayoutMode.Auto,
|
|
375
|
-
vertex: {
|
|
376
|
-
module: modules[0],
|
|
377
|
-
entryPoint: "main",
|
|
378
|
-
},
|
|
379
|
-
fragment: {
|
|
380
|
-
module: modules[1],
|
|
381
|
-
entryPoint: "main",
|
|
382
|
-
targets: [
|
|
383
|
-
{
|
|
384
|
-
format,
|
|
385
|
-
},
|
|
386
|
-
],
|
|
387
|
-
},
|
|
388
|
-
primitive: {
|
|
389
|
-
topology: WebGPUConstants.PrimitiveTopology.TriangleStrip,
|
|
390
|
-
stripIndexFormat: WebGPUConstants.IndexFormat.Uint16,
|
|
391
|
-
},
|
|
392
|
-
});
|
|
393
|
-
pipelineAndBGL = this._videoPipelines[format][index] = [pipeline, pipeline.getBindGroupLayout(0)];
|
|
394
|
-
}
|
|
395
|
-
return pipelineAndBGL;
|
|
396
|
-
}
|
|
397
11
|
static GetTextureTypeFromFormat(format) {
|
|
398
12
|
switch (format) {
|
|
399
13
|
// One Component = 8 bits
|
|
@@ -502,7 +116,7 @@ export class WebGPUTextureHelper {
|
|
|
502
116
|
}
|
|
503
117
|
return 0;
|
|
504
118
|
}
|
|
505
|
-
static
|
|
119
|
+
static GetBlockInformationFromFormat(format) {
|
|
506
120
|
switch (format) {
|
|
507
121
|
// 8 bits formats
|
|
508
122
|
case WebGPUConstants.TextureFormat.R8Unorm:
|
|
@@ -643,10 +257,10 @@ export class WebGPUTextureHelper {
|
|
|
643
257
|
}
|
|
644
258
|
return { width: 1, height: 1, length: 4 };
|
|
645
259
|
}
|
|
646
|
-
static
|
|
260
|
+
static IsHardwareTexture(texture) {
|
|
647
261
|
return !!texture.release;
|
|
648
262
|
}
|
|
649
|
-
static
|
|
263
|
+
static IsInternalTexture(texture) {
|
|
650
264
|
return !!texture.dispose;
|
|
651
265
|
}
|
|
652
266
|
static IsImageBitmap(imageBitmap) {
|
|
@@ -655,9 +269,6 @@ export class WebGPUTextureHelper {
|
|
|
655
269
|
static IsImageBitmapArray(imageBitmap) {
|
|
656
270
|
return Array.isArray(imageBitmap) && imageBitmap[0].close !== undefined;
|
|
657
271
|
}
|
|
658
|
-
setCommandEncoder(encoder) {
|
|
659
|
-
this._commandEncoderForCreation = encoder;
|
|
660
|
-
}
|
|
661
272
|
static IsCompressedFormat(format) {
|
|
662
273
|
switch (format) {
|
|
663
274
|
case WebGPUConstants.TextureFormat.BC7RGBAUnormSRGB:
|
|
@@ -1054,608 +665,5 @@ export class WebGPUTextureHelper {
|
|
|
1054
665
|
// WebGPU only supports 1 or 4
|
|
1055
666
|
return sampleCount > 1 ? 4 : 1;
|
|
1056
667
|
}
|
|
1057
|
-
copyVideoToTexture(video, texture, format, invertY = false, commandEncoder) {
|
|
1058
|
-
var _a, _b, _c, _d;
|
|
1059
|
-
const useOwnCommandEncoder = commandEncoder === undefined;
|
|
1060
|
-
const [pipeline, bindGroupLayout] = this._getVideoPipeline(format, invertY ? VideoPipelineType.InvertY : VideoPipelineType.DontInvertY);
|
|
1061
|
-
if (useOwnCommandEncoder) {
|
|
1062
|
-
commandEncoder = this._device.createCommandEncoder({});
|
|
1063
|
-
}
|
|
1064
|
-
(_b = (_a = commandEncoder).pushDebugGroup) === null || _b === void 0 ? void 0 : _b.call(_a, `copy video to texture - invertY=${invertY}`);
|
|
1065
|
-
const webgpuHardwareTexture = texture._hardwareTexture;
|
|
1066
|
-
const renderPassDescriptor = {
|
|
1067
|
-
colorAttachments: [
|
|
1068
|
-
{
|
|
1069
|
-
view: webgpuHardwareTexture.underlyingResource.createView({
|
|
1070
|
-
format,
|
|
1071
|
-
dimension: WebGPUConstants.TextureViewDimension.E2d,
|
|
1072
|
-
mipLevelCount: 1,
|
|
1073
|
-
baseArrayLayer: 0,
|
|
1074
|
-
baseMipLevel: 0,
|
|
1075
|
-
arrayLayerCount: 1,
|
|
1076
|
-
aspect: WebGPUConstants.TextureAspect.All,
|
|
1077
|
-
}),
|
|
1078
|
-
loadOp: WebGPUConstants.LoadOp.Load,
|
|
1079
|
-
storeOp: WebGPUConstants.StoreOp.Store,
|
|
1080
|
-
},
|
|
1081
|
-
],
|
|
1082
|
-
};
|
|
1083
|
-
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
1084
|
-
const descriptor = {
|
|
1085
|
-
layout: bindGroupLayout,
|
|
1086
|
-
entries: [
|
|
1087
|
-
{
|
|
1088
|
-
binding: 0,
|
|
1089
|
-
resource: this._videoSampler,
|
|
1090
|
-
},
|
|
1091
|
-
{
|
|
1092
|
-
binding: 1,
|
|
1093
|
-
resource: this._device.importExternalTexture({
|
|
1094
|
-
source: video.underlyingResource,
|
|
1095
|
-
}),
|
|
1096
|
-
},
|
|
1097
|
-
],
|
|
1098
|
-
};
|
|
1099
|
-
const bindGroup = this._device.createBindGroup(descriptor);
|
|
1100
|
-
passEncoder.setPipeline(pipeline);
|
|
1101
|
-
passEncoder.setBindGroup(0, bindGroup);
|
|
1102
|
-
passEncoder.draw(4, 1, 0, 0);
|
|
1103
|
-
passEncoder.end();
|
|
1104
|
-
(_d = (_c = commandEncoder).popDebugGroup) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
1105
|
-
if (useOwnCommandEncoder) {
|
|
1106
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1107
|
-
commandEncoder = null;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
invertYPreMultiplyAlpha(gpuOrHdwTexture, width, height, format, invertY = false, premultiplyAlpha = false, faceIndex = 0, mipLevel = 0, layers = 1, ofstX = 0, ofstY = 0, rectWidth = 0, rectHeight = 0, commandEncoder,
|
|
1111
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1112
|
-
allowGPUOptimization) {
|
|
1113
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1114
|
-
const useRect = rectWidth !== 0;
|
|
1115
|
-
const useOwnCommandEncoder = commandEncoder === undefined;
|
|
1116
|
-
const [pipeline, bindGroupLayout] = this._getPipeline(format, useRect ? PipelineType.InvertYPremultiplyAlphaWithOfst : PipelineType.InvertYPremultiplyAlpha, {
|
|
1117
|
-
invertY,
|
|
1118
|
-
premultiplyAlpha,
|
|
1119
|
-
});
|
|
1120
|
-
faceIndex = Math.max(faceIndex, 0);
|
|
1121
|
-
if (useOwnCommandEncoder) {
|
|
1122
|
-
commandEncoder = this._device.createCommandEncoder({});
|
|
1123
|
-
}
|
|
1124
|
-
(_b = (_a = commandEncoder).pushDebugGroup) === null || _b === void 0 ? void 0 : _b.call(_a, `internal process texture - invertY=${invertY} premultiplyAlpha=${premultiplyAlpha}`);
|
|
1125
|
-
let gpuTexture;
|
|
1126
|
-
if (WebGPUTextureHelper._IsHardwareTexture(gpuOrHdwTexture)) {
|
|
1127
|
-
gpuTexture = gpuOrHdwTexture.underlyingResource;
|
|
1128
|
-
if (!(invertY && !premultiplyAlpha && layers === 1 && faceIndex === 0)) {
|
|
1129
|
-
// we optimize only for the most likely case (invertY=true, premultiplyAlpha=false, layers=1, faceIndex=0) to avoid dealing with big caches
|
|
1130
|
-
gpuOrHdwTexture = undefined;
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
else {
|
|
1134
|
-
gpuTexture = gpuOrHdwTexture;
|
|
1135
|
-
gpuOrHdwTexture = undefined;
|
|
1136
|
-
}
|
|
1137
|
-
if (!gpuTexture) {
|
|
1138
|
-
return;
|
|
1139
|
-
}
|
|
1140
|
-
if (useRect) {
|
|
1141
|
-
this._bufferManager.setRawData(this._ubCopyWithOfst, 0, new Float32Array([ofstX, ofstY, rectWidth, rectHeight]), 0, 4 * 4);
|
|
1142
|
-
}
|
|
1143
|
-
const webgpuHardwareTexture = gpuOrHdwTexture;
|
|
1144
|
-
const outputTexture = (_c = webgpuHardwareTexture === null || webgpuHardwareTexture === void 0 ? void 0 : webgpuHardwareTexture._copyInvertYTempTexture) !== null && _c !== void 0 ? _c : this.createTexture({ width, height, layers: 1 }, false, false, false, false, false, format, 1, commandEncoder, WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.RenderAttachment | WebGPUConstants.TextureUsage.TextureBinding, undefined, "TempTextureForCopyWithInvertY");
|
|
1145
|
-
const renderPassDescriptor = (_d = webgpuHardwareTexture === null || webgpuHardwareTexture === void 0 ? void 0 : webgpuHardwareTexture._copyInvertYRenderPassDescr) !== null && _d !== void 0 ? _d : {
|
|
1146
|
-
colorAttachments: [
|
|
1147
|
-
{
|
|
1148
|
-
view: outputTexture.createView({
|
|
1149
|
-
format,
|
|
1150
|
-
dimension: WebGPUConstants.TextureViewDimension.E2d,
|
|
1151
|
-
baseMipLevel: 0,
|
|
1152
|
-
mipLevelCount: 1,
|
|
1153
|
-
arrayLayerCount: 1,
|
|
1154
|
-
baseArrayLayer: 0,
|
|
1155
|
-
}),
|
|
1156
|
-
loadOp: WebGPUConstants.LoadOp.Load,
|
|
1157
|
-
storeOp: WebGPUConstants.StoreOp.Store,
|
|
1158
|
-
},
|
|
1159
|
-
],
|
|
1160
|
-
};
|
|
1161
|
-
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
1162
|
-
let bindGroup = useRect ? webgpuHardwareTexture === null || webgpuHardwareTexture === void 0 ? void 0 : webgpuHardwareTexture._copyInvertYBindGroupWithOfst : webgpuHardwareTexture === null || webgpuHardwareTexture === void 0 ? void 0 : webgpuHardwareTexture._copyInvertYBindGroup;
|
|
1163
|
-
if (!bindGroup) {
|
|
1164
|
-
const descriptor = {
|
|
1165
|
-
layout: bindGroupLayout,
|
|
1166
|
-
entries: [
|
|
1167
|
-
{
|
|
1168
|
-
binding: 0,
|
|
1169
|
-
resource: gpuTexture.createView({
|
|
1170
|
-
format,
|
|
1171
|
-
dimension: WebGPUConstants.TextureViewDimension.E2d,
|
|
1172
|
-
baseMipLevel: mipLevel,
|
|
1173
|
-
mipLevelCount: 1,
|
|
1174
|
-
arrayLayerCount: layers,
|
|
1175
|
-
baseArrayLayer: faceIndex,
|
|
1176
|
-
}),
|
|
1177
|
-
},
|
|
1178
|
-
],
|
|
1179
|
-
};
|
|
1180
|
-
if (useRect) {
|
|
1181
|
-
descriptor.entries.push({
|
|
1182
|
-
binding: 1,
|
|
1183
|
-
resource: {
|
|
1184
|
-
buffer: this._ubCopyWithOfst,
|
|
1185
|
-
},
|
|
1186
|
-
});
|
|
1187
|
-
}
|
|
1188
|
-
bindGroup = this._device.createBindGroup(descriptor);
|
|
1189
|
-
}
|
|
1190
|
-
passEncoder.setPipeline(pipeline);
|
|
1191
|
-
passEncoder.setBindGroup(0, bindGroup);
|
|
1192
|
-
passEncoder.draw(4, 1, 0, 0);
|
|
1193
|
-
passEncoder.end();
|
|
1194
|
-
commandEncoder.copyTextureToTexture({
|
|
1195
|
-
texture: outputTexture,
|
|
1196
|
-
}, {
|
|
1197
|
-
texture: gpuTexture,
|
|
1198
|
-
mipLevel,
|
|
1199
|
-
origin: {
|
|
1200
|
-
x: 0,
|
|
1201
|
-
y: 0,
|
|
1202
|
-
z: faceIndex,
|
|
1203
|
-
},
|
|
1204
|
-
}, {
|
|
1205
|
-
width,
|
|
1206
|
-
height,
|
|
1207
|
-
depthOrArrayLayers: 1,
|
|
1208
|
-
});
|
|
1209
|
-
if (webgpuHardwareTexture) {
|
|
1210
|
-
webgpuHardwareTexture._copyInvertYTempTexture = outputTexture;
|
|
1211
|
-
webgpuHardwareTexture._copyInvertYRenderPassDescr = renderPassDescriptor;
|
|
1212
|
-
if (useRect) {
|
|
1213
|
-
webgpuHardwareTexture._copyInvertYBindGroupWithOfst = bindGroup;
|
|
1214
|
-
}
|
|
1215
|
-
else {
|
|
1216
|
-
webgpuHardwareTexture._copyInvertYBindGroup = bindGroup;
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
else {
|
|
1220
|
-
this._deferredReleaseTextures.push([outputTexture, null]);
|
|
1221
|
-
}
|
|
1222
|
-
(_f = (_e = commandEncoder).popDebugGroup) === null || _f === void 0 ? void 0 : _f.call(_e);
|
|
1223
|
-
if (useOwnCommandEncoder) {
|
|
1224
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1225
|
-
commandEncoder = null;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
copyWithInvertY(srcTextureView, format, renderPassDescriptor, commandEncoder) {
|
|
1229
|
-
var _a, _b, _c, _d;
|
|
1230
|
-
const useOwnCommandEncoder = commandEncoder === undefined;
|
|
1231
|
-
const [pipeline, bindGroupLayout] = this._getPipeline(format, PipelineType.InvertYPremultiplyAlpha, { invertY: true, premultiplyAlpha: false });
|
|
1232
|
-
if (useOwnCommandEncoder) {
|
|
1233
|
-
commandEncoder = this._device.createCommandEncoder({});
|
|
1234
|
-
}
|
|
1235
|
-
(_b = (_a = commandEncoder).pushDebugGroup) === null || _b === void 0 ? void 0 : _b.call(_a, `internal copy texture with invertY`);
|
|
1236
|
-
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
1237
|
-
const bindGroup = this._device.createBindGroup({
|
|
1238
|
-
layout: bindGroupLayout,
|
|
1239
|
-
entries: [
|
|
1240
|
-
{
|
|
1241
|
-
binding: 0,
|
|
1242
|
-
resource: srcTextureView,
|
|
1243
|
-
},
|
|
1244
|
-
],
|
|
1245
|
-
});
|
|
1246
|
-
passEncoder.setPipeline(pipeline);
|
|
1247
|
-
passEncoder.setBindGroup(0, bindGroup);
|
|
1248
|
-
passEncoder.draw(4, 1, 0, 0);
|
|
1249
|
-
passEncoder.end();
|
|
1250
|
-
(_d = (_c = commandEncoder).popDebugGroup) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
1251
|
-
if (useOwnCommandEncoder) {
|
|
1252
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1253
|
-
commandEncoder = null;
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
//------------------------------------------------------------------------------
|
|
1257
|
-
// Creation
|
|
1258
|
-
//------------------------------------------------------------------------------
|
|
1259
|
-
createTexture(imageBitmap, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, is3D = false, format = WebGPUConstants.TextureFormat.RGBA8Unorm, sampleCount = 1, commandEncoder, usage = -1, additionalUsages = 0, label) {
|
|
1260
|
-
sampleCount = WebGPUTextureHelper.GetSample(sampleCount);
|
|
1261
|
-
const layerCount = imageBitmap.layers || 1;
|
|
1262
|
-
const textureSize = {
|
|
1263
|
-
width: imageBitmap.width,
|
|
1264
|
-
height: imageBitmap.height,
|
|
1265
|
-
depthOrArrayLayers: layerCount,
|
|
1266
|
-
};
|
|
1267
|
-
const renderAttachmentFlag = renderableTextureFormatToIndex[format] ? WebGPUConstants.TextureUsage.RenderAttachment : 0;
|
|
1268
|
-
const isCompressedFormat = WebGPUTextureHelper.IsCompressedFormat(format);
|
|
1269
|
-
const mipLevelCount = hasMipmaps ? WebGPUTextureHelper.ComputeNumMipmapLevels(imageBitmap.width, imageBitmap.height) : 1;
|
|
1270
|
-
const usages = usage >= 0 ? usage : WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.TextureBinding;
|
|
1271
|
-
additionalUsages |= hasMipmaps && !isCompressedFormat ? WebGPUConstants.TextureUsage.CopySrc | renderAttachmentFlag : 0;
|
|
1272
|
-
if (!isCompressedFormat && !is3D) {
|
|
1273
|
-
// we don't know in advance if the texture will be updated with copyExternalImageToTexture (which requires to have those flags), so we need to force the flags all the times
|
|
1274
|
-
additionalUsages |= renderAttachmentFlag | WebGPUConstants.TextureUsage.CopyDst;
|
|
1275
|
-
}
|
|
1276
|
-
const gpuTexture = this._device.createTexture({
|
|
1277
|
-
label: `Texture${is3D ? "3D" : "2D"}_${label ? label + "_" : ""}${textureSize.width}x${textureSize.height}x${textureSize.depthOrArrayLayers}_${hasMipmaps ? "wmips" : "womips"}_${format}_samples${sampleCount}`,
|
|
1278
|
-
size: textureSize,
|
|
1279
|
-
dimension: is3D ? WebGPUConstants.TextureDimension.E3d : WebGPUConstants.TextureDimension.E2d,
|
|
1280
|
-
format,
|
|
1281
|
-
usage: usages | additionalUsages,
|
|
1282
|
-
sampleCount,
|
|
1283
|
-
mipLevelCount,
|
|
1284
|
-
});
|
|
1285
|
-
if (WebGPUTextureHelper.IsImageBitmap(imageBitmap)) {
|
|
1286
|
-
this.updateTexture(imageBitmap, gpuTexture, imageBitmap.width, imageBitmap.height, layerCount, format, 0, 0, invertY, premultiplyAlpha, 0, 0);
|
|
1287
|
-
if (hasMipmaps && generateMipmaps) {
|
|
1288
|
-
this.generateMipmaps(gpuTexture, format, mipLevelCount, 0, commandEncoder);
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
return gpuTexture;
|
|
1292
|
-
}
|
|
1293
|
-
createCubeTexture(imageBitmaps, hasMipmaps = false, generateMipmaps = false, invertY = false, premultiplyAlpha = false, format = WebGPUConstants.TextureFormat.RGBA8Unorm, sampleCount = 1, commandEncoder, usage = -1, additionalUsages = 0, label) {
|
|
1294
|
-
sampleCount = WebGPUTextureHelper.GetSample(sampleCount);
|
|
1295
|
-
const width = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].width : imageBitmaps.width;
|
|
1296
|
-
const height = WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps) ? imageBitmaps[0].height : imageBitmaps.height;
|
|
1297
|
-
const renderAttachmentFlag = renderableTextureFormatToIndex[format] ? WebGPUConstants.TextureUsage.RenderAttachment : 0;
|
|
1298
|
-
const isCompressedFormat = WebGPUTextureHelper.IsCompressedFormat(format);
|
|
1299
|
-
const mipLevelCount = hasMipmaps ? WebGPUTextureHelper.ComputeNumMipmapLevels(width, height) : 1;
|
|
1300
|
-
const usages = usage >= 0 ? usage : WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.CopyDst | WebGPUConstants.TextureUsage.TextureBinding;
|
|
1301
|
-
additionalUsages |= hasMipmaps && !isCompressedFormat ? WebGPUConstants.TextureUsage.CopySrc | renderAttachmentFlag : 0;
|
|
1302
|
-
if (!isCompressedFormat) {
|
|
1303
|
-
// we don't know in advance if the texture will be updated with copyExternalImageToTexture (which requires to have those flags), so we need to force the flags all the times
|
|
1304
|
-
additionalUsages |= renderAttachmentFlag | WebGPUConstants.TextureUsage.CopyDst;
|
|
1305
|
-
}
|
|
1306
|
-
const gpuTexture = this._device.createTexture({
|
|
1307
|
-
label: `TextureCube_${label ? label + "_" : ""}${width}x${height}x6_${hasMipmaps ? "wmips" : "womips"}_${format}_samples${sampleCount}`,
|
|
1308
|
-
size: {
|
|
1309
|
-
width,
|
|
1310
|
-
height,
|
|
1311
|
-
depthOrArrayLayers: 6,
|
|
1312
|
-
},
|
|
1313
|
-
dimension: WebGPUConstants.TextureDimension.E2d,
|
|
1314
|
-
format,
|
|
1315
|
-
usage: usages | additionalUsages,
|
|
1316
|
-
sampleCount,
|
|
1317
|
-
mipLevelCount,
|
|
1318
|
-
});
|
|
1319
|
-
if (WebGPUTextureHelper.IsImageBitmapArray(imageBitmaps)) {
|
|
1320
|
-
this.updateCubeTextures(imageBitmaps, gpuTexture, width, height, format, invertY, premultiplyAlpha, 0, 0);
|
|
1321
|
-
if (hasMipmaps && generateMipmaps) {
|
|
1322
|
-
this.generateCubeMipmaps(gpuTexture, format, mipLevelCount, commandEncoder);
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
return gpuTexture;
|
|
1326
|
-
}
|
|
1327
|
-
generateCubeMipmaps(gpuTexture, format, mipLevelCount, commandEncoder) {
|
|
1328
|
-
var _a, _b, _c, _d;
|
|
1329
|
-
const useOwnCommandEncoder = commandEncoder === undefined;
|
|
1330
|
-
if (useOwnCommandEncoder) {
|
|
1331
|
-
commandEncoder = this._device.createCommandEncoder({});
|
|
1332
|
-
}
|
|
1333
|
-
(_b = (_a = commandEncoder).pushDebugGroup) === null || _b === void 0 ? void 0 : _b.call(_a, `create cube mipmaps - ${mipLevelCount} levels`);
|
|
1334
|
-
for (let f = 0; f < 6; ++f) {
|
|
1335
|
-
this.generateMipmaps(gpuTexture, format, mipLevelCount, f, commandEncoder);
|
|
1336
|
-
}
|
|
1337
|
-
(_d = (_c = commandEncoder).popDebugGroup) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
1338
|
-
if (useOwnCommandEncoder) {
|
|
1339
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1340
|
-
commandEncoder = null;
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
generateMipmaps(gpuOrHdwTexture, format, mipLevelCount, faceIndex = 0, commandEncoder) {
|
|
1344
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1345
|
-
const useOwnCommandEncoder = commandEncoder === undefined;
|
|
1346
|
-
const [pipeline, bindGroupLayout] = this._getPipeline(format);
|
|
1347
|
-
faceIndex = Math.max(faceIndex, 0);
|
|
1348
|
-
if (useOwnCommandEncoder) {
|
|
1349
|
-
commandEncoder = this._device.createCommandEncoder({});
|
|
1350
|
-
}
|
|
1351
|
-
(_b = (_a = commandEncoder).pushDebugGroup) === null || _b === void 0 ? void 0 : _b.call(_a, `create mipmaps for face #${faceIndex} - ${mipLevelCount} levels`);
|
|
1352
|
-
let gpuTexture;
|
|
1353
|
-
if (WebGPUTextureHelper._IsHardwareTexture(gpuOrHdwTexture)) {
|
|
1354
|
-
gpuTexture = gpuOrHdwTexture.underlyingResource;
|
|
1355
|
-
gpuOrHdwTexture._mipmapGenRenderPassDescr = gpuOrHdwTexture._mipmapGenRenderPassDescr || [];
|
|
1356
|
-
gpuOrHdwTexture._mipmapGenBindGroup = gpuOrHdwTexture._mipmapGenBindGroup || [];
|
|
1357
|
-
}
|
|
1358
|
-
else {
|
|
1359
|
-
gpuTexture = gpuOrHdwTexture;
|
|
1360
|
-
gpuOrHdwTexture = undefined;
|
|
1361
|
-
}
|
|
1362
|
-
if (!gpuTexture) {
|
|
1363
|
-
return;
|
|
1364
|
-
}
|
|
1365
|
-
const webgpuHardwareTexture = gpuOrHdwTexture;
|
|
1366
|
-
for (let i = 1; i < mipLevelCount; ++i) {
|
|
1367
|
-
const renderPassDescriptor = (_d = (_c = webgpuHardwareTexture === null || webgpuHardwareTexture === void 0 ? void 0 : webgpuHardwareTexture._mipmapGenRenderPassDescr[faceIndex]) === null || _c === void 0 ? void 0 : _c[i - 1]) !== null && _d !== void 0 ? _d : {
|
|
1368
|
-
colorAttachments: [
|
|
1369
|
-
{
|
|
1370
|
-
view: gpuTexture.createView({
|
|
1371
|
-
format,
|
|
1372
|
-
dimension: WebGPUConstants.TextureViewDimension.E2d,
|
|
1373
|
-
baseMipLevel: i,
|
|
1374
|
-
mipLevelCount: 1,
|
|
1375
|
-
arrayLayerCount: 1,
|
|
1376
|
-
baseArrayLayer: faceIndex,
|
|
1377
|
-
}),
|
|
1378
|
-
loadOp: WebGPUConstants.LoadOp.Load,
|
|
1379
|
-
storeOp: WebGPUConstants.StoreOp.Store,
|
|
1380
|
-
},
|
|
1381
|
-
],
|
|
1382
|
-
};
|
|
1383
|
-
if (webgpuHardwareTexture) {
|
|
1384
|
-
webgpuHardwareTexture._mipmapGenRenderPassDescr[faceIndex] = webgpuHardwareTexture._mipmapGenRenderPassDescr[faceIndex] || [];
|
|
1385
|
-
webgpuHardwareTexture._mipmapGenRenderPassDescr[faceIndex][i - 1] = renderPassDescriptor;
|
|
1386
|
-
}
|
|
1387
|
-
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
1388
|
-
const bindGroup = (_f = (_e = webgpuHardwareTexture === null || webgpuHardwareTexture === void 0 ? void 0 : webgpuHardwareTexture._mipmapGenBindGroup[faceIndex]) === null || _e === void 0 ? void 0 : _e[i - 1]) !== null && _f !== void 0 ? _f : this._device.createBindGroup({
|
|
1389
|
-
layout: bindGroupLayout,
|
|
1390
|
-
entries: [
|
|
1391
|
-
{
|
|
1392
|
-
binding: 0,
|
|
1393
|
-
resource: this._mipmapSampler,
|
|
1394
|
-
},
|
|
1395
|
-
{
|
|
1396
|
-
binding: 1,
|
|
1397
|
-
resource: gpuTexture.createView({
|
|
1398
|
-
format,
|
|
1399
|
-
dimension: WebGPUConstants.TextureViewDimension.E2d,
|
|
1400
|
-
baseMipLevel: i - 1,
|
|
1401
|
-
mipLevelCount: 1,
|
|
1402
|
-
arrayLayerCount: 1,
|
|
1403
|
-
baseArrayLayer: faceIndex,
|
|
1404
|
-
}),
|
|
1405
|
-
},
|
|
1406
|
-
],
|
|
1407
|
-
});
|
|
1408
|
-
if (webgpuHardwareTexture) {
|
|
1409
|
-
webgpuHardwareTexture._mipmapGenBindGroup[faceIndex] = webgpuHardwareTexture._mipmapGenBindGroup[faceIndex] || [];
|
|
1410
|
-
webgpuHardwareTexture._mipmapGenBindGroup[faceIndex][i - 1] = bindGroup;
|
|
1411
|
-
}
|
|
1412
|
-
passEncoder.setPipeline(pipeline);
|
|
1413
|
-
passEncoder.setBindGroup(0, bindGroup);
|
|
1414
|
-
passEncoder.draw(4, 1, 0, 0);
|
|
1415
|
-
passEncoder.end();
|
|
1416
|
-
}
|
|
1417
|
-
(_h = (_g = commandEncoder).popDebugGroup) === null || _h === void 0 ? void 0 : _h.call(_g);
|
|
1418
|
-
if (useOwnCommandEncoder) {
|
|
1419
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1420
|
-
commandEncoder = null;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
createGPUTextureForInternalTexture(texture, width, height, depth, creationFlags) {
|
|
1424
|
-
if (!texture._hardwareTexture) {
|
|
1425
|
-
texture._hardwareTexture = new WebGPUHardwareTexture();
|
|
1426
|
-
}
|
|
1427
|
-
if (width === undefined) {
|
|
1428
|
-
width = texture.width;
|
|
1429
|
-
}
|
|
1430
|
-
if (height === undefined) {
|
|
1431
|
-
height = texture.height;
|
|
1432
|
-
}
|
|
1433
|
-
if (depth === undefined) {
|
|
1434
|
-
depth = texture.depth;
|
|
1435
|
-
}
|
|
1436
|
-
const gpuTextureWrapper = texture._hardwareTexture;
|
|
1437
|
-
const isStorageTexture = ((creationFlags !== null && creationFlags !== void 0 ? creationFlags : 0) & 1) !== 0;
|
|
1438
|
-
gpuTextureWrapper.format = WebGPUTextureHelper.GetWebGPUTextureFormat(texture.type, texture.format, texture._useSRGBBuffer);
|
|
1439
|
-
gpuTextureWrapper.textureUsages =
|
|
1440
|
-
texture._source === InternalTextureSource.RenderTarget || texture.source === InternalTextureSource.MultiRenderTarget
|
|
1441
|
-
? WebGPUConstants.TextureUsage.TextureBinding | WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.RenderAttachment
|
|
1442
|
-
: texture._source === InternalTextureSource.DepthStencil
|
|
1443
|
-
? WebGPUConstants.TextureUsage.TextureBinding | WebGPUConstants.TextureUsage.RenderAttachment
|
|
1444
|
-
: -1;
|
|
1445
|
-
gpuTextureWrapper.textureAdditionalUsages = isStorageTexture ? WebGPUConstants.TextureUsage.StorageBinding : 0;
|
|
1446
|
-
const hasMipMaps = texture.generateMipMaps;
|
|
1447
|
-
const layerCount = depth || 1;
|
|
1448
|
-
let mipmapCount;
|
|
1449
|
-
if (texture._maxLodLevel !== null) {
|
|
1450
|
-
mipmapCount = texture._maxLodLevel;
|
|
1451
|
-
}
|
|
1452
|
-
else {
|
|
1453
|
-
mipmapCount = hasMipMaps ? WebGPUTextureHelper.ComputeNumMipmapLevels(width, height) : 1;
|
|
1454
|
-
}
|
|
1455
|
-
if (texture.isCube) {
|
|
1456
|
-
const gpuTexture = this.createCubeTexture({ width, height }, texture.generateMipMaps, texture.generateMipMaps, texture.invertY, false, gpuTextureWrapper.format, 1, this._commandEncoderForCreation, gpuTextureWrapper.textureUsages, gpuTextureWrapper.textureAdditionalUsages, texture.label);
|
|
1457
|
-
gpuTextureWrapper.set(gpuTexture);
|
|
1458
|
-
gpuTextureWrapper.createView({
|
|
1459
|
-
format: WebGPUTextureHelper.GetDepthFormatOnly(gpuTextureWrapper.format),
|
|
1460
|
-
dimension: WebGPUConstants.TextureViewDimension.Cube,
|
|
1461
|
-
mipLevelCount: mipmapCount,
|
|
1462
|
-
baseArrayLayer: 0,
|
|
1463
|
-
baseMipLevel: 0,
|
|
1464
|
-
arrayLayerCount: 6,
|
|
1465
|
-
aspect: WebGPUTextureHelper.HasDepthAndStencilAspects(gpuTextureWrapper.format) ? WebGPUConstants.TextureAspect.DepthOnly : WebGPUConstants.TextureAspect.All,
|
|
1466
|
-
}, isStorageTexture);
|
|
1467
|
-
}
|
|
1468
|
-
else {
|
|
1469
|
-
const gpuTexture = this.createTexture({ width, height, layers: layerCount }, texture.generateMipMaps, texture.generateMipMaps, texture.invertY, false, texture.is3D, gpuTextureWrapper.format, 1, this._commandEncoderForCreation, gpuTextureWrapper.textureUsages, gpuTextureWrapper.textureAdditionalUsages, texture.label);
|
|
1470
|
-
gpuTextureWrapper.set(gpuTexture);
|
|
1471
|
-
gpuTextureWrapper.createView({
|
|
1472
|
-
format: WebGPUTextureHelper.GetDepthFormatOnly(gpuTextureWrapper.format),
|
|
1473
|
-
dimension: texture.is2DArray
|
|
1474
|
-
? WebGPUConstants.TextureViewDimension.E2dArray
|
|
1475
|
-
: texture.is3D
|
|
1476
|
-
? WebGPUConstants.TextureDimension.E3d
|
|
1477
|
-
: WebGPUConstants.TextureViewDimension.E2d,
|
|
1478
|
-
mipLevelCount: mipmapCount,
|
|
1479
|
-
baseArrayLayer: 0,
|
|
1480
|
-
baseMipLevel: 0,
|
|
1481
|
-
arrayLayerCount: texture.is3D ? 1 : layerCount,
|
|
1482
|
-
aspect: WebGPUTextureHelper.HasDepthAndStencilAspects(gpuTextureWrapper.format) ? WebGPUConstants.TextureAspect.DepthOnly : WebGPUConstants.TextureAspect.All,
|
|
1483
|
-
}, isStorageTexture);
|
|
1484
|
-
}
|
|
1485
|
-
texture.width = texture.baseWidth = width;
|
|
1486
|
-
texture.height = texture.baseHeight = height;
|
|
1487
|
-
texture.depth = texture.baseDepth = depth;
|
|
1488
|
-
this.createMSAATexture(texture, texture.samples);
|
|
1489
|
-
return gpuTextureWrapper;
|
|
1490
|
-
}
|
|
1491
|
-
createMSAATexture(texture, samples, releaseExisting = true, index = -1) {
|
|
1492
|
-
const gpuTextureWrapper = texture._hardwareTexture;
|
|
1493
|
-
if (releaseExisting) {
|
|
1494
|
-
gpuTextureWrapper === null || gpuTextureWrapper === void 0 ? void 0 : gpuTextureWrapper.releaseMSAATexture();
|
|
1495
|
-
}
|
|
1496
|
-
if (!gpuTextureWrapper || (samples !== null && samples !== void 0 ? samples : 1) <= 1) {
|
|
1497
|
-
return;
|
|
1498
|
-
}
|
|
1499
|
-
const width = texture.width;
|
|
1500
|
-
const height = texture.height;
|
|
1501
|
-
const gpuMSAATexture = this.createTexture({ width, height, layers: 1 }, false, false, false, false, false, gpuTextureWrapper.format, samples, this._commandEncoderForCreation, WebGPUConstants.TextureUsage.RenderAttachment, 0, texture.label ? "MSAA" + texture.label : undefined);
|
|
1502
|
-
gpuTextureWrapper.setMSAATexture(gpuMSAATexture, index);
|
|
1503
|
-
}
|
|
1504
|
-
//------------------------------------------------------------------------------
|
|
1505
|
-
// Update
|
|
1506
|
-
//------------------------------------------------------------------------------
|
|
1507
|
-
updateCubeTextures(imageBitmaps, gpuTexture, width, height, format, invertY = false, premultiplyAlpha = false, offsetX = 0, offsetY = 0) {
|
|
1508
|
-
const faces = [0, 3, 1, 4, 2, 5];
|
|
1509
|
-
for (let f = 0; f < faces.length; ++f) {
|
|
1510
|
-
const imageBitmap = imageBitmaps[faces[f]];
|
|
1511
|
-
this.updateTexture(imageBitmap, gpuTexture, width, height, 1, format, f, 0, invertY, premultiplyAlpha, offsetX, offsetY);
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
// TODO WEBGPU handle data source not being in the same format than the destination texture?
|
|
1515
|
-
updateTexture(imageBitmap, texture, width, height, layers, format, faceIndex = 0, mipLevel = 0, invertY = false, premultiplyAlpha = false, offsetX = 0, offsetY = 0, allowGPUOptimization) {
|
|
1516
|
-
const gpuTexture = WebGPUTextureHelper._IsInternalTexture(texture) ? texture._hardwareTexture.underlyingResource : texture;
|
|
1517
|
-
const blockInformation = WebGPUTextureHelper._GetBlockInformationFromFormat(format);
|
|
1518
|
-
const gpuOrHdwTexture = WebGPUTextureHelper._IsInternalTexture(texture) ? texture._hardwareTexture : texture;
|
|
1519
|
-
const textureCopyView = {
|
|
1520
|
-
texture: gpuTexture,
|
|
1521
|
-
origin: {
|
|
1522
|
-
x: offsetX,
|
|
1523
|
-
y: offsetY,
|
|
1524
|
-
z: Math.max(faceIndex, 0),
|
|
1525
|
-
},
|
|
1526
|
-
mipLevel: mipLevel,
|
|
1527
|
-
premultipliedAlpha: premultiplyAlpha,
|
|
1528
|
-
};
|
|
1529
|
-
const textureExtent = {
|
|
1530
|
-
width: Math.ceil(width / blockInformation.width) * blockInformation.width,
|
|
1531
|
-
height: Math.ceil(height / blockInformation.height) * blockInformation.height,
|
|
1532
|
-
depthOrArrayLayers: layers || 1,
|
|
1533
|
-
};
|
|
1534
|
-
if (imageBitmap.byteLength !== undefined) {
|
|
1535
|
-
imageBitmap = imageBitmap;
|
|
1536
|
-
const bytesPerRow = Math.ceil(width / blockInformation.width) * blockInformation.length;
|
|
1537
|
-
const aligned = Math.ceil(bytesPerRow / 256) * 256 === bytesPerRow;
|
|
1538
|
-
if (aligned) {
|
|
1539
|
-
const commandEncoder = this._device.createCommandEncoder({});
|
|
1540
|
-
const buffer = this._bufferManager.createRawBuffer(imageBitmap.byteLength, WebGPUConstants.BufferUsage.MapWrite | WebGPUConstants.BufferUsage.CopySrc, true, "TempBufferForUpdateTexture" + (gpuTexture ? "_" + gpuTexture.label : ""));
|
|
1541
|
-
const arrayBuffer = buffer.getMappedRange();
|
|
1542
|
-
new Uint8Array(arrayBuffer).set(imageBitmap);
|
|
1543
|
-
buffer.unmap();
|
|
1544
|
-
commandEncoder.copyBufferToTexture({
|
|
1545
|
-
buffer: buffer,
|
|
1546
|
-
offset: 0,
|
|
1547
|
-
bytesPerRow,
|
|
1548
|
-
rowsPerImage: height,
|
|
1549
|
-
}, textureCopyView, textureExtent);
|
|
1550
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1551
|
-
this._bufferManager.releaseBuffer(buffer);
|
|
1552
|
-
}
|
|
1553
|
-
else {
|
|
1554
|
-
this._device.queue.writeTexture(textureCopyView, imageBitmap, {
|
|
1555
|
-
offset: 0,
|
|
1556
|
-
bytesPerRow,
|
|
1557
|
-
rowsPerImage: height,
|
|
1558
|
-
}, textureExtent);
|
|
1559
|
-
}
|
|
1560
|
-
if (invertY || premultiplyAlpha) {
|
|
1561
|
-
if (WebGPUTextureHelper._IsInternalTexture(texture)) {
|
|
1562
|
-
const dontUseRect = offsetX === 0 && offsetY === 0 && width === texture.width && height === texture.height;
|
|
1563
|
-
this.invertYPreMultiplyAlpha(gpuOrHdwTexture, texture.width, texture.height, format, invertY, premultiplyAlpha, faceIndex, mipLevel, layers || 1, offsetX, offsetY, dontUseRect ? 0 : width, dontUseRect ? 0 : height, undefined, allowGPUOptimization);
|
|
1564
|
-
}
|
|
1565
|
-
else {
|
|
1566
|
-
// we should never take this code path
|
|
1567
|
-
throw "updateTexture: Can't process the texture data because a GPUTexture was provided instead of an InternalTexture!";
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
else {
|
|
1572
|
-
imageBitmap = imageBitmap;
|
|
1573
|
-
if (invertY) {
|
|
1574
|
-
textureCopyView.premultipliedAlpha = false; // we are going to handle premultiplyAlpha ourselves
|
|
1575
|
-
// we must preprocess the image
|
|
1576
|
-
if (WebGPUTextureHelper._IsInternalTexture(texture) && offsetX === 0 && offsetY === 0 && width === texture.width && height === texture.height) {
|
|
1577
|
-
// optimization when the source image is the same size than the destination texture and offsets X/Y == 0:
|
|
1578
|
-
// we simply copy the source to the destination and we apply the preprocessing on the destination
|
|
1579
|
-
this._device.queue.copyExternalImageToTexture({ source: imageBitmap }, textureCopyView, textureExtent);
|
|
1580
|
-
this.invertYPreMultiplyAlpha(gpuOrHdwTexture, width, height, format, invertY, premultiplyAlpha, faceIndex, mipLevel, layers || 1, 0, 0, 0, 0, undefined, allowGPUOptimization);
|
|
1581
|
-
}
|
|
1582
|
-
else {
|
|
1583
|
-
// we must apply the preprocessing on the source image before copying it into the destination texture
|
|
1584
|
-
const commandEncoder = this._device.createCommandEncoder({});
|
|
1585
|
-
// create a temp texture and copy the image to it
|
|
1586
|
-
const srcTexture = this.createTexture({ width, height, layers: 1 }, false, false, false, false, false, format, 1, commandEncoder, WebGPUConstants.TextureUsage.CopySrc | WebGPUConstants.TextureUsage.TextureBinding, undefined, "TempTextureForUpdateTexture");
|
|
1587
|
-
this._deferredReleaseTextures.push([srcTexture, null]);
|
|
1588
|
-
textureExtent.depthOrArrayLayers = 1;
|
|
1589
|
-
this._device.queue.copyExternalImageToTexture({ source: imageBitmap }, { texture: srcTexture }, textureExtent);
|
|
1590
|
-
textureExtent.depthOrArrayLayers = layers || 1;
|
|
1591
|
-
// apply the preprocessing to this temp texture
|
|
1592
|
-
this.invertYPreMultiplyAlpha(srcTexture, width, height, format, invertY, premultiplyAlpha, faceIndex, mipLevel, layers || 1, 0, 0, 0, 0, commandEncoder, allowGPUOptimization);
|
|
1593
|
-
// copy the temp texture to the destination texture
|
|
1594
|
-
commandEncoder.copyTextureToTexture({ texture: srcTexture }, textureCopyView, textureExtent);
|
|
1595
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
else {
|
|
1599
|
-
// no preprocessing: direct copy to destination texture
|
|
1600
|
-
this._device.queue.copyExternalImageToTexture({ source: imageBitmap }, textureCopyView, textureExtent);
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
readPixels(texture, x, y, width, height, format, faceIndex = 0, mipLevel = 0, buffer = null, noDataConversion = false) {
|
|
1605
|
-
const blockInformation = WebGPUTextureHelper._GetBlockInformationFromFormat(format);
|
|
1606
|
-
const bytesPerRow = Math.ceil(width / blockInformation.width) * blockInformation.length;
|
|
1607
|
-
const bytesPerRowAligned = Math.ceil(bytesPerRow / 256) * 256;
|
|
1608
|
-
const size = bytesPerRowAligned * height;
|
|
1609
|
-
const gpuBuffer = this._bufferManager.createRawBuffer(size, WebGPUConstants.BufferUsage.MapRead | WebGPUConstants.BufferUsage.CopyDst, undefined, "TempBufferForReadPixels" + (texture.label ? "_" + texture.label : ""));
|
|
1610
|
-
const commandEncoder = this._device.createCommandEncoder({});
|
|
1611
|
-
commandEncoder.copyTextureToBuffer({
|
|
1612
|
-
texture,
|
|
1613
|
-
mipLevel,
|
|
1614
|
-
origin: {
|
|
1615
|
-
x,
|
|
1616
|
-
y,
|
|
1617
|
-
z: Math.max(faceIndex, 0),
|
|
1618
|
-
},
|
|
1619
|
-
}, {
|
|
1620
|
-
buffer: gpuBuffer,
|
|
1621
|
-
offset: 0,
|
|
1622
|
-
bytesPerRow: bytesPerRowAligned,
|
|
1623
|
-
}, {
|
|
1624
|
-
width,
|
|
1625
|
-
height,
|
|
1626
|
-
depthOrArrayLayers: 1,
|
|
1627
|
-
});
|
|
1628
|
-
this._device.queue.submit([commandEncoder.finish()]);
|
|
1629
|
-
return this._bufferManager.readDataFromBuffer(gpuBuffer, size, width, height, bytesPerRow, bytesPerRowAligned, WebGPUTextureHelper.GetTextureTypeFromFormat(format), 0, buffer, true, noDataConversion);
|
|
1630
|
-
}
|
|
1631
|
-
//------------------------------------------------------------------------------
|
|
1632
|
-
// Dispose
|
|
1633
|
-
//------------------------------------------------------------------------------
|
|
1634
|
-
releaseTexture(texture) {
|
|
1635
|
-
if (WebGPUTextureHelper._IsInternalTexture(texture)) {
|
|
1636
|
-
const hardwareTexture = texture._hardwareTexture;
|
|
1637
|
-
const irradianceTexture = texture._irradianceTexture;
|
|
1638
|
-
// We can't destroy the objects just now because they could be used in the current frame - we delay the destroying after the end of the frame
|
|
1639
|
-
this._deferredReleaseTextures.push([hardwareTexture, irradianceTexture]);
|
|
1640
|
-
}
|
|
1641
|
-
else {
|
|
1642
|
-
this._deferredReleaseTextures.push([texture, null]);
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
destroyDeferredTextures() {
|
|
1646
|
-
for (let i = 0; i < this._deferredReleaseTextures.length; ++i) {
|
|
1647
|
-
const [hardwareTexture, irradianceTexture] = this._deferredReleaseTextures[i];
|
|
1648
|
-
if (hardwareTexture) {
|
|
1649
|
-
if (WebGPUTextureHelper._IsHardwareTexture(hardwareTexture)) {
|
|
1650
|
-
hardwareTexture.release();
|
|
1651
|
-
}
|
|
1652
|
-
else {
|
|
1653
|
-
hardwareTexture.destroy();
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
irradianceTexture === null || irradianceTexture === void 0 ? void 0 : irradianceTexture.dispose();
|
|
1657
|
-
}
|
|
1658
|
-
this._deferredReleaseTextures.length = 0;
|
|
1659
|
-
}
|
|
1660
668
|
}
|
|
1661
669
|
//# sourceMappingURL=webgpuTextureHelper.js.map
|