@driftengine/core 4.4.2 → 4.6.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/CHANGELOG.json +97 -0
- package/README.md +1 -1
- package/dist/geometry/boxCsg.d.ts +28 -0
- package/dist/geometry/boxCsg.js +139 -0
- package/dist/geometry/csg.d.ts +36 -0
- package/dist/geometry/csg.js +329 -0
- package/dist/geometry/meshBuilder.js +13 -0
- package/dist/geometry/meshConcat.js +1 -0
- package/dist/geometry/pixelFont.js +2 -0
- package/dist/geometry/solid.d.ts +61 -0
- package/dist/geometry/solid.js +152 -0
- package/dist/geometry/solidFlat.d.ts +35 -0
- package/dist/geometry/solidFlat.js +428 -0
- package/dist/geometry/solidHarness.d.ts +19 -0
- package/dist/geometry/solidHarness.js +66 -0
- package/dist/geometry/solidNormals.d.ts +17 -0
- package/dist/geometry/solidNormals.js +86 -0
- package/dist/geometry/solidRound.d.ts +41 -0
- package/dist/geometry/solidRound.js +323 -0
- package/dist/geometry/solidWriter.d.ts +16 -0
- package/dist/geometry/solidWriter.js +42 -0
- package/dist/index.d.ts +28 -3
- package/dist/index.js +20 -1
- package/dist/render/backend/api.d.ts +34 -14
- package/dist/render/backend/drawFog.d.ts +26 -0
- package/dist/render/backend/drawFog.js +30 -0
- package/dist/render/backend/materialChanges.d.ts +2 -1
- package/dist/render/backend/materialChanges.js +6 -1
- package/dist/render/backend/webgl2/glassTintPrograms.d.ts +13 -0
- package/dist/render/backend/webgl2/glassTintPrograms.js +38 -0
- package/dist/render/backend/webgl2/instanced.d.ts +24 -5
- package/dist/render/backend/webgl2/instanced.js +72 -15
- package/dist/render/backend/webgl2/renderer.d.ts +201 -16
- package/dist/render/backend/webgl2/renderer.js +596 -224
- package/dist/render/backend/webgpu/buffers.d.ts +29 -1
- package/dist/render/backend/webgpu/buffers.js +61 -4
- package/dist/render/backend/webgpu/depthPass.d.ts +1 -1
- package/dist/render/backend/webgpu/depthPass.js +7 -2
- package/dist/render/backend/webgpu/drawCommand.d.ts +5 -0
- package/dist/render/backend/webgpu/drawCommand.js +1 -0
- package/dist/render/backend/webgpu/flatPass.d.ts +6 -1
- package/dist/render/backend/webgpu/flatPass.js +57 -9
- package/dist/render/backend/webgpu/glassTintPass.d.ts +28 -0
- package/dist/render/backend/webgpu/glassTintPass.js +206 -0
- package/dist/render/backend/webgpu/gpuDrivenPass.d.ts +60 -1
- package/dist/render/backend/webgpu/gpuDrivenPass.js +305 -5
- package/dist/render/backend/webgpu/instanceCullPass.d.ts +34 -0
- package/dist/render/backend/webgpu/instanceCullPass.js +144 -0
- package/dist/render/backend/webgpu/instanced.d.ts +23 -2
- package/dist/render/backend/webgpu/instanced.js +41 -4
- package/dist/render/backend/webgpu/latePass.d.ts +30 -0
- package/dist/render/backend/webgpu/latePass.js +140 -0
- package/dist/render/backend/webgpu/lightVolumePass.js +5 -1
- package/dist/render/backend/webgpu/motionPass.d.ts +95 -0
- package/dist/render/backend/webgpu/motionPass.js +491 -0
- package/dist/render/backend/webgpu/pipelineCache.d.ts +10 -1
- package/dist/render/backend/webgpu/pipelineCache.js +11 -1
- package/dist/render/backend/webgpu/pointGlassTintPass.d.ts +32 -0
- package/dist/render/backend/webgpu/pointGlassTintPass.js +193 -0
- package/dist/render/backend/webgpu/pointShadowPass.d.ts +35 -6
- package/dist/render/backend/webgpu/pointShadowPass.js +105 -20
- package/dist/render/backend/webgpu/postPass.d.ts +3 -13
- package/dist/render/backend/webgpu/renderer.d.ts +271 -64
- package/dist/render/backend/webgpu/renderer.js +1395 -580
- package/dist/render/backend/webgpu/scatterPass.js +2 -1
- package/dist/render/backend/webgpu/sdfTextPass.js +6 -1
- package/dist/render/backend/webgpu/shaders/instanceCull.wgsl.d.ts +18 -0
- package/dist/render/backend/webgpu/shaders/instanceCull.wgsl.js +59 -0
- package/dist/render/backend/webgpu/skinPaletteRing.d.ts +4 -0
- package/dist/render/backend/webgpu/skinPaletteRing.js +4 -0
- package/dist/render/backend/webgpu/snapshotMips.d.ts +29 -0
- package/dist/render/backend/webgpu/snapshotMips.js +52 -0
- package/dist/render/backend/webgpu/surfaceTexturePass.d.ts +22 -3
- package/dist/render/backend/webgpu/surfaceTexturePass.js +78 -39
- package/dist/render/driftLight/bake.d.ts +7 -0
- package/dist/render/driftLight/bake.js +61 -56
- package/dist/render/driftLight/denseField.d.ts +46 -0
- package/dist/render/driftLight/denseField.js +109 -0
- package/dist/render/driftLight/lightField.d.ts +10 -5
- package/dist/render/driftLight/lightField.js +25 -19
- package/dist/render/driftLight/presence.d.ts +50 -0
- package/dist/render/driftLight/presence.js +43 -0
- package/dist/render/driftLight/uniforms.d.ts +3 -3
- package/dist/render/driftLight/uniforms.js +5 -6
- package/dist/render/driftLight/worldLightField.d.ts +41 -0
- package/dist/render/driftLight/worldLightField.js +66 -0
- package/dist/render/fixtureAtlas.d.ts +20 -0
- package/dist/render/fixtureAtlas.js +49 -0
- package/dist/render/glass.d.ts +45 -0
- package/dist/render/glass.js +39 -0
- package/dist/render/glassCasters.d.ts +40 -0
- package/dist/render/glassCasters.js +84 -0
- package/dist/render/glassShadow.d.ts +78 -0
- package/dist/render/glassShadow.js +125 -0
- package/dist/render/globalMediumPass.d.ts +2 -3
- package/dist/render/globalMediumPass.js +2 -8
- package/dist/render/gpudriven/lit.d.ts +12 -0
- package/dist/render/gpudriven/lit.js +23 -0
- package/dist/render/gpudriven/materialTable.d.ts +15 -5
- package/dist/render/gpudriven/materialTable.js +26 -6
- package/dist/render/gpudriven/pipeline.d.ts +1 -1
- package/dist/render/gpudriven/pipeline.js +4 -3
- package/dist/render/gpudriven/sunGlass.d.ts +35 -0
- package/dist/render/gpudriven/sunGlass.js +89 -0
- package/dist/render/instanceCull.d.ts +63 -0
- package/dist/render/instanceCull.js +160 -0
- package/dist/render/instances.d.ts +15 -0
- package/dist/render/lightBudget.d.ts +36 -35
- package/dist/render/lightBudget.js +38 -37
- package/dist/render/lightGrid.d.ts +42 -0
- package/dist/render/lightGrid.js +87 -0
- package/dist/render/mesh.d.ts +18 -24
- package/dist/render/mesh.js +51 -68
- package/dist/render/occlusion.d.ts +10 -0
- package/dist/render/occlusion.js +36 -7
- package/dist/render/pointGlassTint.d.ts +59 -0
- package/dist/render/pointGlassTint.js +198 -0
- package/dist/render/pointLightSelection.d.ts +7 -0
- package/dist/render/pointLightSelection.js +29 -4
- package/dist/render/pointShadowArray.d.ts +56 -3
- package/dist/render/pointShadowArray.js +127 -16
- package/dist/render/pointShadowMap.d.ts +23 -1
- package/dist/render/pointShadowMap.js +27 -1
- package/dist/render/rainField.d.ts +13 -0
- package/dist/render/rainField.js +27 -5
- package/dist/render/recon/changeFrames.d.ts +15 -0
- package/dist/render/recon/changeFrames.js +21 -0
- package/dist/render/recon/lateDepth.d.ts +11 -0
- package/dist/render/recon/lateDepth.js +70 -0
- package/dist/render/recon/lateRouting.d.ts +14 -0
- package/dist/render/recon/lateRouting.js +18 -0
- package/dist/render/recon/mover.d.ts +57 -0
- package/dist/render/recon/mover.js +86 -0
- package/dist/render/recon/resolve.d.ts +34 -4
- package/dist/render/recon/resolve.js +161 -20
- package/dist/render/renderQuality.d.ts +35 -0
- package/dist/render/renderQuality.js +7 -0
- package/dist/render/rendererHarness.js +16 -0
- package/dist/render/sceneTarget.d.ts +9 -1
- package/dist/render/sceneTarget.js +60 -12
- package/dist/render/shaders/depth.d.ts +16 -1
- package/dist/render/shaders/depth.js +94 -15
- package/dist/render/shaders/flat/directionalShadow.js +91 -6
- package/dist/render/shaders/flat/driftLight.d.ts +1 -1
- package/dist/render/shaders/flat/driftLight.js +32 -7
- package/dist/render/shaders/flat/glassTint.d.ts +6 -0
- package/dist/render/shaders/flat/glassTint.js +25 -0
- package/dist/render/shaders/flat/index.d.ts +13 -0
- package/dist/render/shaders/flat/index.js +9 -3
- package/dist/render/shaders/flat/lampGlass.d.ts +1 -0
- package/dist/render/shaders/flat/lampGlass.js +183 -0
- package/dist/render/shaders/flat/main.d.ts +1 -1
- package/dist/render/shaders/flat/main.js +190 -38
- package/dist/render/shaders/flat/pointShadow.d.ts +1 -1
- package/dist/render/shaders/flat/pointShadow.js +2 -0
- package/dist/render/shaders/flat/preamble.js +96 -26
- package/dist/render/shaders/flat/surfaceEffects.d.ts +29 -0
- package/dist/render/shaders/flat/surfaceEffects.js +152 -0
- package/dist/render/shaders/generated/depth.wgsl.d.ts +230 -7
- package/dist/render/shaders/generated/depth.wgsl.js +230 -7
- package/dist/render/shaders/generated/flat.wgsl.d.ts +1644 -1596
- package/dist/render/shaders/generated/flat.wgsl.js +1683 -1621
- package/dist/render/shaders/generated/globalMedium.wgsl.d.ts +3 -13
- package/dist/render/shaders/generated/globalMedium.wgsl.js +3 -13
- package/dist/render/shaders/generated/lightVolume.wgsl.d.ts +3 -13
- package/dist/render/shaders/generated/lightVolume.wgsl.js +21 -17
- package/dist/render/shaders/generated/octahedralResolve.wgsl.d.ts +29 -0
- package/dist/render/shaders/generated/octahedralResolve.wgsl.js +29 -0
- package/dist/render/shaders/generated/rush.wgsl.d.ts +21 -16
- package/dist/render/shaders/generated/rush.wgsl.js +21 -16
- package/dist/render/shaders/generated/sdfText.wgsl.d.ts +2 -2
- package/dist/render/shaders/generated/sdfText.wgsl.js +2 -2
- package/dist/render/shaders/generated/text.wgsl.d.ts +1 -1
- package/dist/render/shaders/generated/text.wgsl.js +1 -1
- package/dist/render/shaders/gi/driftLight.wgsl.d.ts +1 -1
- package/dist/render/shaders/gi/driftLight.wgsl.js +27 -4
- package/dist/render/shaders/globalMedium.js +6 -6
- package/dist/render/shaders/gpudriven/blendRaster.wgsl.d.ts +7 -0
- package/dist/render/shaders/gpudriven/blendRaster.wgsl.js +86 -1
- package/dist/render/shaders/gpudriven/cull.wgsl.d.ts +1 -1
- package/dist/render/shaders/gpudriven/cull.wgsl.js +11 -2
- package/dist/render/shaders/gpudriven/materialTable.wgsl.d.ts +1 -1
- package/dist/render/shaders/gpudriven/materialTable.wgsl.js +3 -1
- package/dist/render/shaders/gpudriven/shade.wgsl.js +50 -1
- package/dist/render/shaders/gpudriven/sunGlass.wgsl.d.ts +9 -0
- package/dist/render/shaders/gpudriven/sunGlass.wgsl.js +133 -0
- package/dist/render/shaders/lightVolume.js +6 -6
- package/dist/render/shaders/octahedralResolve.d.ts +8 -0
- package/dist/render/shaders/octahedralResolve.js +48 -17
- package/dist/render/shaders/recon/lateDepth.wgsl.d.ts +1 -0
- package/dist/render/shaders/recon/lateDepth.wgsl.js +69 -0
- package/dist/render/shaders/recon/motion.wgsl.d.ts +1 -1
- package/dist/render/shaders/recon/motion.wgsl.js +84 -0
- package/dist/render/shaders/recon/resolve.wgsl.d.ts +8 -7
- package/dist/render/shaders/recon/resolve.wgsl.js +161 -27
- package/dist/render/shaders/rush.js +11 -1
- package/dist/render/shaders/sdfText.d.ts +1 -1
- package/dist/render/shaders/sdfText.js +3 -2
- package/dist/render/shaders/text.d.ts +1 -1
- package/dist/render/shaders/text.js +18 -9
- package/dist/render/shadowCasters.d.ts +20 -1
- package/dist/render/shadowCasters.js +15 -1
- package/dist/render/shadowMap.d.ts +54 -5
- package/dist/render/shadowMap.js +190 -36
- package/dist/render/sunGlassTint.d.ts +25 -0
- package/dist/render/sunGlassTint.js +79 -0
- package/dist/render/surfaceEffects.d.ts +83 -0
- package/dist/render/surfaceEffects.js +75 -0
- package/dist/render/surfaceScene.d.ts +8 -0
- package/dist/render/surfaceScene.js +8 -0
- package/dist/render/surfaceTexture.d.ts +18 -2
- package/dist/render/surfaceTexture.js +68 -15
- package/dist/render/temporalAa.d.ts +25 -6
- package/dist/render/temporalAa.js +45 -15
- package/dist/render/textureSource.d.ts +30 -0
- package/dist/render/textureSource.js +53 -0
- package/dist/render/translucentQueue.d.ts +6 -0
- package/dist/render/translucentQueue.js +15 -1
- package/dist/render/vertexDefaults.js +2 -0
- package/dist/world/hlod.d.ts +104 -0
- package/dist/world/hlod.js +214 -0
- package/package.json +6 -6
- package/src/geometry/boxCsg.ts +186 -0
- package/src/geometry/csg.ts +384 -0
- package/src/geometry/meshBuilder.ts +15 -0
- package/src/geometry/meshConcat.ts +1 -0
- package/src/geometry/pixelFont.ts +2 -0
- package/src/geometry/solid.ts +189 -0
- package/src/geometry/solidFlat.ts +522 -0
- package/src/geometry/solidHarness.ts +83 -0
- package/src/geometry/solidNormals.ts +103 -0
- package/src/geometry/solidRound.ts +443 -0
- package/src/geometry/solidWriter.ts +58 -0
- package/src/index.ts +61 -1
- package/src/render/backend/api.ts +36 -11
- package/src/render/backend/drawFog.ts +31 -0
- package/src/render/backend/materialChanges.ts +9 -2
- package/src/render/backend/webgl2/glassTintPrograms.ts +58 -0
- package/src/render/backend/webgl2/instanced.ts +80 -14
- package/src/render/backend/webgl2/renderer.ts +700 -250
- package/src/render/backend/webgpu/buffers.ts +92 -5
- package/src/render/backend/webgpu/depthPass.ts +7 -2
- package/src/render/backend/webgpu/drawCommand.ts +6 -0
- package/src/render/backend/webgpu/flatPass.ts +62 -11
- package/src/render/backend/webgpu/glassTintPass.ts +245 -0
- package/src/render/backend/webgpu/gpuDrivenPass.ts +349 -5
- package/src/render/backend/webgpu/instanceCullPass.ts +165 -0
- package/src/render/backend/webgpu/instanced.ts +42 -4
- package/src/render/backend/webgpu/latePass.ts +161 -0
- package/src/render/backend/webgpu/lightVolumePass.ts +5 -1
- package/src/render/backend/webgpu/motionPass.ts +535 -0
- package/src/render/backend/webgpu/pipelineCache.ts +12 -1
- package/src/render/backend/webgpu/pointGlassTintPass.ts +233 -0
- package/src/render/backend/webgpu/pointShadowPass.ts +158 -26
- package/src/render/backend/webgpu/renderer.ts +1671 -670
- package/src/render/backend/webgpu/scatterPass.ts +2 -1
- package/src/render/backend/webgpu/sdfTextPass.ts +6 -1
- package/src/render/backend/webgpu/shaders/instanceCull.wgsl.ts +61 -0
- package/src/render/backend/webgpu/skinPaletteRing.ts +4 -0
- package/src/render/backend/webgpu/snapshotMips.ts +80 -0
- package/src/render/backend/webgpu/surfaceTexturePass.ts +91 -51
- package/src/render/driftLight/bake.ts +85 -62
- package/src/render/driftLight/denseField.ts +149 -0
- package/src/render/driftLight/lightField.ts +33 -18
- package/src/render/driftLight/presence.ts +69 -0
- package/src/render/driftLight/uniforms.ts +8 -9
- package/src/render/driftLight/worldLightField.ts +83 -0
- package/src/render/fixtureAtlas.ts +63 -0
- package/src/render/glass.ts +74 -0
- package/src/render/glassCasters.ts +164 -0
- package/src/render/glassShadow.ts +153 -0
- package/src/render/globalMediumPass.ts +4 -11
- package/src/render/gpudriven/lit.ts +31 -0
- package/src/render/gpudriven/materialTable.ts +28 -6
- package/src/render/gpudriven/pipeline.ts +4 -3
- package/src/render/gpudriven/sunGlass.ts +117 -0
- package/src/render/instanceCull.ts +205 -0
- package/src/render/instances.ts +16 -0
- package/src/render/lightBudget.ts +41 -38
- package/src/render/lightGrid.ts +130 -0
- package/src/render/mesh.ts +59 -72
- package/src/render/occlusion.ts +51 -7
- package/src/render/pointGlassTint.ts +250 -0
- package/src/render/pointLightSelection.ts +72 -4
- package/src/render/pointShadowArray.ts +188 -22
- package/src/render/pointShadowMap.ts +41 -0
- package/src/render/rainField.ts +39 -5
- package/src/render/recon/changeFrames.ts +24 -0
- package/src/render/recon/lateDepth.ts +83 -0
- package/src/render/recon/lateRouting.ts +29 -0
- package/src/render/recon/mover.ts +118 -0
- package/src/render/recon/resolve.ts +206 -20
- package/src/render/renderQuality.ts +47 -0
- package/src/render/rendererHarness.ts +16 -0
- package/src/render/sceneTarget.ts +62 -11
- package/src/render/shaders/depth.ts +118 -15
- package/src/render/shaders/flat/directionalShadow.ts +97 -6
- package/src/render/shaders/flat/driftLight.ts +32 -7
- package/src/render/shaders/flat/glassTint.ts +25 -0
- package/src/render/shaders/flat/index.ts +22 -3
- package/src/render/shaders/flat/lampGlass.ts +185 -0
- package/src/render/shaders/flat/main.ts +190 -38
- package/src/render/shaders/flat/pointShadow.ts +2 -0
- package/src/render/shaders/flat/preamble.ts +96 -26
- package/src/render/shaders/flat/surfaceEffects.ts +152 -0
- package/src/render/shaders/generated/depth.wgsl.ts +237 -7
- package/src/render/shaders/generated/flat.wgsl.ts +1685 -1621
- package/src/render/shaders/generated/globalMedium.wgsl.ts +3 -13
- package/src/render/shaders/generated/lightVolume.wgsl.ts +23 -17
- package/src/render/shaders/generated/octahedralResolve.wgsl.ts +30 -0
- package/src/render/shaders/generated/rush.wgsl.ts +21 -16
- package/src/render/shaders/generated/sdfText.wgsl.ts +2 -2
- package/src/render/shaders/generated/text.wgsl.ts +1 -1
- package/src/render/shaders/gi/driftLight.wgsl.ts +27 -4
- package/src/render/shaders/globalMedium.ts +6 -6
- package/src/render/shaders/gpudriven/blendRaster.wgsl.ts +88 -1
- package/src/render/shaders/gpudriven/cull.wgsl.ts +11 -2
- package/src/render/shaders/gpudriven/materialTable.wgsl.ts +3 -1
- package/src/render/shaders/gpudriven/shade.wgsl.ts +50 -1
- package/src/render/shaders/gpudriven/sunGlass.wgsl.ts +139 -0
- package/src/render/shaders/lightVolume.ts +6 -6
- package/src/render/shaders/octahedralResolve.ts +50 -17
- package/src/render/shaders/recon/lateDepth.wgsl.ts +72 -0
- package/src/render/shaders/recon/motion.wgsl.ts +84 -0
- package/src/render/shaders/recon/resolve.wgsl.ts +161 -27
- package/src/render/shaders/rush.ts +11 -1
- package/src/render/shaders/sdfText.ts +3 -2
- package/src/render/shaders/text.ts +18 -9
- package/src/render/shadowCasters.ts +28 -1
- package/src/render/shadowMap.ts +231 -37
- package/src/render/sunGlassTint.ts +86 -0
- package/src/render/surfaceEffects.ts +132 -0
- package/src/render/surfaceScene.ts +16 -0
- package/src/render/surfaceTexture.ts +110 -19
- package/src/render/temporalAa.ts +78 -14
- package/src/render/textureSource.ts +72 -0
- package/src/render/translucentQueue.ts +20 -1
- package/src/render/vertexDefaults.ts +2 -0
- package/src/world/hlod.ts +290 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where every mover was last frame, drawn into the reconstruction's motion target.
|
|
3
|
+
*
|
|
4
|
+
* Moved out of `renderer.ts` when it grew variants: the renderer decides *which* draws moved and
|
|
5
|
+
* hands them here; this owns how their motion is drawn. See `shaders/recon/motion.wgsl.ts` for what
|
|
6
|
+
* a texel carries, why it is a pass of its own, and why its matrices are unjittered.
|
|
7
|
+
*/
|
|
8
|
+
import { DEPTH_COMPARE_EQUAL, DEPTH_FORMAT } from '../../depthConvention.ts';
|
|
9
|
+
import {
|
|
10
|
+
MOTION_DRAW_FLOATS,
|
|
11
|
+
MOTION_DRAW_STRIDE,
|
|
12
|
+
MOTION_FRAME_FLOATS,
|
|
13
|
+
MOTION_TARGET_FORMAT,
|
|
14
|
+
RECON_MOTION_WGSL,
|
|
15
|
+
} from '../../shaders/recon/motion.wgsl.ts';
|
|
16
|
+
import { INSTANCE_STRIDE } from '../../instances.ts';
|
|
17
|
+
import type { GpuMesh } from './buffers.ts';
|
|
18
|
+
|
|
19
|
+
/** What a record is, which decides the vertex stage and what else it binds. */
|
|
20
|
+
const RIGID = 0;
|
|
21
|
+
const SKINNED = 1;
|
|
22
|
+
const DYNAMIC = 2;
|
|
23
|
+
const INSTANCED = 3;
|
|
24
|
+
|
|
25
|
+
/** An instanced record's per-draw matrices are not read; this fills their slot. */
|
|
26
|
+
const IDENTITY = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
27
|
+
|
|
28
|
+
export class MotionPass {
|
|
29
|
+
private readonly device: GPUDevice;
|
|
30
|
+
/** The frame's movers, in the order they were drawn. */
|
|
31
|
+
private readonly meshes: GpuMesh[] = [];
|
|
32
|
+
/** Two matrices a mover — this frame's model and last frame's — at `MOTION_DRAW_FLOATS` apart. */
|
|
33
|
+
private matrices = new Float32Array(0);
|
|
34
|
+
private count = 0;
|
|
35
|
+
/** `RIGID` or `SKINNED` per record, grown beside `matrices`. */
|
|
36
|
+
private kinds = new Uint8Array(0);
|
|
37
|
+
/** A skinned record's two palettes, this frame's and last frame's, by record index. */
|
|
38
|
+
private readonly paletteNow: (GPUTextureView | null)[] = [];
|
|
39
|
+
private readonly paletteWas: (GPUTextureView | null)[] = [];
|
|
40
|
+
/** A rewritten record's last-frame rows, by record index. */
|
|
41
|
+
private readonly previousRows: (GPUBuffer | null)[] = [];
|
|
42
|
+
/** One pipeline per stride for rewritten meshes: current and previous rows at that stride. */
|
|
43
|
+
private readonly dynamicPipelines = new Map<number, GPURenderPipeline>();
|
|
44
|
+
/** An instanced record's placement this frame and last frame, and how many slots pair. */
|
|
45
|
+
private readonly instancesNow: (GPUBuffer | null)[] = [];
|
|
46
|
+
private readonly instancesWas: (GPUBuffer | null)[] = [];
|
|
47
|
+
private instanceCounts = new Uint32Array(0);
|
|
48
|
+
private readonly instancedPipelines = new Map<number, GPURenderPipeline>();
|
|
49
|
+
private layout: GPUBindGroupLayout | null = null;
|
|
50
|
+
private paletteLayout: GPUBindGroupLayout | null = null;
|
|
51
|
+
private skinnedLayout: GPUPipelineLayout | null = null;
|
|
52
|
+
/** Keyed by stride and the two skin offsets, packed into one number so a lookup builds nothing. */
|
|
53
|
+
private readonly skinnedPipelines = new Map<number, GPURenderPipeline>();
|
|
54
|
+
/**
|
|
55
|
+
* A bind group per pair of palette views. The ring keeps its textures from frame to frame, so a
|
|
56
|
+
* steady scene settles on a handful of pairs and builds nothing per frame.
|
|
57
|
+
*/
|
|
58
|
+
private readonly paletteGroups = new Map<GPUTextureView, Map<GPUTextureView, GPUBindGroup>>();
|
|
59
|
+
private module: GPUShaderModule | null = null;
|
|
60
|
+
private pipelineLayout: GPUPipelineLayout | null = null;
|
|
61
|
+
private readonly pipelines = new Map<number, GPURenderPipeline>();
|
|
62
|
+
private frameBuffer: GPUBuffer | null = null;
|
|
63
|
+
private drawBuffer: GPUBuffer | null = null;
|
|
64
|
+
private drawCapacity = 0;
|
|
65
|
+
private group: GPUBindGroup | null = null;
|
|
66
|
+
private readonly frameStaging = new Float32Array(MOTION_FRAME_FLOATS);
|
|
67
|
+
private drawStaging = new Uint8Array(0);
|
|
68
|
+
/** A float view of `drawStaging`, made when it is, so a frame's upload allocates nothing. */
|
|
69
|
+
private drawFloats = new Float32Array(0);
|
|
70
|
+
|
|
71
|
+
constructor(device: GPUDevice) {
|
|
72
|
+
this.device = device;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** A frame states its movers afresh. */
|
|
76
|
+
reset(): void {
|
|
77
|
+
this.count = 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A rigid mover: the same positions under last frame's model. */
|
|
81
|
+
recordRigid(mesh: GpuMesh, model: ArrayLike<number>, previousModel: ArrayLike<number>): void {
|
|
82
|
+
this.take(mesh, model, previousModel, RIGID);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A skinned mover: its positions under last frame's pose as well as last frame's model. */
|
|
86
|
+
recordSkinned(
|
|
87
|
+
mesh: GpuMesh,
|
|
88
|
+
model: ArrayLike<number>,
|
|
89
|
+
previousModel: ArrayLike<number>,
|
|
90
|
+
palette: GPUTextureView,
|
|
91
|
+
previousPalette: GPUTextureView,
|
|
92
|
+
): void {
|
|
93
|
+
const at = this.take(mesh, model, previousModel, SKINNED);
|
|
94
|
+
this.paletteNow[at] = palette;
|
|
95
|
+
this.paletteWas[at] = previousPalette;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A rewritten mesh: its vertices as they were, read from `previous`, under last frame's model. */
|
|
99
|
+
recordDynamic(
|
|
100
|
+
mesh: GpuMesh,
|
|
101
|
+
model: ArrayLike<number>,
|
|
102
|
+
previousModel: ArrayLike<number>,
|
|
103
|
+
previous: GPUBuffer,
|
|
104
|
+
): void {
|
|
105
|
+
const at = this.take(mesh, model, previousModel, DYNAMIC);
|
|
106
|
+
this.previousRows[at] = previous;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** An instanced batch: its first `count` slots, each under last frame's placement of that slot. */
|
|
110
|
+
recordInstanced(
|
|
111
|
+
mesh: GpuMesh,
|
|
112
|
+
placement: GPUBuffer,
|
|
113
|
+
previousPlacement: GPUBuffer,
|
|
114
|
+
count: number,
|
|
115
|
+
): void {
|
|
116
|
+
const at = this.take(mesh, IDENTITY, IDENTITY, INSTANCED);
|
|
117
|
+
this.instancesNow[at] = placement;
|
|
118
|
+
this.instancesWas[at] = previousPlacement;
|
|
119
|
+
this.instanceCounts[at] = count;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** One record's slot: its mesh, its two matrices and its kind. Returns the record's index. */
|
|
123
|
+
private take(
|
|
124
|
+
mesh: GpuMesh,
|
|
125
|
+
model: ArrayLike<number>,
|
|
126
|
+
previousModel: ArrayLike<number>,
|
|
127
|
+
kind: number,
|
|
128
|
+
): number {
|
|
129
|
+
const at = this.count;
|
|
130
|
+
const wanted = (at + 1) * MOTION_DRAW_FLOATS;
|
|
131
|
+
if (this.matrices.length < wanted) {
|
|
132
|
+
/* Doubling, so a scene settles on one allocation rather than one a draw. */
|
|
133
|
+
const grown = new Float32Array(Math.max(wanted, this.matrices.length * 2, 64));
|
|
134
|
+
grown.set(this.matrices);
|
|
135
|
+
this.matrices = grown;
|
|
136
|
+
const kinds = new Uint8Array(grown.length / MOTION_DRAW_FLOATS);
|
|
137
|
+
kinds.set(this.kinds);
|
|
138
|
+
this.kinds = kinds;
|
|
139
|
+
const counts = new Uint32Array(kinds.length);
|
|
140
|
+
counts.set(this.instanceCounts);
|
|
141
|
+
this.instanceCounts = counts;
|
|
142
|
+
}
|
|
143
|
+
this.matrices.set(model as ArrayLike<number> & Iterable<number>, at * MOTION_DRAW_FLOATS);
|
|
144
|
+
this.matrices.set(
|
|
145
|
+
previousModel as ArrayLike<number> & Iterable<number>,
|
|
146
|
+
at * MOTION_DRAW_FLOATS + 16,
|
|
147
|
+
);
|
|
148
|
+
this.meshes[at] = mesh;
|
|
149
|
+
this.kinds[at] = kind;
|
|
150
|
+
this.count = at + 1;
|
|
151
|
+
return at;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The pipeline layout and module, built once.
|
|
156
|
+
*
|
|
157
|
+
* **The position alone**, at offset zero of the mesh's interleaved rows: that is all the rigid
|
|
158
|
+
* stage reads, and positions are the layout's first attribute and never optional.
|
|
159
|
+
*/
|
|
160
|
+
private buildLayout(): void {
|
|
161
|
+
if (this.layout !== null) return;
|
|
162
|
+
this.layout = this.device.createBindGroupLayout({
|
|
163
|
+
label: 'recon.motion.layout',
|
|
164
|
+
entries: [
|
|
165
|
+
{ binding: 0, visibility: 0x1, buffer: { type: 'uniform' as const } },
|
|
166
|
+
{
|
|
167
|
+
binding: 1,
|
|
168
|
+
visibility: 0x1,
|
|
169
|
+
buffer: { type: 'uniform' as const, hasDynamicOffset: true },
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
this.module = this.device.createShaderModule({
|
|
174
|
+
label: 'recon.motion',
|
|
175
|
+
code: RECON_MOTION_WGSL,
|
|
176
|
+
});
|
|
177
|
+
this.pipelineLayout = this.device.createPipelineLayout({
|
|
178
|
+
bindGroupLayouts: [this.layout],
|
|
179
|
+
});
|
|
180
|
+
/* The two palettes, read with `textureLoad` at integer texels: unfilterable is exact. */
|
|
181
|
+
this.paletteLayout = this.device.createBindGroupLayout({
|
|
182
|
+
label: 'recon.motion.palettes',
|
|
183
|
+
entries: [
|
|
184
|
+
{ binding: 0, visibility: 0x1, texture: { sampleType: 'unfilterable-float' as const } },
|
|
185
|
+
{ binding: 1, visibility: 0x1, texture: { sampleType: 'unfilterable-float' as const } },
|
|
186
|
+
],
|
|
187
|
+
});
|
|
188
|
+
this.skinnedLayout = this.device.createPipelineLayout({
|
|
189
|
+
bindGroupLayouts: [this.layout, this.paletteLayout],
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The skinned pipeline for one stride and one placement of the joints and weights in it.
|
|
195
|
+
*
|
|
196
|
+
* Same fragment stage, winding and depth test as the rigid one — see `pipelineFor` — with the two
|
|
197
|
+
* skinning attributes read from the interleaved rows at the offsets the mesh records.
|
|
198
|
+
*/
|
|
199
|
+
private skinnedPipelineFor(
|
|
200
|
+
stride: number,
|
|
201
|
+
offsets: { readonly joints: number; readonly weights: number },
|
|
202
|
+
): GPURenderPipeline | null {
|
|
203
|
+
const key = (stride * 4096 + offsets.joints) * 4096 + offsets.weights;
|
|
204
|
+
const held = this.skinnedPipelines.get(key);
|
|
205
|
+
if (held !== undefined) return held;
|
|
206
|
+
const module = this.module;
|
|
207
|
+
const layout = this.skinnedLayout;
|
|
208
|
+
if (module === null || layout === null) return null;
|
|
209
|
+
const pipeline = this.device.createRenderPipeline({
|
|
210
|
+
label: `recon.motion.skinned.${String(stride)}`,
|
|
211
|
+
layout,
|
|
212
|
+
vertex: {
|
|
213
|
+
module,
|
|
214
|
+
entryPoint: 'motionSkinnedVert',
|
|
215
|
+
buffers: [
|
|
216
|
+
{
|
|
217
|
+
arrayStride: stride,
|
|
218
|
+
attributes: [
|
|
219
|
+
{ shaderLocation: 0, offset: 0, format: 'float32x3' },
|
|
220
|
+
{ shaderLocation: 11, offset: offsets.joints, format: 'float32x4' },
|
|
221
|
+
{ shaderLocation: 12, offset: offsets.weights, format: 'float32x4' },
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
fragment: { module, entryPoint: 'motionFrag', targets: [{ format: MOTION_TARGET_FORMAT }] },
|
|
227
|
+
primitive: { topology: 'triangle-list', cullMode: 'back' },
|
|
228
|
+
depthStencil: {
|
|
229
|
+
format: DEPTH_FORMAT,
|
|
230
|
+
depthWriteEnabled: false,
|
|
231
|
+
depthCompare: DEPTH_COMPARE_EQUAL,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
this.skinnedPipelines.set(key, pipeline);
|
|
235
|
+
return pipeline;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The rewritten pipeline for one stride: position from each of two buffers of that stride. */
|
|
239
|
+
private dynamicPipelineFor(stride: number): GPURenderPipeline | null {
|
|
240
|
+
const held = this.dynamicPipelines.get(stride);
|
|
241
|
+
if (held !== undefined) return held;
|
|
242
|
+
const module = this.module;
|
|
243
|
+
const layout = this.pipelineLayout;
|
|
244
|
+
if (module === null || layout === null) return null;
|
|
245
|
+
const pipeline = this.device.createRenderPipeline({
|
|
246
|
+
label: `recon.motion.dynamic.${String(stride)}`,
|
|
247
|
+
layout,
|
|
248
|
+
vertex: {
|
|
249
|
+
module,
|
|
250
|
+
entryPoint: 'motionDynamicVert',
|
|
251
|
+
buffers: [
|
|
252
|
+
{
|
|
253
|
+
arrayStride: stride,
|
|
254
|
+
attributes: [{ shaderLocation: 0, offset: 0, format: 'float32x3' }],
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
arrayStride: stride,
|
|
258
|
+
attributes: [{ shaderLocation: 1, offset: 0, format: 'float32x3' }],
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
fragment: { module, entryPoint: 'motionFrag', targets: [{ format: MOTION_TARGET_FORMAT }] },
|
|
263
|
+
primitive: { topology: 'triangle-list', cullMode: 'back' },
|
|
264
|
+
depthStencil: {
|
|
265
|
+
format: DEPTH_FORMAT,
|
|
266
|
+
depthWriteEnabled: false,
|
|
267
|
+
depthCompare: DEPTH_COMPARE_EQUAL,
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
this.dynamicPipelines.set(stride, pipeline);
|
|
271
|
+
return pipeline;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The instanced pipeline for one mesh stride: the mesh's positions, then this frame's and last
|
|
276
|
+
* frame's placements, one matrix an instance, as the scene's instanced stage reads them.
|
|
277
|
+
*/
|
|
278
|
+
private instancedPipelineFor(stride: number): GPURenderPipeline | null {
|
|
279
|
+
const held = this.instancedPipelines.get(stride);
|
|
280
|
+
if (held !== undefined) return held;
|
|
281
|
+
const module = this.module;
|
|
282
|
+
const layout = this.pipelineLayout;
|
|
283
|
+
if (module === null || layout === null) return null;
|
|
284
|
+
const placement = (first: number): GPUVertexBufferLayout => ({
|
|
285
|
+
arrayStride: INSTANCE_STRIDE,
|
|
286
|
+
stepMode: 'instance',
|
|
287
|
+
attributes: [
|
|
288
|
+
{ shaderLocation: first, offset: 0, format: 'float32x4' },
|
|
289
|
+
{ shaderLocation: first + 1, offset: 16, format: 'float32x4' },
|
|
290
|
+
{ shaderLocation: first + 2, offset: 32, format: 'float32x4' },
|
|
291
|
+
{ shaderLocation: first + 3, offset: 48, format: 'float32x4' },
|
|
292
|
+
],
|
|
293
|
+
});
|
|
294
|
+
const pipeline = this.device.createRenderPipeline({
|
|
295
|
+
label: `recon.motion.instanced.${String(stride)}`,
|
|
296
|
+
layout,
|
|
297
|
+
vertex: {
|
|
298
|
+
module,
|
|
299
|
+
entryPoint: 'motionInstancedVert',
|
|
300
|
+
buffers: [
|
|
301
|
+
{
|
|
302
|
+
arrayStride: stride,
|
|
303
|
+
attributes: [{ shaderLocation: 0, offset: 0, format: 'float32x3' }],
|
|
304
|
+
},
|
|
305
|
+
placement(2),
|
|
306
|
+
placement(6),
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
fragment: { module, entryPoint: 'motionFrag', targets: [{ format: MOTION_TARGET_FORMAT }] },
|
|
310
|
+
primitive: { topology: 'triangle-list', cullMode: 'back' },
|
|
311
|
+
depthStencil: {
|
|
312
|
+
format: DEPTH_FORMAT,
|
|
313
|
+
depthWriteEnabled: false,
|
|
314
|
+
depthCompare: DEPTH_COMPARE_EQUAL,
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
this.instancedPipelines.set(stride, pipeline);
|
|
318
|
+
return pipeline;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The bind group holding one pair of palettes, built the first time the pair is seen. */
|
|
322
|
+
private paletteGroup(now: GPUTextureView, was: GPUTextureView): GPUBindGroup | null {
|
|
323
|
+
const layout = this.paletteLayout;
|
|
324
|
+
if (layout === null) return null;
|
|
325
|
+
let byWas = this.paletteGroups.get(now);
|
|
326
|
+
if (byWas === undefined) {
|
|
327
|
+
byWas = new Map();
|
|
328
|
+
this.paletteGroups.set(now, byWas);
|
|
329
|
+
}
|
|
330
|
+
let group = byWas.get(was);
|
|
331
|
+
if (group === undefined) {
|
|
332
|
+
group = this.device.createBindGroup({
|
|
333
|
+
label: 'recon.motion.palettes',
|
|
334
|
+
layout,
|
|
335
|
+
entries: [
|
|
336
|
+
{ binding: 0, resource: now },
|
|
337
|
+
{ binding: 1, resource: was },
|
|
338
|
+
],
|
|
339
|
+
});
|
|
340
|
+
byWas.set(was, group);
|
|
341
|
+
}
|
|
342
|
+
return group;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** The pipeline for one vertex stride, built on first sight of it. */
|
|
346
|
+
private pipelineFor(stride: number): GPURenderPipeline | null {
|
|
347
|
+
const held = this.pipelines.get(stride);
|
|
348
|
+
if (held !== undefined) return held;
|
|
349
|
+
const module = this.module;
|
|
350
|
+
const layout = this.pipelineLayout;
|
|
351
|
+
if (module === null || layout === null) return null;
|
|
352
|
+
const pipeline = this.device.createRenderPipeline({
|
|
353
|
+
label: `recon.motion.${String(stride)}`,
|
|
354
|
+
layout,
|
|
355
|
+
vertex: {
|
|
356
|
+
module,
|
|
357
|
+
entryPoint: 'motionVert',
|
|
358
|
+
buffers: [
|
|
359
|
+
{
|
|
360
|
+
arrayStride: stride,
|
|
361
|
+
attributes: [{ shaderLocation: 0, offset: 0, format: 'float32x3' }],
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
},
|
|
365
|
+
fragment: { module, entryPoint: 'motionFrag', targets: [{ format: MOTION_TARGET_FORMAT }] },
|
|
366
|
+
/*
|
|
367
|
+
* **The scene's own winding**, because this draws the scene's geometry through the scene's
|
|
368
|
+
* clip transform — the product the renderer hands over already carries the negation that
|
|
369
|
+
* `naga` writes into every generated vertex stage, so the faces come out the way they did
|
|
370
|
+
* and a `cw` front face here would draw the inside of every mesh. §3 row 57.
|
|
371
|
+
*/
|
|
372
|
+
primitive: { topology: 'triangle-list', cullMode: 'back' },
|
|
373
|
+
depthStencil: {
|
|
374
|
+
format: DEPTH_FORMAT,
|
|
375
|
+
/*
|
|
376
|
+
* **Tested and not written.** The frame's depth is finished; this pass only wants the
|
|
377
|
+
* pixels the scene actually kept, and `DEPTH_COMPARE_EQUAL` is the comparison that admits
|
|
378
|
+
* exactly them — the same transform on the same positions gives the same depth, which is
|
|
379
|
+
* why the rasterisation matrix is handed over whole rather than rebuilt here.
|
|
380
|
+
*
|
|
381
|
+
* **And the equality is not fragile here**, which was worth measuring rather than
|
|
382
|
+
* assuming: this driver contracts multiply-adds (§3 row 107) and two shader modules can
|
|
383
|
+
* contract a matrix product differently, so an equality across them could have admitted
|
|
384
|
+
* only some of a surface. Run with `greater-equal` instead, the ghost measured the same
|
|
385
|
+
* to the pixel — 5,942 either way — so nothing is being dropped.
|
|
386
|
+
*/
|
|
387
|
+
depthWriteEnabled: false,
|
|
388
|
+
depthCompare: DEPTH_COMPARE_EQUAL,
|
|
389
|
+
},
|
|
390
|
+
});
|
|
391
|
+
this.pipelines.set(stride, pipeline);
|
|
392
|
+
return pipeline;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Every mover of the frame, into `target`, tested against the finished `depth`.
|
|
397
|
+
*
|
|
398
|
+
* **After everything that draws and before the resolve reads it.** `raster` is the scene's clip
|
|
399
|
+
* transform with the generated stages' y negation folded in; `viewProj` and `previousViewProj`
|
|
400
|
+
* are this frame's and last frame's unjittered view-projections.
|
|
401
|
+
*
|
|
402
|
+
* **Cleared every frame, even when nothing moved.** A texel left from last frame is a flag saying
|
|
403
|
+
* "a draw wrote this", and the resolve would take a motion belonging to a surface that is no
|
|
404
|
+
* longer there. The clear is the pass's own load operation, so an empty frame still runs it.
|
|
405
|
+
*/
|
|
406
|
+
run(
|
|
407
|
+
encoder: GPUCommandEncoder,
|
|
408
|
+
target: GPUTextureView,
|
|
409
|
+
depth: GPUTextureView,
|
|
410
|
+
raster: Float32Array,
|
|
411
|
+
viewProj: Float32Array,
|
|
412
|
+
previousViewProj: Float32Array,
|
|
413
|
+
timestampWrites: GPURenderPassTimestampWrites | undefined,
|
|
414
|
+
): void {
|
|
415
|
+
this.buildLayout();
|
|
416
|
+
const layout = this.layout;
|
|
417
|
+
if (layout === null) return;
|
|
418
|
+
const pass = encoder.beginRenderPass({
|
|
419
|
+
label: 'recon.motion',
|
|
420
|
+
timestampWrites,
|
|
421
|
+
colorAttachments: [
|
|
422
|
+
{ view: target, loadOp: 'clear', storeOp: 'store', clearValue: [0, 0, 0, 0] },
|
|
423
|
+
],
|
|
424
|
+
depthStencilAttachment: {
|
|
425
|
+
view: depth,
|
|
426
|
+
depthLoadOp: 'load',
|
|
427
|
+
depthStoreOp: 'store',
|
|
428
|
+
depthReadOnly: false,
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
const count = this.count;
|
|
433
|
+
if (count > 0) {
|
|
434
|
+
const bytes = count * MOTION_DRAW_STRIDE;
|
|
435
|
+
if (this.drawCapacity < count) {
|
|
436
|
+
this.drawBuffer?.destroy();
|
|
437
|
+
this.drawCapacity = Math.max(count, this.drawCapacity * 2, 16);
|
|
438
|
+
this.drawBuffer = this.device.createBuffer({
|
|
439
|
+
label: 'recon.motion.draws',
|
|
440
|
+
size: this.drawCapacity * MOTION_DRAW_STRIDE,
|
|
441
|
+
usage: 0x40 | 0x8, // UNIFORM | COPY_DST
|
|
442
|
+
});
|
|
443
|
+
this.drawStaging = new Uint8Array(this.drawCapacity * MOTION_DRAW_STRIDE);
|
|
444
|
+
this.drawFloats = new Float32Array(this.drawStaging.buffer);
|
|
445
|
+
this.group = null;
|
|
446
|
+
}
|
|
447
|
+
this.frameBuffer ??= this.device.createBuffer({
|
|
448
|
+
label: 'recon.motion.frame',
|
|
449
|
+
size: MOTION_FRAME_FLOATS * 4,
|
|
450
|
+
usage: 0x40 | 0x8,
|
|
451
|
+
});
|
|
452
|
+
this.group ??= this.device.createBindGroup({
|
|
453
|
+
label: 'recon.motion.group',
|
|
454
|
+
layout,
|
|
455
|
+
entries: [
|
|
456
|
+
{ binding: 0, resource: { buffer: this.frameBuffer } },
|
|
457
|
+
{
|
|
458
|
+
binding: 1,
|
|
459
|
+
resource: { buffer: this.drawBuffer as GPUBuffer, size: MOTION_DRAW_STRIDE },
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
this.frameStaging.set(raster, 0);
|
|
465
|
+
this.frameStaging.set(viewProj, 16);
|
|
466
|
+
this.frameStaging.set(previousViewProj, 32);
|
|
467
|
+
this.device.queue.writeBuffer(this.frameBuffer, 0, this.frameStaging);
|
|
468
|
+
|
|
469
|
+
/* Copied a float at a time rather than through `subarray`, which is a view allocated per
|
|
470
|
+
mover per frame. */
|
|
471
|
+
for (let i = 0; i < count; i += 1) {
|
|
472
|
+
const from = i * MOTION_DRAW_FLOATS;
|
|
473
|
+
const to = (i * MOTION_DRAW_STRIDE) / 4;
|
|
474
|
+
for (let k = 0; k < MOTION_DRAW_FLOATS; k += 1) {
|
|
475
|
+
this.drawFloats[to + k] = this.matrices[from + k] as number;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
this.device.queue.writeBuffer(this.drawBuffer as GPUBuffer, 0, this.drawStaging, 0, bytes);
|
|
479
|
+
|
|
480
|
+
let bound: GPURenderPipeline | null = null;
|
|
481
|
+
for (let i = 0; i < count; i += 1) {
|
|
482
|
+
const mesh = this.meshes[i];
|
|
483
|
+
if (mesh === undefined) continue;
|
|
484
|
+
const kind = this.kinds[i];
|
|
485
|
+
let pipeline: GPURenderPipeline | null = null;
|
|
486
|
+
let instances = 1;
|
|
487
|
+
if (kind === INSTANCED) {
|
|
488
|
+
const now = this.instancesNow[i] ?? null;
|
|
489
|
+
const was = this.instancesWas[i] ?? null;
|
|
490
|
+
if (now === null || was === null) continue;
|
|
491
|
+
pipeline = this.instancedPipelineFor(mesh.vertexStride);
|
|
492
|
+
pass.setVertexBuffer(1, now);
|
|
493
|
+
pass.setVertexBuffer(2, was);
|
|
494
|
+
instances = this.instanceCounts[i] ?? 0;
|
|
495
|
+
} else if (kind === DYNAMIC) {
|
|
496
|
+
const previous = this.previousRows[i] ?? null;
|
|
497
|
+
if (previous === null) continue;
|
|
498
|
+
pipeline = this.dynamicPipelineFor(mesh.vertexStride);
|
|
499
|
+
pass.setVertexBuffer(1, previous);
|
|
500
|
+
} else if (kind === SKINNED) {
|
|
501
|
+
const offsets = mesh.skinOffsets;
|
|
502
|
+
const now = this.paletteNow[i] ?? null;
|
|
503
|
+
const was = this.paletteWas[i] ?? null;
|
|
504
|
+
if (offsets === null || now === null || was === null) continue;
|
|
505
|
+
pipeline = this.skinnedPipelineFor(mesh.vertexStride, offsets);
|
|
506
|
+
const palettes = this.paletteGroup(now, was);
|
|
507
|
+
if (pipeline === null || palettes === null) continue;
|
|
508
|
+
pass.setBindGroup(1, palettes);
|
|
509
|
+
} else {
|
|
510
|
+
pipeline = this.pipelineFor(mesh.vertexStride);
|
|
511
|
+
}
|
|
512
|
+
if (pipeline === null) continue;
|
|
513
|
+
if (pipeline !== bound) {
|
|
514
|
+
pass.setPipeline(pipeline);
|
|
515
|
+
bound = pipeline;
|
|
516
|
+
}
|
|
517
|
+
pass.setBindGroup(0, this.group, [i * MOTION_DRAW_STRIDE]);
|
|
518
|
+
pass.setVertexBuffer(0, mesh.vertexBuffers[0] as GPUBuffer);
|
|
519
|
+
pass.setIndexBuffer(mesh.indexBuffer, 'uint32');
|
|
520
|
+
pass.drawIndexed(mesh.indexCount, instances);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
pass.end();
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
dispose(): void {
|
|
527
|
+
this.paletteGroups.clear();
|
|
528
|
+
this.frameBuffer?.destroy();
|
|
529
|
+
this.drawBuffer?.destroy();
|
|
530
|
+
this.frameBuffer = null;
|
|
531
|
+
this.drawBuffer = null;
|
|
532
|
+
this.drawCapacity = 0;
|
|
533
|
+
this.group = null;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
@@ -34,6 +34,16 @@ export class PipelineCache {
|
|
|
34
34
|
*/
|
|
35
35
|
readonly sampleCount: number;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Whether the lit pipelines here read glass in their shadows: `glassShadows` other than `'off'`.
|
|
39
|
+
*
|
|
40
|
+
* **Carried by the cache for the reason the format is**: one value every lit pipeline is built
|
|
41
|
+
* with, chosen once by the renderer. It is the `GLASS_SHADOWS` override the generated lit shader
|
|
42
|
+
* branches on (see `FlatShaderOptions.glassShadows`), so off specialises the lookups away rather
|
|
43
|
+
* than leaving code that returns at its first line and still costs the pass its registers.
|
|
44
|
+
*/
|
|
45
|
+
readonly glassShadows: boolean;
|
|
46
|
+
|
|
37
47
|
private readonly device: GPUDevice;
|
|
38
48
|
private readonly pipelines = new Map<string, GPURenderPipeline>();
|
|
39
49
|
/**
|
|
@@ -52,10 +62,11 @@ export class PipelineCache {
|
|
|
52
62
|
*/
|
|
53
63
|
private readonly compiling = new Map<string, Promise<GPURenderPipeline>>();
|
|
54
64
|
|
|
55
|
-
constructor(device: GPUDevice, format: GPUTextureFormat, sampleCount = 1) {
|
|
65
|
+
constructor(device: GPUDevice, format: GPUTextureFormat, sampleCount = 1, glassShadows = true) {
|
|
56
66
|
this.device = device;
|
|
57
67
|
this.format = format;
|
|
58
68
|
this.sampleCount = sampleCount;
|
|
69
|
+
this.glassShadows = glassShadows;
|
|
59
70
|
}
|
|
60
71
|
|
|
61
72
|
/** How many distinct pipelines have been built. Read by tests and diagnostics. */
|