@pmndrs/vdb 0.1.0 → 0.2.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.md +592 -2
- package/README.md +85 -37
- package/THIRD_PARTY_NOTICES.md +197 -29
- package/dist/core/compute/atlas.d.ts +10 -2
- package/dist/core/compute/atlas.js +6 -1
- package/dist/core/compute/atlas.js.map +1 -1
- package/dist/core/compute/index.d.ts +3 -3
- package/dist/core/compute/index.js +2 -2
- package/dist/core/compute/index.js.map +1 -1
- package/dist/core/compute/majorant-build.d.ts +45 -0
- package/dist/core/compute/majorant-build.js +193 -0
- package/dist/core/compute/majorant-build.js.map +1 -0
- package/dist/core/compute/multi-scale.d.ts +155 -0
- package/dist/core/compute/multi-scale.js +684 -0
- package/dist/core/compute/multi-scale.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +22 -7
- package/dist/core/compute/pyramid.js +22 -9
- package/dist/core/compute/pyramid.js.map +1 -1
- package/dist/core/compute/shared.d.ts +1 -0
- package/dist/core/compute/shared.js.map +1 -1
- package/dist/core/compute/stats.d.ts +10 -3
- package/dist/core/compute/stats.js +6 -1
- package/dist/core/compute/stats.js.map +1 -1
- package/dist/core/compute/value-transform.d.ts +8 -1
- package/dist/core/compute/value-transform.js +9 -3
- package/dist/core/compute/value-transform.js.map +1 -1
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.js +8 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/frame/emission.d.ts +85 -0
- package/dist/core/frame/emission.js +422 -0
- package/dist/core/frame/emission.js.map +1 -0
- package/dist/core/frame/environment.d.ts +47 -0
- package/dist/core/frame/environment.js +178 -0
- package/dist/core/frame/environment.js.map +1 -0
- package/dist/core/frame/index.d.ts +39 -0
- package/dist/core/frame/index.js +27 -0
- package/dist/core/frame/index.js.map +1 -0
- package/dist/core/frame/kernels.d.ts +115 -0
- package/dist/core/frame/kernels.js +496 -0
- package/dist/core/frame/kernels.js.map +1 -0
- package/dist/core/frame/limits.d.ts +67 -0
- package/dist/core/frame/limits.js +109 -0
- package/dist/core/frame/limits.js.map +1 -0
- package/dist/core/frame/phase.d.ts +17 -0
- package/dist/core/frame/phase.js +53 -0
- package/dist/core/frame/phase.js.map +1 -0
- package/dist/core/frame/pipelines.d.ts +49 -0
- package/dist/core/frame/pipelines.js +147 -0
- package/dist/core/frame/pipelines.js.map +1 -0
- package/dist/core/frame/renderer.d.ts +122 -0
- package/dist/core/frame/renderer.js +1712 -0
- package/dist/core/frame/renderer.js.map +1 -0
- package/dist/core/frame/resources.d.ts +71 -0
- package/dist/core/frame/resources.js +100 -0
- package/dist/core/frame/resources.js.map +1 -0
- package/dist/core/frame/scattering.d.ts +97 -0
- package/dist/core/frame/scattering.js +332 -0
- package/dist/core/frame/scattering.js.map +1 -0
- package/dist/core/frame/settings.d.ts +243 -0
- package/dist/core/frame/settings.js +67 -0
- package/dist/core/frame/settings.js.map +1 -0
- package/dist/core/frame/shadows.d.ts +55 -0
- package/dist/core/frame/shadows.js +460 -0
- package/dist/core/frame/shadows.js.map +1 -0
- package/dist/core/frame/types.d.ts +415 -0
- package/dist/core/frame/types.js +49 -0
- package/dist/core/frame/types.js.map +1 -0
- package/dist/core/frame/uniforms.d.ts +105 -0
- package/dist/core/frame/uniforms.js +276 -0
- package/dist/core/frame/uniforms.js.map +1 -0
- package/dist/core/frame/wgsl/chunks.d.ts +4 -0
- package/dist/core/frame/wgsl/chunks.js +728 -0
- package/dist/core/frame/wgsl/chunks.js.map +1 -0
- package/dist/core/frame/wgsl/emission.d.ts +82 -0
- package/dist/core/frame/wgsl/emission.js +353 -0
- package/dist/core/frame/wgsl/emission.js.map +1 -0
- package/dist/core/frame/wgsl/environment.d.ts +42 -0
- package/dist/core/frame/wgsl/environment.js +711 -0
- package/dist/core/frame/wgsl/environment.js.map +1 -0
- package/dist/core/frame/wgsl/gather.d.ts +55 -0
- package/dist/core/frame/wgsl/gather.js +850 -0
- package/dist/core/frame/wgsl/gather.js.map +1 -0
- package/dist/core/frame/wgsl/integrate.d.ts +78 -0
- package/dist/core/frame/wgsl/integrate.js +213 -0
- package/dist/core/frame/wgsl/integrate.js.map +1 -0
- package/dist/core/frame/wgsl/lighting.d.ts +103 -0
- package/dist/core/frame/wgsl/lighting.js +1636 -0
- package/dist/core/frame/wgsl/lighting.js.map +1 -0
- package/dist/core/frame/wgsl/occluders.d.ts +20 -0
- package/dist/core/frame/wgsl/occluders.js +95 -0
- package/dist/core/frame/wgsl/occluders.js.map +1 -0
- package/dist/core/frame/wgsl/resolve.d.ts +19 -0
- package/dist/core/frame/wgsl/resolve.js +205 -0
- package/dist/core/frame/wgsl/resolve.js.map +1 -0
- package/dist/core/frame/wgsl/shadows.d.ts +35 -0
- package/dist/core/frame/wgsl/shadows.js +328 -0
- package/dist/core/frame/wgsl/shadows.js.map +1 -0
- package/dist/core/half.d.ts +11 -0
- package/dist/core/half.js +22 -0
- package/dist/core/half.js.map +1 -0
- package/dist/core/index.d.ts +25 -3
- package/dist/core/index.js +23 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/internal.d.ts +17 -1
- package/dist/core/internal.js +18 -1
- package/dist/core/internal.js.map +1 -1
- package/dist/core/pool/image-header.d.ts +13 -2
- package/dist/core/pool/image-header.js +24 -5
- package/dist/core/pool/image-header.js.map +1 -1
- package/dist/core/pool/layout.d.ts +35 -1
- package/dist/core/pool/layout.js +51 -2
- package/dist/core/pool/layout.js.map +1 -1
- package/dist/core/pool/limits.d.ts +1 -0
- package/dist/core/pool/limits.js +1 -0
- package/dist/core/pool/limits.js.map +1 -1
- package/dist/core/pool/pool.d.ts +120 -15
- package/dist/core/pool/pool.js +255 -24
- package/dist/core/pool/pool.js.map +1 -1
- package/dist/core/reference/index.d.ts +6 -0
- package/dist/core/reference/index.js +7 -0
- package/dist/core/reference/index.js.map +1 -0
- package/dist/core/reference/renderer.d.ts +105 -0
- package/dist/core/reference/renderer.js +474 -0
- package/dist/core/reference/renderer.js.map +1 -0
- package/dist/core/reference/wgsl.d.ts +65 -0
- package/dist/core/reference/wgsl.js +803 -0
- package/dist/core/reference/wgsl.js.map +1 -0
- package/dist/{three → core}/sequence.d.ts +32 -2
- package/dist/{three → core}/sequence.js +24 -2
- package/dist/core/sequence.js.map +1 -0
- package/dist/core/source/brick-cache.d.ts +165 -0
- package/dist/core/source/brick-cache.js +627 -0
- package/dist/core/source/brick-cache.js.map +1 -0
- package/dist/core/source/dense-fill.d.ts +53 -0
- package/dist/core/source/dense-fill.js +377 -0
- package/dist/core/source/dense-fill.js.map +1 -0
- package/dist/core/source/dense.d.ts +33 -2
- package/dist/core/source/dense.js +121 -24
- package/dist/core/source/dense.js.map +1 -1
- package/dist/core/source/sparse-wgsl.d.ts +92 -0
- package/dist/core/source/sparse-wgsl.js +481 -0
- package/dist/core/source/sparse-wgsl.js.map +1 -0
- package/dist/core/source/sparse.d.ts +192 -0
- package/dist/core/source/sparse.js +762 -0
- package/dist/core/source/sparse.js.map +1 -0
- package/dist/core/source/types.d.ts +59 -2
- package/dist/core/source/types.js.map +1 -1
- package/dist/core/surface/index.d.ts +10 -0
- package/dist/core/surface/index.js +9 -0
- package/dist/core/surface/index.js.map +1 -0
- package/dist/core/surface/level-set-pass.d.ts +140 -0
- package/dist/core/surface/level-set-pass.js +291 -0
- package/dist/core/surface/level-set-pass.js.map +1 -0
- package/dist/core/surface/level-set-wgsl.d.ts +46 -0
- package/dist/core/surface/level-set-wgsl.js +99 -0
- package/dist/core/surface/level-set-wgsl.js.map +1 -0
- package/dist/core/surface/points.d.ts +109 -0
- package/dist/core/surface/points.js +226 -0
- package/dist/core/surface/points.js.map +1 -0
- package/dist/core/types.d.ts +12 -3
- package/dist/core/types.js +6 -2
- package/dist/core/types.js.map +1 -1
- package/dist/core/wgsl/api.d.ts +29 -5
- package/dist/core/wgsl/api.js +110 -27
- package/dist/core/wgsl/api.js.map +1 -1
- package/dist/core/wgsl/generate.d.ts +8 -0
- package/dist/core/wgsl/generate.js +195 -22
- package/dist/core/wgsl/generate.js.map +1 -1
- package/dist/core/wgsl/lean.d.ts +50 -0
- package/dist/core/wgsl/lean.js +327 -0
- package/dist/core/wgsl/lean.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +5 -1
- package/dist/core/wgsl/level-set.js +11 -5
- package/dist/core/wgsl/level-set.js.map +1 -1
- package/dist/core/wgsl/majorant.d.ts +62 -0
- package/dist/core/wgsl/majorant.js +381 -0
- package/dist/core/wgsl/majorant.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
- package/dist/core/wgsl/types.d.ts +97 -3
- package/dist/core/wgsl/types.js.map +1 -1
- package/dist/three/coarse-first.d.ts +53 -8
- package/dist/three/coarse-first.js +24 -6
- package/dist/three/coarse-first.js.map +1 -1
- package/dist/three/compute.d.ts +12 -2
- package/dist/three/compute.js +16 -6
- package/dist/three/compute.js.map +1 -1
- package/dist/three/device.d.ts +7 -0
- package/dist/three/device.js +3 -0
- package/dist/three/device.js.map +1 -1
- package/dist/three/frame/core-environment.d.ts +38 -0
- package/dist/three/frame/core-environment.js +154 -0
- package/dist/three/frame/core-environment.js.map +1 -0
- package/dist/three/frame/core-integrate-material.d.ts +34 -0
- package/dist/three/frame/core-integrate-material.js +162 -0
- package/dist/three/frame/core-integrate-material.js.map +1 -0
- package/dist/three/frame/core-occluders.d.ts +53 -0
- package/dist/three/frame/core-occluders.js +193 -0
- package/dist/three/frame/core-occluders.js.map +1 -0
- package/dist/three/frame/core-structs.d.ts +34 -0
- package/dist/three/frame/core-structs.js +61 -0
- package/dist/three/frame/core-structs.js.map +1 -0
- package/dist/three/frame/core-textures.d.ts +41 -0
- package/dist/three/frame/core-textures.js +114 -0
- package/dist/three/frame/core-textures.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +64 -114
- package/dist/three/frame/emission-light.js +188 -567
- package/dist/three/frame/emission-light.js.map +1 -1
- package/dist/three/frame/index.d.ts +11 -31
- package/dist/three/frame/index.js +9 -29
- package/dist/three/frame/index.js.map +1 -1
- package/dist/three/frame/medium.d.ts +12 -0
- package/dist/three/frame/medium.js.map +1 -1
- package/dist/three/frame/renderer.d.ts +58 -454
- package/dist/three/frame/renderer.js +409 -1427
- package/dist/three/frame/renderer.js.map +1 -1
- package/dist/three/frame/spectrum.d.ts +0 -14
- package/dist/three/frame/spectrum.js +2 -23
- package/dist/three/frame/spectrum.js.map +1 -1
- package/dist/three/frame/three-internals.d.ts +3 -8
- package/dist/three/frame/three-internals.js +13 -11
- package/dist/three/frame/three-internals.js.map +1 -1
- package/dist/three/frame/volume-shadows.d.ts +93 -107
- package/dist/three/frame/volume-shadows.js +278 -631
- package/dist/three/frame/volume-shadows.js.map +1 -1
- package/dist/three/frame/volume.d.ts +91 -33
- package/dist/three/frame/volume.js +63 -51
- package/dist/three/frame/volume.js.map +1 -1
- package/dist/three/grid-node.d.ts +34 -1
- package/dist/three/grid-node.js +36 -1
- package/dist/three/grid-node.js.map +1 -1
- package/dist/three/index.d.ts +20 -11
- package/dist/three/index.js +21 -12
- package/dist/three/index.js.map +1 -1
- package/dist/three/internal.d.ts +14 -8
- package/dist/three/internal.js +11 -7
- package/dist/three/internal.js.map +1 -1
- package/dist/three/level-set-material.d.ts +81 -8
- package/dist/three/level-set-material.js +162 -125
- package/dist/three/level-set-material.js.map +1 -1
- package/dist/three/level-set-physical-material.d.ts +154 -0
- package/dist/three/level-set-physical-material.js +253 -0
- package/dist/three/level-set-physical-material.js.map +1 -0
- package/dist/three/level-set-velocity.d.ts +94 -0
- package/dist/three/level-set-velocity.js +208 -0
- package/dist/three/level-set-velocity.js.map +1 -0
- package/dist/three/material.d.ts +141 -11
- package/dist/three/material.js +161 -18
- package/dist/three/material.js.map +1 -1
- package/dist/three/points.d.ts +60 -4
- package/dist/three/points.js +140 -9
- package/dist/three/points.js.map +1 -1
- package/dist/three/sparse-source.d.ts +49 -117
- package/dist/three/sparse-source.js +109 -580
- package/dist/three/sparse-source.js.map +1 -1
- package/dist/three/volume-source.d.ts +11 -156
- package/dist/three/volume-source.js +29 -272
- package/dist/three/volume-source.js.map +1 -1
- package/dist/tools/cpu/brick-atlas.d.ts +36 -0
- package/dist/tools/cpu/brick-atlas.js +129 -0
- package/dist/tools/cpu/brick-atlas.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +23 -4
- package/dist/tools/cpu/compute.js +35 -14
- package/dist/tools/cpu/compute.js.map +1 -1
- package/dist/tools/cpu/lean-reads.d.ts +81 -0
- package/dist/tools/cpu/lean-reads.js +262 -0
- package/dist/tools/cpu/lean-reads.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +42 -3
- package/dist/tools/cpu/level-set.js +59 -7
- package/dist/tools/cpu/level-set.js.map +1 -1
- package/dist/tools/cpu/majorant.d.ts +265 -0
- package/dist/tools/cpu/majorant.js +541 -0
- package/dist/tools/cpu/majorant.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +93 -2
- package/dist/tools/cpu/march.js +165 -14
- package/dist/tools/cpu/march.js.map +1 -1
- package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
- package/dist/tools/cpu/mesh-decimate.js +1225 -0
- package/dist/tools/cpu/mesh-decimate.js.map +1 -0
- package/dist/tools/cpu/points.d.ts +29 -0
- package/dist/tools/cpu/points.js +38 -0
- package/dist/tools/cpu/points.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +19 -6
- package/dist/tools/cpu/read-value.js +32 -17
- package/dist/tools/cpu/read-value.js.map +1 -1
- package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
- package/dist/tools/cpu/sample-trilinear.js +19 -7
- package/dist/tools/cpu/sample-trilinear.js.map +1 -1
- package/dist/tools/cpu/stride-tables.d.ts +2 -2
- package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
- package/dist/tools/cpu/stride-tables.generated.js +7 -6
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
- package/dist/tools/cpu/stride-tables.js +1 -1
- package/dist/tools/cpu/stride-tables.js.map +1 -1
- package/dist/tools/cpu/surface-nets.d.ts +90 -0
- package/dist/tools/cpu/surface-nets.js +597 -0
- package/dist/tools/cpu/surface-nets.js.map +1 -0
- package/dist/tools/errors.d.ts +9 -0
- package/dist/tools/errors.js +9 -0
- package/dist/tools/errors.js.map +1 -1
- package/dist/tools/frame/ambient.d.ts +98 -0
- package/dist/tools/frame/ambient.js +274 -0
- package/dist/tools/frame/ambient.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +15 -0
- package/dist/tools/frame/blackbody.js +35 -0
- package/dist/tools/frame/blackbody.js.map +1 -1
- package/dist/tools/frame/brick-cache.d.ts +165 -0
- package/dist/tools/frame/brick-cache.js +326 -0
- package/dist/tools/frame/brick-cache.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +9 -0
- package/dist/tools/frame/emission.js +9 -1
- package/dist/tools/frame/emission.js.map +1 -1
- package/dist/tools/frame/environment-gpu.d.ts +111 -0
- package/dist/tools/frame/environment-gpu.js +280 -0
- package/dist/tools/frame/environment-gpu.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +3 -2
- package/dist/tools/frame/environment.js +8 -4
- package/dist/tools/frame/environment.js.map +1 -1
- package/dist/tools/frame/froxel.d.ts +58 -0
- package/dist/tools/frame/froxel.js +115 -0
- package/dist/tools/frame/froxel.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +90 -0
- package/dist/tools/frame/grid.js +112 -13
- package/dist/tools/frame/grid.js.map +1 -1
- package/dist/tools/frame/index.d.ts +14 -0
- package/dist/tools/frame/index.js +45 -4
- package/dist/tools/frame/index.js.map +1 -1
- package/dist/tools/frame/medium.d.ts +16 -0
- package/dist/tools/frame/medium.js +3 -1
- package/dist/tools/frame/medium.js.map +1 -1
- package/dist/tools/frame/mie.d.ts +9 -0
- package/dist/tools/frame/mie.js +18 -0
- package/dist/tools/frame/mie.js.map +1 -1
- package/dist/tools/frame/mlp-nn.d.ts +36 -0
- package/dist/tools/frame/mlp-nn.js +159 -0
- package/dist/tools/frame/mlp-nn.js.map +1 -0
- package/dist/tools/frame/mlp-tza.d.ts +29 -0
- package/dist/tools/frame/mlp-tza.js +186 -0
- package/dist/tools/frame/mlp-tza.js.map +1 -0
- package/dist/tools/frame/mlp.d.ts +183 -0
- package/dist/tools/frame/mlp.js +434 -0
- package/dist/tools/frame/mlp.js.map +1 -0
- package/dist/tools/frame/ms-exit.d.ts +42 -0
- package/dist/tools/frame/ms-exit.js +90 -0
- package/dist/tools/frame/ms-exit.js.map +1 -0
- package/dist/tools/frame/multi-scale.d.ts +152 -0
- package/dist/tools/frame/multi-scale.js +302 -0
- package/dist/tools/frame/multi-scale.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +6 -5
- package/dist/tools/frame/neural-weights.js +234 -235
- package/dist/tools/frame/neural-weights.js.map +1 -1
- package/dist/tools/frame/neural.js +1 -1
- package/dist/tools/frame/neural.js.map +1 -1
- package/dist/tools/frame/occluders.d.ts +51 -0
- package/dist/tools/frame/occluders.js +72 -0
- package/dist/tools/frame/occluders.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +17 -0
- package/dist/tools/frame/pyramid-layout.js +47 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -1
- package/dist/tools/frame/shadows.d.ts +110 -0
- package/dist/tools/frame/shadows.js +286 -0
- package/dist/tools/frame/shadows.js.map +1 -1
- package/dist/tools/frame/sparse.d.ts +82 -0
- package/dist/tools/frame/sparse.js +242 -1
- package/dist/tools/frame/sparse.js.map +1 -1
- package/dist/tools/frame/spectral-stack.d.ts +159 -0
- package/dist/tools/frame/spectral-stack.js +391 -0
- package/dist/tools/frame/spectral-stack.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +21 -2
- package/dist/tools/frame/spectral.js +30 -8
- package/dist/tools/frame/spectral.js.map +1 -1
- package/dist/tools/frame/stack.d.ts +115 -0
- package/dist/tools/frame/stack.js +290 -0
- package/dist/tools/frame/stack.js.map +1 -0
- package/dist/tools/frame/view.d.ts +131 -0
- package/dist/tools/frame/view.js +337 -0
- package/dist/tools/frame/view.js.map +1 -0
- package/dist/tools/index.d.ts +66 -15
- package/dist/tools/index.js +55 -11
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/internal.d.ts +58 -17
- package/dist/tools/internal.js +65 -11
- package/dist/tools/internal.js.map +1 -1
- package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
- package/dist/tools/nanovdb/build-from-vdb.js +10 -2
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
- package/dist/tools/nanovdb/bytes.d.ts +17 -4
- package/dist/tools/nanovdb/bytes.js +46 -3
- package/dist/tools/nanovdb/bytes.js.map +1 -1
- package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
- package/dist/tools/nanovdb/coarse-first.js +7 -1
- package/dist/tools/nanovdb/coarse-first.js.map +1 -1
- package/dist/tools/nanovdb/half.d.ts +22 -0
- package/dist/tools/nanovdb/half.js +73 -0
- package/dist/tools/nanovdb/half.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +3 -1
- package/dist/tools/nanovdb/index.js +2 -1
- package/dist/tools/nanovdb/index.js.map +1 -1
- package/dist/tools/nanovdb/inspect.d.ts +10 -1
- package/dist/tools/nanovdb/inspect.js +8 -1
- package/dist/tools/nanovdb/inspect.js.map +1 -1
- package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
- package/dist/tools/nanovdb/leaf-codec.js +40 -4
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
- package/dist/tools/nanovdb/quantize.d.ts +39 -10
- package/dist/tools/nanovdb/quantize.js +96 -44
- package/dist/tools/nanovdb/quantize.js.map +1 -1
- package/dist/tools/nanovdb/resample.d.ts +20 -3
- package/dist/tools/nanovdb/resample.js +20 -7
- package/dist/tools/nanovdb/resample.js.map +1 -1
- package/dist/tools/nanovdb/serialize.d.ts +34 -3
- package/dist/tools/nanovdb/serialize.js +51 -7
- package/dist/tools/nanovdb/serialize.js.map +1 -1
- package/dist/tools/nanovdb/stats.d.ts +34 -5
- package/dist/tools/nanovdb/stats.js +87 -11
- package/dist/tools/nanovdb/stats.js.map +1 -1
- package/dist/tools/nanovdb/transform.d.ts +4 -0
- package/dist/tools/nanovdb/transform.js +3 -0
- package/dist/tools/nanovdb/transform.js.map +1 -1
- package/dist/tools/nanovdb/tree.d.ts +14 -3
- package/dist/tools/nanovdb/tree.js +25 -13
- package/dist/tools/nanovdb/tree.js.map +1 -1
- package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
- package/dist/tools/nanovdb/write-nvdb.js +108 -28
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
- package/dist/tools/nvdb-file.d.ts +77 -7
- package/dist/tools/nvdb-file.js +177 -20
- package/dist/tools/nvdb-file.js.map +1 -1
- package/dist/tools/nvdb-stream.d.ts +23 -7
- package/dist/tools/nvdb-stream.js +78 -34
- package/dist/tools/nvdb-stream.js.map +1 -1
- package/dist/tools/reference/analytic.d.ts +41 -0
- package/dist/tools/reference/analytic.js +95 -0
- package/dist/tools/reference/analytic.js.map +1 -0
- package/dist/tools/reference/environment.d.ts +62 -0
- package/dist/tools/reference/environment.js +154 -0
- package/dist/tools/reference/environment.js.map +1 -0
- package/dist/tools/reference/index.d.ts +12 -0
- package/dist/tools/reference/index.js +13 -0
- package/dist/tools/reference/index.js.map +1 -0
- package/dist/tools/reference/media.d.ts +14 -0
- package/dist/tools/reference/media.js +30 -0
- package/dist/tools/reference/media.js.map +1 -0
- package/dist/tools/reference/rng.d.ts +20 -0
- package/dist/tools/reference/rng.js +30 -0
- package/dist/tools/reference/rng.js.map +1 -0
- package/dist/tools/reference/scene.d.ts +312 -0
- package/dist/tools/reference/scene.js +169 -0
- package/dist/tools/reference/scene.js.map +1 -0
- package/dist/tools/reference/tables.d.ts +98 -0
- package/dist/tools/reference/tables.js +264 -0
- package/dist/tools/reference/tables.js.map +1 -0
- package/dist/tools/reference/trace.d.ts +160 -0
- package/dist/tools/reference/trace.js +497 -0
- package/dist/tools/reference/trace.js.map +1 -0
- package/dist/tools/vdb/blosc-write.d.ts +43 -0
- package/dist/tools/vdb/blosc-write.js +197 -0
- package/dist/tools/vdb/blosc-write.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +35 -5
- package/dist/tools/vdb/blosc.js +82 -26
- package/dist/tools/vdb/blosc.js.map +1 -1
- package/dist/tools/vdb/blosclz.d.ts +33 -0
- package/dist/tools/vdb/blosclz.js +112 -0
- package/dist/tools/vdb/blosclz.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +13 -3
- package/dist/tools/vdb/byte-reader.js +26 -4
- package/dist/tools/vdb/byte-reader.js.map +1 -1
- package/dist/tools/vdb/compression.d.ts +13 -5
- package/dist/tools/vdb/compression.js +13 -2
- package/dist/tools/vdb/compression.js.map +1 -1
- package/dist/tools/vdb/grid.js +8 -2
- package/dist/tools/vdb/grid.js.map +1 -1
- package/dist/tools/vdb/index.d.ts +2 -1
- package/dist/tools/vdb/index.js.map +1 -1
- package/dist/tools/vdb/lz4.d.ts +30 -0
- package/dist/tools/vdb/lz4.js +228 -0
- package/dist/tools/vdb/lz4.js.map +1 -0
- package/dist/tools/vdb/metadata.js +1 -1
- package/dist/tools/vdb/metadata.js.map +1 -1
- package/dist/tools/vdb/parse.d.ts +24 -2
- package/dist/tools/vdb/parse.js +102 -32
- package/dist/tools/vdb/parse.js.map +1 -1
- package/dist/tools/vdb/point-render-data.d.ts +49 -1
- package/dist/tools/vdb/point-render-data.js +91 -11
- package/dist/tools/vdb/point-render-data.js.map +1 -1
- package/dist/tools/vdb/points.d.ts +26 -0
- package/dist/tools/vdb/points.js +46 -5
- package/dist/tools/vdb/points.js.map +1 -1
- package/dist/tools/vdb/types.d.ts +59 -2
- package/dist/tools/vdb/types.js.map +1 -1
- package/dist/tools/wvdb/bake.d.ts +38 -9
- package/dist/tools/wvdb/bake.js +63 -13
- package/dist/tools/wvdb/bake.js.map +1 -1
- package/dist/tools/wvdb/dense.d.ts +80 -1
- package/dist/tools/wvdb/dense.js +67 -8
- package/dist/tools/wvdb/dense.js.map +1 -1
- package/dist/tools/wvdb/format.d.ts +59 -0
- package/dist/tools/wvdb/format.js +3 -0
- package/dist/tools/wvdb/format.js.map +1 -1
- package/dist/tools/wvdb/index.d.ts +1 -0
- package/dist/tools/wvdb/index.js +1 -0
- package/dist/tools/wvdb/index.js.map +1 -1
- package/dist/tools/wvdb/level-set.d.ts +10 -2
- package/dist/tools/wvdb/level-set.js.map +1 -1
- package/dist/tools/wvdb/nanovdb.d.ts +6 -1
- package/dist/tools/wvdb/nanovdb.js +5 -1
- package/dist/tools/wvdb/nanovdb.js.map +1 -1
- package/dist/tools/wvdb/partial.d.ts +74 -0
- package/dist/tools/wvdb/partial.js +233 -0
- package/dist/tools/wvdb/partial.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +77 -1
- package/dist/tools/wvdb/read.js +30 -7
- package/dist/tools/wvdb/read.js.map +1 -1
- package/dist/tools/wvdb/write.d.ts +23 -1
- package/dist/tools/wvdb/write.js +8 -1
- package/dist/tools/wvdb/write.js.map +1 -1
- package/package.json +2 -1
- package/vendor/VENDOR.md +21 -6
- package/vendor/pnanovdb.wgsl +52 -14
- package/dist/three/frame/blackbody.d.ts +0 -42
- package/dist/three/frame/blackbody.js +0 -74
- package/dist/three/frame/blackbody.js.map +0 -1
- package/dist/three/frame/chunks.d.ts +0 -157
- package/dist/three/frame/chunks.js +0 -559
- package/dist/three/frame/chunks.js.map +0 -1
- package/dist/three/frame/density-material.d.ts +0 -53
- package/dist/three/frame/density-material.js +0 -353
- package/dist/three/frame/density-material.js.map +0 -1
- package/dist/three/frame/environment-grid-material.d.ts +0 -21
- package/dist/three/frame/environment-grid-material.js +0 -184
- package/dist/three/frame/environment-grid-material.js.map +0 -1
- package/dist/three/frame/environment-material.d.ts +0 -22
- package/dist/three/frame/environment-material.js +0 -87
- package/dist/three/frame/environment-material.js.map +0 -1
- package/dist/three/frame/grid-mip-material.d.ts +0 -12
- package/dist/three/frame/grid-mip-material.js +0 -61
- package/dist/three/frame/grid-mip-material.js.map +0 -1
- package/dist/three/frame/inject-material.d.ts +0 -56
- package/dist/three/frame/inject-material.js +0 -424
- package/dist/three/frame/inject-material.js.map +0 -1
- package/dist/three/frame/integrate-material.d.ts +0 -26
- package/dist/three/frame/integrate-material.js +0 -198
- package/dist/three/frame/integrate-material.js.map +0 -1
- package/dist/three/frame/layout.d.ts +0 -34
- package/dist/three/frame/layout.js +0 -48
- package/dist/three/frame/layout.js.map +0 -1
- package/dist/three/frame/lighting-material.d.ts +0 -41
- package/dist/three/frame/lighting-material.js +0 -257
- package/dist/three/frame/lighting-material.js.map +0 -1
- package/dist/three/frame/lights.d.ts +0 -11
- package/dist/three/frame/lights.js +0 -16
- package/dist/three/frame/lights.js.map +0 -1
- package/dist/three/frame/neural.d.ts +0 -14
- package/dist/three/frame/neural.js +0 -105
- package/dist/three/frame/neural.js.map +0 -1
- package/dist/three/frame/phase.d.ts +0 -44
- package/dist/three/frame/phase.js +0 -80
- package/dist/three/frame/phase.js.map +0 -1
- package/dist/three/frame/shadow-density-material.d.ts +0 -30
- package/dist/three/frame/shadow-density-material.js +0 -123
- package/dist/three/frame/shadow-density-material.js.map +0 -1
- package/dist/three/frame/temporal-material.d.ts +0 -29
- package/dist/three/frame/temporal-material.js +0 -152
- package/dist/three/frame/temporal-material.js.map +0 -1
- package/dist/three/frame/transmittance-material.d.ts +0 -31
- package/dist/three/frame/transmittance-material.js +0 -315
- package/dist/three/frame/transmittance-material.js.map +0 -1
- package/dist/three/frame/view.d.ts +0 -103
- package/dist/three/frame/view.js +0 -296
- package/dist/three/frame/view.js.map +0 -1
- package/dist/three/frame/volume-shadow-material.d.ts +0 -36
- package/dist/three/frame/volume-shadow-material.js +0 -128
- package/dist/three/frame/volume-shadow-material.js.map +0 -1
- package/dist/three/sequence.js.map +0 -1
|
@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MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,WAAW,GAAG,CAAC,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,QAAQ,CAAC,gBAAgB,EAAE,2DAA2D,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC1I,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,UAAU,CAAC,IAAI,CAAC,CAAC,CAAE,CAAE,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAE,CAAE,GAAG,CAAC,CAAC,CAAC,WAAW,UAAU,CAAC,IAAI,CAAC,CAAC,CAAE,CAAE,QAAQ,CAAC;IAC/I,MAAM,QAAQ,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACzE,OAAO,UAAU,CAAC,GAAG,uBAAuB;;;;;;;;;;;;iBAY7B,SAAS;;;;aAIb,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CpB,CAAC;AACF,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 4e2d46f (\"Add opt-in multi-scale density lookups for\n// indirect light\", after v0.29):\n// src/three-openvdb/frame/webgpu/frameMultiScaleChunks.js L1–71 (frameMultiScaleLight);\n// src/three-openvdb/frame/webgpu/FrameGridMipMaterial.js (the binomial branch: weights 1 3 3 1 on 4 x 4 x 4 taps);\n// src/three-openvdb/frame/webgpu/frameNeuralChunks.js (createNeuralMipNodes: sampleLevel, unit).\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: WGSL compute on 3D textures (his levels are z-slice atlases drawn by a fragment pass); the chain is\n// built in f32 and written as f16 by buffer copies (rg16float in core WebGPU, no storage-texture format needed);\n// zero-padded binomial levels on an exactly halving layout by default (his clamped edges behind `edge: 'clamp'`);\n// the lookup is a text WGSL function over host-bound textures. CPU twins: `tools/frame/multi-scale.ts`.\n// Divergences: DIVERGES.md (K7.3 row).\n\n/**\n * `vdbCreateMultiScaleMips` (K7.3): the binomial mip chain of a 3D grid texture for `'multi-scale'` multiple\n * scattering (mjurczyk 4e2d46f, Disney \"Deep Scattering\" §4.2), recorded into the host's encoder, plus the WGSL\n * lookup a transmittance kernel calls (`vdbFrameMultiScaleWgsl`). Engine-free; internal (K6.3 consumes it).\n *\n * Build, one compute pass (dispatches see each other's writes):\n * 1. **level** k = 1 … levels − 1 (one thread per texel of level k): the separable 1 3 3 1 sum of the 4 × 4 × 4\n * taps 2x − 1 … 2x + 2 of level k − 1, / 512, in f32 into a scratch chain. Level 1 reads the host's texture\n * (`textureLoad`, any float format, the selected channels, a region at `origin`); level k ≥ 2 reads the chain.\n * 2. **pack** (one thread per output word): f32 → f16 (round to nearest even, `vdbFloatToHalf`) into rows of\n * 256-byte multiples, then `copyBufferToTexture` into mip k − 1 of the output texture.\n *\n * Output: one 3D texture, mip j = level j + 1, sizes halving exactly (`vdbFrameMultiScaleLayout`). Format\n * r16float / rg16float / rgba16float by channel count; all three are filterable and copy targets in core WebGPU,\n * so no optional feature is needed (rg16float is not storage-capable without `texture-formats-tier1`, which is\n * why the kernel writes a buffer, not a storage texture). The texture is the chain's own\n * (`TEXTURE_BINDING | COPY_DST | COPY_SRC`) or the host's (`target`, never destroyed here).\n *\n * Lifetime: `resize` replaces the texture and the scratch (`version` bumps); the old ones are retired, as the\n * pool's buffers: destroyed after two more `record`s, once `queue.onSubmittedWorkDone()` asked then resolves, so\n * a bind group the host built on the old `view` for the frame in flight stays valid. `destroy()` frees everything\n * this object allocated (retired included), never `target`.\n */\nimport { VDBError } from \"../errors.js\";\nimport { USAGE, WORKGROUP_AXIS } from \"./shared.js\";\nimport {\n VDB_FRAME_MULTI_SCALE_DEFAULT_LEVELS,\n vdbFrameMultiScaleLayout,\n type VDBFrameMultiScaleEdge,\n type VDBFrameMultiScaleLayout,\n} from \"../../tools/frame/multi-scale.js\";\n\nconst W = WORKGROUP_AXIS;\nconst STAGE_COMPUTE = 0x4;\nconst TEXTURE_USAGE = { COPY_SRC: 0x1, COPY_DST: 0x2, TEXTURE_BINDING: 0x4 } as const;\n/** Uniform slot stride (minUniformBufferOffsetAlignment's default). */\nconst SLOT = 256;\nconst PARAMS_BYTES = 112;\n\n/** Output formats of the chain: components per texel. */\nexport type VDBMultiScaleFormat = \"r16float\" | \"rg16float\" | \"rgba16float\";\nconst FORMAT_CHANNELS: Record<VDBMultiScaleFormat, number> = { r16float: 1, rg16float: 2, rgba16float: 4 };\n\nconst BUILD_WGSL = /* wgsl */ `\nstruct MsParams {\n srcOrigin: vec3u,\n fromTexture: u32,\n srcDims: vec3u,\n srcOffset: u32,\n srcExtent: vec3u,\n dstOffset: u32,\n dims: vec3u,\n edgeClamp: u32,\n dstExtent: vec3u,\n channels: u32,\n select: vec4u,\n rowWords: u32,\n texelChannels: u32,\n packOffset: u32,\n pad0: u32,\n};\n@group(0) @binding(0) var<uniform> ms: MsParams;\n@group(0) @binding(1) var msSource: texture_3d<f32>;\n@group(0) @binding(2) var<storage, read_write> msScratch: array<u32>;\n\nfn msWeight(i: i32) -> f32 {\n return select(3.0, 1.0, i == 0 || i == 3);\n}\n\n// Tap p of the source level, channel c: 0 outside it ('zero'), or clamped to its valid texels ('clamp').\nfn msTap(p: vec3i, c: u32) -> f32 {\n var q = p;\n if ms.edgeClamp != 0u {\n q = clamp(p, vec3i(0), vec3i(ms.srcExtent) - vec3i(1));\n } else if any(p < vec3i(0)) || any(p >= vec3i(ms.srcDims)) {\n return 0.0;\n }\n if ms.fromTexture != 0u {\n let t = textureLoad(msSource, vec3u(q) + ms.srcOrigin, 0);\n return t[ms.select[c]];\n }\n let i = (u32(q.x) + (u32(q.y) + u32(q.z) * ms.srcDims.y) * ms.srcDims.x) * ms.channels + c;\n return bitcast<f32>(msScratch[ms.srcOffset + i]);\n}\n\n// One texel of level k: the 1 3 3 1 binomial of the 4 x 4 x 4 taps 2x - 1 ... 2x + 2 (x, then y, then z), / 512.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csMsLevel(@builtin(global_invocation_id) id: vec3u) {\n if any(id >= ms.dims) {\n return;\n }\n var e = id;\n if ms.edgeClamp != 0u {\n e = min(id, ms.dstExtent - vec3u(1u));\n }\n let b = vec3i(e) * 2 - vec3i(1);\n let o = (id.x + (id.y + id.z * ms.dims.y) * ms.dims.x) * ms.channels;\n for (var c = 0u; c < ms.channels; c++) {\n var sz = 0.0;\n for (var l = 0; l < 4; l++) {\n var sy = 0.0;\n for (var j = 0; j < 4; j++) {\n var sx = 0.0;\n for (var i = 0; i < 4; i++) {\n sx += msWeight(i) * msTap(b + vec3i(i, j, l), c);\n }\n sy += msWeight(j) * sx;\n }\n sz += msWeight(l) * sy;\n }\n msScratch[ms.dstOffset + o + c] = bitcast<u32>(sz / 512.0);\n }\n}\n\n// f32 -> f16 bits, round to nearest even (tools vdbFloatToHalf, after NanoVDB HalfLite).\nfn msHalf(v: f32) -> u32 {\n let bits = bitcast<u32>(v);\n let ui = bits & 0x7fffffffu;\n var h = (bits >> 16u) & 0x8000u;\n if ui >= 0x38800000u {\n if ui >= 0x7f800000u {\n h = h | 0x7c00u;\n if ui == 0x7f800000u {\n return h;\n }\n let m = (ui & 0x7fffffu) >> 13u;\n return h | m | select(0u, 1u, m == 0u);\n }\n if ui > 0x477fefffu {\n return h | 0x7c00u;\n }\n let r = ui - 0x38000000u;\n return h | ((r + 0x00000fffu + ((r >> 13u) & 1u)) >> 13u);\n }\n if ui < 0x33000001u {\n return h;\n }\n let shift = 0x7eu - (ui >> 23u);\n let m = 0x800000u | (ui & 0x7fffffu);\n let r = m << (32u - shift);\n h = h | (m >> shift);\n if r > 0x80000000u || (r == 0x80000000u && (h & 1u) != 0u) {\n h = h + 1u;\n }\n return h;\n}\n\n// Half number n of a row: texel n / texelChannels, component n % texelChannels (0 past the level's channels).\nfn msRowHalf(y: u32, z: u32, n: u32) -> u32 {\n let x = n / ms.texelChannels;\n let c = n % ms.texelChannels;\n if x >= ms.dims.x || c >= ms.channels {\n return 0u;\n }\n let i = (x + (y + z * ms.dims.y) * ms.dims.x) * ms.channels + c;\n return msHalf(bitcast<f32>(msScratch[ms.dstOffset + i]));\n}\n\n// Two halves per word, rows of rowWords words (bytesPerRow a multiple of 256), at packOffset words.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csMsPack(@builtin(global_invocation_id) id: vec3u) {\n let words = (ms.dims.x * ms.texelChannels + 1u) / 2u;\n if id.x >= words || id.y >= ms.dims.y || id.z >= ms.dims.z {\n return;\n }\n let lo = msRowHalf(id.y, id.z, id.x * 2u);\n let hi = msRowHalf(id.y, id.z, id.x * 2u + 1u);\n msScratch[ms.packOffset + (id.y + id.z * ms.dims.y) * ms.rowWords + id.x] = lo | (hi << 16u);\n}\n`;\n\n/** The WGSL of the mip build kernels (exported for tests). */\nexport function multiScaleMipsWgsl(): string {\n return BUILD_WGSL;\n}\n\ninterface Pipelines {\n level: GPUComputePipeline;\n pack: GPUComputePipeline;\n group0: GPUBindGroupLayout;\n error: Promise<GPUError | null>;\n}\n\nconst pipelines = new WeakMap<GPUDevice, Pipelines>();\n\nfunction multiScalePipelines(device: GPUDevice): Pipelines {\n const cached = pipelines.get(device);\n if (cached) return cached;\n device.pushErrorScope(\"validation\");\n const group0 = device.createBindGroupLayout({\n label: \"vdb multiScaleMips group 0\",\n entries: [\n { binding: 0, visibility: STAGE_COMPUTE, buffer: { type: \"uniform\", hasDynamicOffset: true, minBindingSize: PARAMS_BYTES } },\n { binding: 1, visibility: STAGE_COMPUTE, texture: { sampleType: \"unfilterable-float\", viewDimension: \"3d\" } },\n { binding: 2, visibility: STAGE_COMPUTE, buffer: { type: \"storage\" } },\n ],\n });\n const module = device.createShaderModule({ label: \"vdb multiScaleMips\", code: BUILD_WGSL });\n const layout = device.createPipelineLayout({ bindGroupLayouts: [group0] });\n const make = (entryPoint: string) => device.createComputePipeline({ label: `vdb multiScaleMips ${entryPoint}`, layout, compute: { module, entryPoint } });\n const p: Pipelines = { level: make(\"csMsLevel\"), pack: make(\"csMsPack\"), group0, error: device.popErrorScope() };\n pipelines.set(device, p);\n return p;\n}\n\n/** Options of {@link vdbCreateMultiScaleMips}. */\nexport interface VDBMultiScaleMipsOptions {\n /** Base texels per axis: the grid region the levels filter (one cascade of the shadow grid). */\n size: readonly [number, number, number];\n /** Levels including the base (2 to 8, default 6: his `multiScaleLevels` maximum). */\n levels?: number;\n /** Source components that become the level channels, in order (default [0, 1]: extinction, absorption). */\n channels?: readonly number[];\n /** Output format (default by channel count: 1 r16float, 2 rg16float, 3–4 rgba16float). */\n format?: VDBMultiScaleFormat;\n /** Edge rule (default `'zero'`; `'clamp'` is his clamp-to-edge). */\n edge?: VDBFrameMultiScaleEdge;\n /**\n * Write into this 3D texture instead of allocating: `format`, the layout's level-1 size, levels − 1 mips,\n * `COPY_DST`. Never destroyed here.\n */\n target?: GPUTexture;\n /** Debug label of the GPU objects. */\n label?: string;\n}\n\n/** Options of {@link VDBMultiScaleMips.record}. */\nexport interface VDBMultiScaleRecordOptions {\n /** First texel of the base region in the source texture (default 0, 0, 0): a cascade of a stacked grid. */\n origin?: readonly [number, number, number];\n /** Timestamps around the build's one compute pass (the `timestamp-query` feature). */\n timestampWrites?: GPUComputePassTimestampWrites;\n}\n\n/** Options of {@link VDBMultiScaleMips.resize}. */\nexport interface VDBMultiScaleResizeOptions {\n /** Levels (default: unchanged). */\n levels?: number;\n /** The host texture for the new size (required when the chain was made with `target`). */\n target?: GPUTexture;\n}\n\n/** The mip chain of a grid texture on the GPU (see the file comment). */\nexport interface VDBMultiScaleMips {\n /** The level sizes (levels 1 … levels − 1 = mips 0 … levels − 2 of {@link texture}). */\n readonly layout: VDBFrameMultiScaleLayout;\n /** Components per level texel (the `channels` option's length). */\n readonly channels: number;\n /** The texture's format. */\n readonly format: VDBMultiScaleFormat;\n /** The levels as one 3D texture with levels − 1 mips. */\n readonly texture: GPUTexture;\n /** A 3D view of every mip of {@link texture}: bind it as the lookup's `mips`. */\n readonly view: GPUTextureView;\n /** Bumps when `resize` replaces {@link texture}: rebuild bind groups that hold {@link view}. */\n readonly version: number;\n /** Bytes: `textures` (counted whoever owns them) and `scratch` (this chain's buffers). */\n readonly gpuBytes: { readonly textures: number; readonly scratch: number };\n /** Pipeline validation (null = valid). */\n readonly error: Promise<GPUError | null>;\n /**\n * Records a build of every level from `source` into `encoder`; the host submits it. Record it after the\n * pass that writes `source` (in the same encoder or an earlier submit).\n *\n * @param encoder The host's encoder.\n * @param source The base grid: a 3D texture with `TEXTURE_BINDING` and a float sample type, or a 3D view of\n * one (then the size and format are the host's to check). Holds the region at `origin`.\n * @param options Region origin and timestamps. The origin lives in a uniform written with `queue.writeBuffer`,\n * so builds from two origins need two submits.\n */\n record(encoder: GPUCommandEncoder, source: GPUTexture | GPUTextureView, options?: VDBMultiScaleRecordOptions): void;\n /** New base size (and levels): new texture and scratch, `version` bumps, the old ones retired (file comment). */\n resize(size: readonly [number, number, number], options?: VDBMultiScaleResizeOptions): void;\n /** Frees what this chain allocated, retired resources included (never `target`). Idempotent. */\n destroy(): void;\n}\n\nconst align = (n: number, a: number) => Math.ceil(n / a) * a;\nconst bad = (message: string): never => {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbCreateMultiScaleMips: ${message}`);\n};\n\n/** Updates a retired texture must outlive before the chain asks the queue about it (the pool's rule). */\nconst RETIRE_AFTER_RECORDS = 2;\n\ninterface Resources {\n layout: VDBFrameMultiScaleLayout;\n texture: GPUTexture;\n view: GPUTextureView;\n owned: (GPUBuffer | GPUTexture)[];\n scratch: GPUBuffer;\n params: GPUBuffer;\n /** Per level: chain word offset, packed word offset, packed row words. */\n offsets: { chain: number; pack: number; rowWords: number }[];\n gpuBytes: { textures: number; scratch: number };\n}\n\nconst isTexture = (s: GPUTexture | GPUTextureView): s is GPUTexture => typeof (s as GPUTexture).createView === \"function\";\n\nclass MultiScaleMips implements VDBMultiScaleMips {\n readonly channels: number;\n readonly format: VDBMultiScaleFormat;\n readonly error: Promise<GPUError | null>;\n version = 0;\n readonly #device: GPUDevice;\n readonly #select: readonly number[];\n readonly #edge: VDBFrameMultiScaleEdge;\n readonly #label: string;\n readonly #hostTarget: boolean;\n #r: Resources;\n #records = 0;\n #retired: { resources: (GPUBuffer | GPUTexture)[]; since: number; waiting: boolean }[] = [];\n #destroyed = false;\n\n constructor(device: GPUDevice, o: VDBMultiScaleMipsOptions) {\n if (!device || typeof (device as { createBuffer?: unknown }).createBuffer !== \"function\") bad(\"expected a GPUDevice as the first argument.\");\n if (!o || typeof o !== \"object\") bad(\"expected an options object with size.\");\n const select = o.channels ?? [0, 1];\n if (!Array.isArray(select) || select.length < 1 || select.length > 4 || select.some((c) => !Number.isInteger(c) || c < 0 || c > 3)) {\n bad(`channels must be 1 to 4 component indices from 0 to 3, got ${JSON.stringify(o.channels)}.`);\n }\n const format = o.format ?? (select.length === 1 ? \"r16float\" : select.length === 2 ? \"rg16float\" : \"rgba16float\");\n if (!(format in FORMAT_CHANNELS)) bad(`format must be r16float, rg16float or rgba16float, got ${JSON.stringify(o.format)}.`);\n if (FORMAT_CHANNELS[format] < select.length) bad(`format ${format} holds ${FORMAT_CHANNELS[format]} channel(s); channels has ${select.length}.`);\n const edge = o.edge ?? \"zero\";\n if (edge !== \"zero\" && edge !== \"clamp\") bad(`edge must be 'zero' or 'clamp', got ${JSON.stringify(o.edge)}.`);\n this.#device = device;\n this.#select = [...select];\n this.channels = select.length;\n this.format = format;\n this.#edge = edge;\n this.#label = o.label ?? \"vdb multiScaleMips\";\n this.#hostTarget = !!o.target;\n this.#r = this.#allocate(o.size, o.levels ?? VDB_FRAME_MULTI_SCALE_DEFAULT_LEVELS, o.target);\n this.error = multiScalePipelines(device).error;\n }\n\n get layout(): VDBFrameMultiScaleLayout {\n return this.#r.layout;\n }\n get texture(): GPUTexture {\n return this.#r.texture;\n }\n get view(): GPUTextureView {\n return this.#r.view;\n }\n get gpuBytes(): { textures: number; scratch: number } {\n return this.#r.gpuBytes;\n }\n\n #allocate(size: readonly number[], levels: number, target: GPUTexture | undefined): Resources {\n let layout: VDBFrameMultiScaleLayout;\n try {\n layout = vdbFrameMultiScaleLayout(size, levels);\n } catch (e) {\n return bad(e instanceof Error ? e.message.replace(/^.*?vdbFrameMultiScaleLayout: /, \"\") : String(e));\n }\n const device = this.#device;\n const F = FORMAT_CHANNELS[this.format];\n const C = this.channels;\n const top = layout.mips[0]!.dimensions;\n const mipCount = layout.levels - 1;\n const owned: (GPUBuffer | GPUTexture)[] = [];\n let texture: GPUTexture;\n if (target) {\n if (target.format !== this.format || target.dimension !== \"3d\" || target.width !== top[0] || target.height !== top[1] || target.depthOrArrayLayers !== top[2] || target.mipLevelCount !== mipCount || (target.usage & TEXTURE_USAGE.COPY_DST) === 0) {\n bad(\n `target must be a ${this.format} 3D texture of ${top.join(\"x\")} with ${mipCount} mip levels and COPY_DST ` +\n `(got ${target.format} ${target.dimension} ${target.width}x${target.height}x${target.depthOrArrayLayers}, ${target.mipLevelCount} mips, usage ${target.usage}).`,\n );\n }\n texture = target;\n } else {\n if (this.#hostTarget) bad(\"this chain writes into a host target: pass options.target for the new size.\");\n texture = device.createTexture({\n label: `${this.#label} levels`,\n size: [top[0], top[1], top[2]],\n dimension: \"3d\",\n format: this.format,\n mipLevelCount: mipCount,\n usage: TEXTURE_USAGE.TEXTURE_BINDING | TEXTURE_USAGE.COPY_DST | TEXTURE_USAGE.COPY_SRC,\n });\n owned.push(texture);\n }\n const offsets: Resources[\"offsets\"] = [];\n let chain = 0;\n for (const m of layout.mips) {\n offsets.push({ chain, pack: 0, rowWords: align(m.dimensions[0] * F * 2, 256) / 4 });\n chain += m.dimensions[0] * m.dimensions[1] * m.dimensions[2] * C;\n }\n let pack = align(chain, 64);\n layout.mips.forEach((m, i) => {\n offsets[i]!.pack = pack;\n pack = align(pack + offsets[i]!.rowWords * m.dimensions[1] * m.dimensions[2], 64);\n });\n const scratch = device.createBuffer({ label: `${this.#label} scratch`, size: Math.max(4, pack * 4), usage: USAGE.STORAGE | USAGE.COPY_SRC });\n const params = device.createBuffer({ label: `${this.#label} params`, size: 2 * mipCount * SLOT, usage: USAGE.UNIFORM | USAGE.COPY_DST });\n owned.push(scratch, params);\n const textureBytes = layout.mips.reduce((s, m) => s + m.dimensions[0] * m.dimensions[1] * m.dimensions[2] * F * 2, 0);\n const r: Resources = {\n layout,\n texture,\n view: texture.createView({ label: `${this.#label} view`, dimension: \"3d\" }),\n owned,\n scratch,\n params,\n offsets,\n gpuBytes: { textures: textureBytes, scratch: scratch.size + params.size },\n };\n this.#writeParams(r, [0, 0, 0]);\n return r;\n }\n\n /** Slots: level k at 2(k − 1), its pack at 2(k − 1) + 1. Only the level-1 slot depends on `origin`. */\n #writeParams(r: Resources, origin: readonly number[]): void {\n const { layout, offsets } = r;\n const bytes = new ArrayBuffer(2 * layout.mips.length * SLOT);\n const F = FORMAT_CHANNELS[this.format];\n layout.mips.forEach((m, i) => {\n const fromBase = i === 0;\n const srcDims = fromBase ? layout.size : layout.mips[i - 1]!.dimensions;\n const srcExtent = fromBase ? layout.size : layout.mips[i - 1]!.extent;\n for (const pack of [false, true]) {\n const u = new Uint32Array(bytes, (2 * i + (pack ? 1 : 0)) * SLOT, PARAMS_BYTES / 4);\n for (let a = 0; a < 3; a++) {\n u[a] = fromBase ? origin[a]! : 0;\n u[4 + a] = srcDims[a]!;\n u[8 + a] = srcExtent[a]!;\n u[12 + a] = m.dimensions[a]!;\n u[16 + a] = m.extent[a]!;\n }\n u[3] = fromBase ? 1 : 0;\n u[7] = fromBase ? 0 : offsets[i - 1]!.chain;\n u[11] = offsets[i]!.chain;\n u[15] = this.#edge === \"clamp\" ? 1 : 0;\n u[19] = this.channels;\n for (let c = 0; c < 4; c++) u[20 + c] = this.#select[c] ?? 0;\n u[24] = offsets[i]!.rowWords;\n u[25] = F;\n u[26] = offsets[i]!.pack;\n }\n });\n this.#device.queue.writeBuffer(r.params, 0, bytes);\n }\n\n #origin: readonly number[] = [0, 0, 0];\n\n record(encoder: GPUCommandEncoder, source: GPUTexture | GPUTextureView, options: VDBMultiScaleRecordOptions = {}): void {\n if (this.#destroyed) throw new VDBError(\"VDB_DISPOSED\", \"vdbCreateMultiScaleMips: record() after destroy().\");\n if (!source || typeof source !== \"object\") bad(\"record: expected the source GPUTexture or GPUTextureView.\");\n const origin = options.origin ?? [0, 0, 0];\n if (origin.length !== 3 || origin.some((v) => !Number.isInteger(v) || v < 0)) bad(`record: origin must be 3 integers >= 0, got ${JSON.stringify(origin)}.`);\n const r = this.#r;\n const size = r.layout.size;\n let view: GPUTextureView;\n if (isTexture(source)) {\n const f = source.format;\n if (source.dimension !== \"3d\" || (source.usage & TEXTURE_USAGE.TEXTURE_BINDING) === 0 || /int|depth|stencil/.test(f)) {\n bad(`record: the source must be a 3D texture with TEXTURE_BINDING and a float format (got ${source.dimension} ${f}, usage ${source.usage}).`);\n }\n const extent = [source.width, source.height, source.depthOrArrayLayers];\n if ([0, 1, 2].some((a) => origin[a]! + size[a]! > extent[a]!)) {\n bad(`record: the region (origin ${origin.join(\",\")}, size ${size.join(\"x\")}) is outside the source (${extent.join(\"x\")}).`);\n }\n view = source.createView({ dimension: \"3d\", baseMipLevel: 0, mipLevelCount: 1 });\n } else {\n view = source;\n }\n this.#records++;\n this.#reap();\n if (origin.some((v, a) => v !== this.#origin[a])) {\n this.#origin = [...origin];\n this.#writeParams(r, origin);\n }\n const device = this.#device;\n const p = multiScalePipelines(device);\n const group = device.createBindGroup({\n label: `${this.#label} group`,\n layout: p.group0,\n entries: [\n { binding: 0, resource: { buffer: r.params, size: PARAMS_BYTES } },\n { binding: 1, resource: view },\n { binding: 2, resource: { buffer: r.scratch } },\n ],\n });\n const F = FORMAT_CHANNELS[this.format];\n const groups = (s: readonly number[]): [number, number, number] => [Math.ceil(s[0]! / W), Math.ceil(s[1]! / W), Math.ceil(s[2]! / W)];\n const pass = encoder.beginComputePass({ label: \"vdb multiScaleMips\", ...(options.timestampWrites ? { timestampWrites: options.timestampWrites } : {}) });\n r.layout.mips.forEach((m, i) => {\n pass.setPipeline(p.level);\n pass.setBindGroup(0, group, [2 * i * SLOT]);\n pass.dispatchWorkgroups(...groups(m.dimensions));\n });\n r.layout.mips.forEach((m, i) => {\n pass.setPipeline(p.pack);\n pass.setBindGroup(0, group, [(2 * i + 1) * SLOT]);\n pass.dispatchWorkgroups(...groups([Math.ceil((m.dimensions[0] * F) / 2), m.dimensions[1], m.dimensions[2]]));\n });\n pass.end();\n r.layout.mips.forEach((m, i) => {\n const o = r.offsets[i]!;\n encoder.copyBufferToTexture(\n { buffer: r.scratch, offset: o.pack * 4, bytesPerRow: o.rowWords * 4, rowsPerImage: m.dimensions[1] },\n { texture: r.texture, mipLevel: i },\n [m.dimensions[0], m.dimensions[1], m.dimensions[2]],\n );\n });\n }\n\n resize(size: readonly [number, number, number], options: VDBMultiScaleResizeOptions = {}): void {\n if (this.#destroyed) throw new VDBError(\"VDB_DISPOSED\", \"vdbCreateMultiScaleMips: resize() after destroy().\");\n const next = this.#allocate(size, options.levels ?? this.#r.layout.levels, options.target);\n this.#retired.push({ resources: this.#r.owned, since: this.#records, waiting: false });\n this.#r = next;\n this.#origin = [0, 0, 0];\n this.version++;\n }\n\n /** The pool's rule: retired at least two records ago, then destroyed once the queue says that work is done. */\n #reap(): void {\n const ready = this.#retired.filter((r) => !r.waiting && this.#records - r.since >= RETIRE_AFTER_RECORDS);\n if (ready.length === 0) return;\n for (const r of ready) r.waiting = true;\n const destroy = (): void => {\n if (this.#destroyed) return; // destroy() freed them\n this.#retired = this.#retired.filter((r) => !ready.includes(r));\n for (const r of ready) for (const x of r.resources) x.destroy();\n };\n this.#device.queue.onSubmittedWorkDone().then(destroy, destroy);\n }\n\n destroy(): void {\n if (this.#destroyed) return;\n this.#destroyed = true;\n for (const r of this.#retired) for (const x of r.resources) x.destroy();\n this.#retired = [];\n for (const x of this.#r.owned) x.destroy();\n }\n}\n\n/**\n * Creates the binomial mip chain of a grid texture for `'multi-scale'` multiple scattering (see the file comment)\n * and returns it unbuilt: record a build with `mips.record(encoder, source)` after the pass that writes the grid,\n * then bind `mips.view` as the lookup's `mips` (`vdbFrameMultiScaleWgsl`).\n *\n * const mips = vdbCreateMultiScaleMips(device, { size: [64, 64, 64] });\n * mips.record(encoder, shadowGrid, { origin: [0, 0, 64 * lastCascade] });\n * device.queue.submit([encoder.finish()]);\n *\n * @param device The host's `GPUDevice`.\n * @param options Size, levels, channels, format, edge rule, target and label ({@link VDBMultiScaleMipsOptions}).\n */\nexport function vdbCreateMultiScaleMips(device: GPUDevice, options: VDBMultiScaleMipsOptions): VDBMultiScaleMips {\n return new MultiScaleMips(device, options);\n}\n\n/** Bytes of the WGSL `VdbFrameMultiScale` struct ({@link vdbFrameMultiScaleParams}). */\nexport const VDB_FRAME_MULTI_SCALE_PARAMS_BYTES = 64;\n\n/** The lookup's sampler: linear, clamp-to-edge (the lookup picks each mip with an explicit level). */\nexport const VDB_FRAME_MULTI_SCALE_SAMPLER: GPUSamplerDescriptor = {\n label: \"vdb multiScale sampler\",\n magFilter: \"linear\",\n minFilter: \"linear\",\n mipmapFilter: \"nearest\",\n addressModeU: \"clamp-to-edge\",\n addressModeV: \"clamp-to-edge\",\n addressModeW: \"clamp-to-edge\",\n};\n\n/** The lookup's grid (WGSL `VdbFrameMultiScale`; the CPU twin's `VDBFrameMultiScaleGrid` plus the base region). */\nexport interface VDBFrameMultiScaleParams {\n /** World box of the base region (his last cascade: gridMin, gridSize). */\n boxMin: readonly [number, number, number];\n boxSize: readonly [number, number, number];\n /** h: the grid's largest voxel side, world units. */\n unit: number;\n /** Levels read, base included (clamped in WGSL to the mips present + 1). */\n levels: number;\n /** 1 − g; 0 gives no scattered light. */\n multipleScattering: number;\n /** First texel of the base region in the base texture (default 0, 0, 0). */\n baseOrigin?: readonly [number, number, number];\n /** Base region texels per axis (the chain's `layout.size`). */\n baseSize: readonly [number, number, number];\n /**\n * K6.3a: level k of the lookup reads mip level min(k + levelOffset, the chain's mips) (default 0, his; 1 is the\n * paper's σ = 2^k, `multiScaleSigma: 'paper'`, with one more level in the chain).\n */\n levelOffset?: number;\n}\n\n/**\n * The 64 bytes of a WGSL `VdbFrameMultiScale` (into `target` at `byteOffset`, or a new buffer): boxMin, levels,\n * boxSize, unit, baseOrigin, multipleScattering, baseSize, levelOffset (K6.3a; was padding, 0 = unchanged).\n */\nexport function vdbFrameMultiScaleParams(p: VDBFrameMultiScaleParams, target: ArrayBuffer = new ArrayBuffer(VDB_FRAME_MULTI_SCALE_PARAMS_BYTES), byteOffset = 0): ArrayBuffer {\n const f = new Float32Array(target, byteOffset, 16);\n const u = new Uint32Array(target, byteOffset, 16);\n const o = p.baseOrigin ?? [0, 0, 0];\n for (let a = 0; a < 3; a++) {\n f[a] = p.boxMin[a]!;\n f[4 + a] = p.boxSize[a]!;\n f[8 + a] = o[a]!;\n f[12 + a] = p.baseSize[a]!;\n }\n u[3] = p.levels;\n f[7] = p.unit;\n f[11] = p.multipleScattering;\n u[15] = p.levelOffset ?? 0;\n return target;\n}\n\nconst MULTI_SCALE_STRUCT_WGSL = /* wgsl */ `\nstruct VdbFrameMultiScale {\n boxMin: vec3f,\n levels: u32,\n boxSize: vec3f,\n unit: f32,\n baseOrigin: vec3f,\n multipleScattering: f32,\n baseSize: vec3f,\n levelOffset: u32,\n};\n`;\n\n/**\n * K7.4a-3: the spectral lookup, the grey one (below) of each colour channel: two bases and two chains, one fetch of each\n * per point serving the three channels; the per-channel sums, depths and diffusion are the grey expressions on vec3s.\n */\nconst MULTI_SCALE_SPECTRAL_WGSL = /* wgsl */ `\n// (extinction rgb, absorption rgb) of a level at a world position\nstruct VdbFrameMultiScaleRgb {\n e: vec3f,\n a: vec3f,\n};\n\n// vdbFrameMultiScaleSample of each channel: 0 outside the box; level 0 the two bases (edges clamped), level k mip k - 1\n// of the two chains at base texel / 2^k\nfn vdbFrameMultiScaleSample3(baseE: texture_3d<f32>, baseA: texture_3d<f32>, mipsE: texture_3d<f32>, mipsA: texture_3d<f32>, smp: sampler, ms: VdbFrameMultiScale, level: u32, world: vec3f) -> VdbFrameMultiScaleRgb {\n let uvw = (world - ms.boxMin) / ms.boxSize;\n if any(uvw < vec3f(0.0)) || any(uvw > vec3f(1.0)) {\n return VdbFrameMultiScaleRgb(vec3f(0.0), vec3f(0.0));\n }\n let q = uvw * ms.baseSize;\n if level == 0u {\n let c = ms.baseOrigin + clamp(q, vec3f(0.5), ms.baseSize - vec3f(0.5));\n let p = c / vec3f(textureDimensions(baseE, 0u));\n return VdbFrameMultiScaleRgb(textureSampleLevel(baseE, smp, p, 0.0).xyz, textureSampleLevel(baseA, smp, p, 0.0).xyz);\n }\n let dims = vec3f(textureDimensions(mipsE, level - 1u));\n let p = q / (exp2(f32(level)) * dims);\n return VdbFrameMultiScaleRgb(textureSampleLevel(mipsE, smp, p, f32(level - 1u)).xyz, textureSampleLevel(mipsA, smp, p, f32(level - 1u)).xyz);\n}\n\n// vdbFrameMultiScaleLight of each channel: scattered light (total - direct) of a light slot\nfn vdbFrameMultiScaleLight3(baseE: texture_3d<f32>, baseA: texture_3d<f32>, mipsE: texture_3d<f32>, mipsA: texture_3d<f32>, smp: sampler, ms: VdbFrameMultiScale, world: vec3f, direction: vec3f, maxDistance: f32) -> vec3f {\n let h = ms.unit;\n let g = ms.multipleScattering;\n // Frisvad frame, pole at -y.\n let a = 1.0 / max(direction.y + 1.0, 1e-4);\n let b = -direction.x * direction.z * a;\n var u = vec3f(1.0 - direction.x * direction.x * a, -direction.x, b);\n var v = vec3f(b, -direction.z, 1.0 - direction.z * direction.z * a);\n if direction.y < -0.9999 {\n u = vec3f(1.0, 0.0, 0.0);\n v = vec3f(0.0, 0.0, 1.0);\n }\n // extinction, effective and reduced depths of each channel\n var dx = vec3f(0.0);\n var dy = vec3f(0.0);\n var dz = vec3f(0.0);\n let top = textureNumLevels(mipsE);\n let count = min(ms.levels, top + 1u);\n for (var k = 0u; k < count; k++) {\n let scale = h * exp2(f32(k));\n let start = scale - h;\n let segment = min(scale, maxDistance - start);\n if segment > 0.0 {\n let center = world + direction * (start + segment * 0.5);\n let read = min(k + ms.levelOffset, top);\n let s0 = vdbFrameMultiScaleSample3(baseE, baseA, mipsE, mipsA, smp, ms, read, center);\n let s1 = vdbFrameMultiScaleSample3(baseE, baseA, mipsE, mipsA, smp, ms, read, center + u * scale);\n let s2 = vdbFrameMultiScaleSample3(baseE, baseA, mipsE, mipsA, smp, ms, read, center - u * scale);\n let s3 = vdbFrameMultiScaleSample3(baseE, baseA, mipsE, mipsA, smp, ms, read, center + v * scale);\n let s4 = vdbFrameMultiScaleSample3(baseE, baseA, mipsE, mipsA, smp, ms, read, center - v * scale);\n let e = (s0.e + s1.e + s2.e + s3.e + s4.e) * 0.2;\n let absorbed = min((s0.a + s1.a + s2.a + s3.a + s4.a) * 0.2, e);\n let reduced = (e - absorbed) * g;\n dx += e * segment;\n dy += sqrt(absorbed * 3.0 * (absorbed + reduced)) * segment;\n dz += reduced * segment;\n }\n }\n var total = dx;\n if g > 0.0 {\n total = min(dx, dy + log(dz * 0.75 + vec3f(1.0)));\n }\n return max(exp(-total) - exp(-dx), vec3f(0.0));\n}\n`;\n\n/** Options of {@link vdbFrameMultiScaleWgsl}. */\nexport interface VDBFrameMultiScaleWgslOptions {\n /** Base texture components of extinction and absorption (default [0, 1]; one entry: no absorption). */\n baseChannels?: readonly number[];\n /** Components of the mip texture (default: as many as `baseChannels`; 1 reads no absorption). */\n mipChannels?: number;\n /**\n * K7.4a-3: the per-channel lookup of spectral media instead of the grey one: `vdbFrameMultiScaleSample3` /\n * `vdbFrameMultiScaleLight3` over two bases (extinction rgb, absorption rgb in xyz) and their two chains (made with\n * `channels: [0, 1, 2]`). Each channel runs the grey arithmetic in the grey order, so a grey medium gives the grey\n * lookup's value in every channel. `baseChannels` / `mipChannels` are ignored.\n */\n spectral?: boolean;\n}\n\nconst COMPONENTS = [\"x\", \"y\", \"z\", \"w\"];\n\n/**\n * The WGSL lookup of `'multi-scale'` multiple scattering, as text to paste into a host shader once (not part of\n * the VDB module, so module bytes and the size snapshot never move). Declares:\n *\n * struct VdbFrameMultiScale { boxMin: vec3f, levels: u32, boxSize: vec3f, unit: f32,\n * baseOrigin: vec3f, multipleScattering: f32, baseSize: vec3f, levelOffset: u32 }\n * fn vdbFrameMultiScaleSample(base: texture_3d<f32>, mips: texture_3d<f32>, smp: sampler,\n * ms: VdbFrameMultiScale, level: u32, world: vec3f) -> vec2f\n * fn vdbFrameMultiScaleLight(base: texture_3d<f32>, mips: texture_3d<f32>, smp: sampler,\n * ms: VdbFrameMultiScale, world: vec3f, direction: vec3f, maxDistance: f32) -> f32\n *\n * `base` is the host's grid texture (filterable float), `mips` the chain's `view`, `smp` a sampler made from\n * {@link VDB_FRAME_MULTI_SCALE_SAMPLER}; the host binds all three at its own slots and fills the struct with\n * {@link vdbFrameMultiScaleParams}. `vdbFrameMultiScaleLight` returns the scattered light (total − direct) for a\n * unit direction to the light; the caller adds its march's direct transmittance and clamps to 1. No derivatives\n * (`textureSampleLevel`), so it runs in compute and in non-uniform control flow. CPU twins:\n * `tools/frame/multi-scale.ts`. K7.4a-3 `spectral: true` declares the per-channel lookup instead,\n * `vdbFrameMultiScaleSample3` / `vdbFrameMultiScaleLight3(baseE, baseA, mipsE, mipsA, smp, ms, world, direction,\n * maxDistance) -> vec3f` over the extinction rgb and absorption rgb bases and their chains (twins\n * `vdbFrameMultiScaleSampleRgb` / `vdbFrameSpectralMultiScaleLight`).\n */\nexport function vdbFrameMultiScaleWgsl(options: VDBFrameMultiScaleWgslOptions = {}): string {\n if (options.spectral) return `${MULTI_SCALE_STRUCT_WGSL}${MULTI_SCALE_SPECTRAL_WGSL}`;\n const base = options.baseChannels ?? [0, 1];\n if (base.length < 1 || base.length > 2 || base.some((c) => !Number.isInteger(c) || c < 0 || c > 3)) {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbFrameMultiScaleWgsl: baseChannels must be 1 or 2 component indices from 0 to 3, got ${JSON.stringify(options.baseChannels)}.`);\n }\n const mipChannels = options.mipChannels ?? base.length;\n if (!Number.isInteger(mipChannels) || mipChannels < 1 || mipChannels > 4) {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbFrameMultiScaleWgsl: mipChannels must be 1 to 4, got ${JSON.stringify(options.mipChannels)}.`);\n }\n const baseValue = base.length > 1 ? `vec2f(s.${COMPONENTS[base[0]!]!}, s.${COMPONENTS[base[1]!]!})` : `vec2f(s.${COMPONENTS[base[0]!]!}, 0.0)`;\n const mipValue = mipChannels > 1 ? \"vec2f(s.x, s.y)\" : \"vec2f(s.x, 0.0)\";\n return /* wgsl */ `${MULTI_SCALE_STRUCT_WGSL}\n// (extinction, absorption) of a level at a world position: 0 outside the box; level 0 is the base region with\n// its edges clamped; level k is mip k - 1 at base texel / 2^k.\nfn vdbFrameMultiScaleSample(base: texture_3d<f32>, mips: texture_3d<f32>, smp: sampler, ms: VdbFrameMultiScale, level: u32, world: vec3f) -> vec2f {\n let uvw = (world - ms.boxMin) / ms.boxSize;\n if any(uvw < vec3f(0.0)) || any(uvw > vec3f(1.0)) {\n return vec2f(0.0);\n }\n let q = uvw * ms.baseSize;\n if level == 0u {\n let c = ms.baseOrigin + clamp(q, vec3f(0.5), ms.baseSize - vec3f(0.5));\n let s = textureSampleLevel(base, smp, c / vec3f(textureDimensions(base, 0u)), 0.0);\n return ${baseValue};\n }\n let dims = vec3f(textureDimensions(mips, level - 1u));\n let s = textureSampleLevel(mips, smp, q / (exp2(f32(level)) * dims), f32(level - 1u));\n return ${mipValue};\n}\n\n// Scattered light (total - direct) of a light slot: level k reads the bulk of the segment h (2^k - 1) to\n// h (2^(k+1) - 1) toward the light (5 points: the axis and +-h 2^k on two axes at right angles), the 1D diffusion\n// of the summed bulk gives total - its direct part (mjurczyk 4e2d46f, after Disney \"Deep Scattering\" 4.2). K6.3a:\n// the points read mip level min(k + levelOffset, mips): offset 1 blurs level k with sigma ~ 2^k voxels (the paper).\nfn vdbFrameMultiScaleLight(base: texture_3d<f32>, mips: texture_3d<f32>, smp: sampler, ms: VdbFrameMultiScale, world: vec3f, direction: vec3f, maxDistance: f32) -> f32 {\n let h = ms.unit;\n let g = ms.multipleScattering;\n // Frisvad frame, pole at -y.\n let a = 1.0 / max(direction.y + 1.0, 1e-4);\n let b = -direction.x * direction.z * a;\n var u = vec3f(1.0 - direction.x * direction.x * a, -direction.x, b);\n var v = vec3f(b, -direction.z, 1.0 - direction.z * direction.z * a);\n if direction.y < -0.9999 {\n u = vec3f(1.0, 0.0, 0.0);\n v = vec3f(0.0, 0.0, 1.0);\n }\n var depths = vec3f(0.0);\n let top = textureNumLevels(mips);\n let count = min(ms.levels, top + 1u);\n for (var k = 0u; k < count; k++) {\n let scale = h * exp2(f32(k));\n let start = scale - h;\n let segment = min(scale, maxDistance - start);\n if segment > 0.0 {\n let center = world + direction * (start + segment * 0.5);\n let read = min(k + ms.levelOffset, top);\n let bulk = (vdbFrameMultiScaleSample(base, mips, smp, ms, read, center)\n + vdbFrameMultiScaleSample(base, mips, smp, ms, read, center + u * scale)\n + vdbFrameMultiScaleSample(base, mips, smp, ms, read, center - u * scale)\n + vdbFrameMultiScaleSample(base, mips, smp, ms, read, center + v * scale)\n + vdbFrameMultiScaleSample(base, mips, smp, ms, read, center - v * scale)) * 0.2;\n let absorbed = min(bulk.y, bulk.x);\n let reduced = (bulk.x - absorbed) * g;\n depths += vec3f(bulk.x, sqrt(absorbed * 3.0 * (absorbed + reduced)), reduced) * segment;\n }\n }\n var total = depths.x;\n if g > 0.0 {\n total = min(depths.x, depths.y + log(depths.z * 0.75 + 1.0));\n }\n return max(exp(-total) - exp(-depths.x), 0.0);\n}\n`;\n}\n"]}
|
|
@@ -36,7 +36,7 @@ export declare function boxPyramidWgsl(type: VDBGridTypeName): string;
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function warmBoxPyramidPipelines(device: GPUDevice, types: Iterable<VDBGridTypeName>): Promise<GPUError | null>[];
|
|
38
38
|
/** Options of {@link vdbCreateBoxPyramid}. */
|
|
39
|
-
export interface
|
|
39
|
+
export interface VDBBoxPyramidOptions {
|
|
40
40
|
/** Inclusive voxel index box the pyramid covers. Default: the grid's index bbox now (fixed afterwards). */
|
|
41
41
|
indexBox?: {
|
|
42
42
|
min: VDBVec3;
|
|
@@ -47,24 +47,31 @@ export interface VDBBoxPyramidGpuOptions {
|
|
|
47
47
|
/** Base level override (default `vdbPyramidBaseLevel`). */
|
|
48
48
|
level?: number;
|
|
49
49
|
/**
|
|
50
|
-
* Write into these r16float textures (`COPY_DST
|
|
51
|
-
*
|
|
52
|
-
* `
|
|
50
|
+
* Write into these r16float textures (`COPY_DST`; `atlas` null exactly when the layout has no atlas)
|
|
51
|
+
* instead of allocating. The pyramid never destroys them (a three texture's `GPUTexture`, for example).
|
|
52
|
+
* Without origins they must have the layout's sizes; with `baseOrigin` / `atlasOrigin` (K6.7: the core
|
|
53
|
+
* sparse source packs every volume's pyramid into one texture) the block at the origin must fit, and
|
|
54
|
+
* `base` and `atlas` may be the same texture.
|
|
53
55
|
*/
|
|
54
56
|
targets?: {
|
|
55
57
|
base: GPUTexture;
|
|
56
58
|
atlas: GPUTexture | null;
|
|
59
|
+
baseOrigin?: VDBVec3;
|
|
60
|
+
atlasOrigin?: VDBVec3;
|
|
57
61
|
};
|
|
62
|
+
/** Debug label of the GPU objects. */
|
|
58
63
|
label?: string;
|
|
59
64
|
}
|
|
60
|
-
/** Options of {@link
|
|
65
|
+
/** Options of {@link VDBBoxPyramid.record}. */
|
|
61
66
|
export interface VDBBoxPyramidRecordOptions {
|
|
62
67
|
/** Timestamps around the build's one compute pass (the `timestamp-query` feature). */
|
|
63
68
|
timestampWrites?: GPUComputePassTimestampWrites;
|
|
64
69
|
}
|
|
65
70
|
/** A coarse pyramid on the GPU (see the file comment). */
|
|
66
|
-
export interface
|
|
71
|
+
export interface VDBBoxPyramid {
|
|
72
|
+
/** The pool id of the grid the pyramid is built from. */
|
|
67
73
|
readonly gridId: number;
|
|
74
|
+
/** The sizes and level layout of the textures. */
|
|
68
75
|
readonly layout: VDBBoxPyramidLayout;
|
|
69
76
|
/** r16float, the base level (`layout.dimensions`). */
|
|
70
77
|
readonly base: GPUTexture;
|
|
@@ -84,6 +91,9 @@ export interface VDBBoxPyramidGpu {
|
|
|
84
91
|
/**
|
|
85
92
|
* Records a (re)build into `encoder`. The grid must be resident (`pool.update(encoder)` recorded
|
|
86
93
|
* earlier in this encoder or submitted before); call after the pool's update, as for bind groups.
|
|
94
|
+
*
|
|
95
|
+
* @param encoder The encoder the build is recorded into; the host submits it.
|
|
96
|
+
* @param options Timestamp writes for the build pass.
|
|
87
97
|
*/
|
|
88
98
|
record(encoder: GPUCommandEncoder, options?: VDBBoxPyramidRecordOptions): void;
|
|
89
99
|
/** Records a rebuild when {@link stale} and the grid is resident; returns whether it did. */
|
|
@@ -101,5 +111,10 @@ export interface VDBBoxPyramidGpu {
|
|
|
101
111
|
* pool.update(encoder);
|
|
102
112
|
* pyramid.update(encoder); // first build, then only on a replace
|
|
103
113
|
* device.queue.submit([encoder.finish()]);
|
|
114
|
+
*
|
|
115
|
+
* @param device The host's `GPUDevice`; the pool must live on it.
|
|
116
|
+
* @param pool The pool that holds the grid.
|
|
117
|
+
* @param gridId The grid's pool id.
|
|
118
|
+
* @param options Index box, size cap, level, target textures and label ({@link VDBBoxPyramidOptions}).
|
|
104
119
|
*/
|
|
105
|
-
export declare function vdbCreateBoxPyramid(device: GPUDevice, pool: VDBGridPool, gridId: number, options?:
|
|
120
|
+
export declare function vdbCreateBoxPyramid(device: GPUDevice, pool: VDBGridPool, gridId: number, options?: VDBBoxPyramidOptions): VDBBoxPyramid;
|
|
@@ -243,7 +243,7 @@ const align = (n, a) => Math.ceil(n / a) * a;
|
|
|
243
243
|
const bad = (message) => {
|
|
244
244
|
throw new VDBError("VDB_BAD_OPTION", `vdbCreateBoxPyramid: ${message}`);
|
|
245
245
|
};
|
|
246
|
-
class
|
|
246
|
+
class BoxPyramid {
|
|
247
247
|
gridId;
|
|
248
248
|
layout;
|
|
249
249
|
base;
|
|
@@ -262,6 +262,8 @@ class BoxPyramidGpu {
|
|
|
262
262
|
#params;
|
|
263
263
|
#rows;
|
|
264
264
|
#blocks;
|
|
265
|
+
/** Where the base and the atlas land in their textures (K6.7 packing; 0 otherwise). */
|
|
266
|
+
#origins = { base: [0, 0, 0], atlas: [0, 0, 0] };
|
|
265
267
|
#group1 = null;
|
|
266
268
|
#destroyed = false;
|
|
267
269
|
constructor(device, pool, gridId, o) {
|
|
@@ -287,7 +289,7 @@ class BoxPyramidGpu {
|
|
|
287
289
|
const baseCount = dims[0] * dims[1] * dims[2];
|
|
288
290
|
const atlasCount = atlas ? atlas.dimensions[0] * atlas.dimensions[1] * atlas.dimensions[2] : 0;
|
|
289
291
|
if (o.targets) {
|
|
290
|
-
const check = (t, want, what) => {
|
|
292
|
+
const check = (t, want, origin, what) => {
|
|
291
293
|
if (!want) {
|
|
292
294
|
if (t)
|
|
293
295
|
bad(`targets.${what} must be null: the layout has no ${what}.`);
|
|
@@ -295,12 +297,18 @@ class BoxPyramidGpu {
|
|
|
295
297
|
}
|
|
296
298
|
if (!t)
|
|
297
299
|
return bad(`targets.${what} is missing (the layout has one, ${want.join("x")}).`);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
+
const size = [t.width, t.height, t.depthOrArrayLayers];
|
|
301
|
+
const fits = origin
|
|
302
|
+
? origin.every((v, a) => Number.isInteger(v) && v >= 0 && v + want[a] <= size[a])
|
|
303
|
+
: size.every((v, a) => v === want[a]);
|
|
304
|
+
if (t.format !== "r16float" || !fits || (t.usage & TEXTURE_USAGE.COPY_DST) === 0) {
|
|
305
|
+
const where = origin ? ` holding ${want.join("x")} at ${origin.join(",")}` : ` of ${want.join("x")}`;
|
|
306
|
+
bad(`targets.${what} must be an r16float 3D texture${where} with COPY_DST (got ${t.format} ${t.width}x${t.height}x${t.depthOrArrayLayers}, usage ${t.usage}).`);
|
|
300
307
|
}
|
|
301
308
|
};
|
|
302
|
-
check(o.targets.base, dims, "base");
|
|
303
|
-
check(o.targets.atlas, atlas?.dimensions ?? null, "atlas");
|
|
309
|
+
check(o.targets.base, dims, o.targets.baseOrigin, "base");
|
|
310
|
+
check(o.targets.atlas, atlas?.dimensions ?? null, o.targets.atlasOrigin, "atlas");
|
|
311
|
+
this.#origins = { base: o.targets.baseOrigin ?? [0, 0, 0], atlas: o.targets.atlasOrigin ?? [0, 0, 0] };
|
|
304
312
|
this.base = o.targets.base;
|
|
305
313
|
this.atlas = o.targets.atlas;
|
|
306
314
|
}
|
|
@@ -414,10 +422,10 @@ class BoxPyramidGpu {
|
|
|
414
422
|
if (atlas)
|
|
415
423
|
dispatch(p.pack, 2, [Math.ceil(atlas.dimensions[0] / 2), atlas.dimensions[1], atlas.dimensions[2]]);
|
|
416
424
|
pass.end();
|
|
417
|
-
encoder.copyBufferToTexture({ buffer: this.#packed, offset: 0, bytesPerRow: this.#rows.base * 4, rowsPerImage: dims[1] }, { texture: this.base }, [dims[0], dims[1], dims[2]]);
|
|
425
|
+
encoder.copyBufferToTexture({ buffer: this.#packed, offset: 0, bytesPerRow: this.#rows.base * 4, rowsPerImage: dims[1] }, { texture: this.base, origin: this.#origins.base }, [dims[0], dims[1], dims[2]]);
|
|
418
426
|
if (atlas && this.atlas) {
|
|
419
427
|
const [aw, ah, ad] = atlas.dimensions;
|
|
420
|
-
encoder.copyBufferToTexture({ buffer: this.#packed, offset: this.#rows.atlasOffset * 4, bytesPerRow: this.#rows.atlas * 4, rowsPerImage: ah }, { texture: this.atlas }, [aw, ah, ad]);
|
|
428
|
+
encoder.copyBufferToTexture({ buffer: this.#packed, offset: this.#rows.atlasOffset * 4, bytesPerRow: this.#rows.atlas * 4, rowsPerImage: ah }, { texture: this.atlas, origin: this.#origins.atlas }, [aw, ah, ad]);
|
|
421
429
|
}
|
|
422
430
|
this.builtRevision = info.imageRevision;
|
|
423
431
|
}
|
|
@@ -448,8 +456,13 @@ class BoxPyramidGpu {
|
|
|
448
456
|
* pool.update(encoder);
|
|
449
457
|
* pyramid.update(encoder); // first build, then only on a replace
|
|
450
458
|
* device.queue.submit([encoder.finish()]);
|
|
459
|
+
*
|
|
460
|
+
* @param device The host's `GPUDevice`; the pool must live on it.
|
|
461
|
+
* @param pool The pool that holds the grid.
|
|
462
|
+
* @param gridId The grid's pool id.
|
|
463
|
+
* @param options Index box, size cap, level, target textures and label ({@link VDBBoxPyramidOptions}).
|
|
451
464
|
*/
|
|
452
465
|
export function vdbCreateBoxPyramid(device, pool, gridId, options = {}) {
|
|
453
|
-
return new
|
|
466
|
+
return new BoxPyramid(device, pool, gridId, options);
|
|
454
467
|
}
|
|
455
468
|
//# sourceMappingURL=pyramid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pyramid.js","sourceRoot":"","sources":["../../../src/core/compute/pyramid.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,mGAAmG;AACnG,yDAAyD;AACzD,4GAA4G;AAC5G,2FAA2F;AAC3F,2GAA2G;AA8B3G,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAA4B,MAAM,qCAAqC,CAAC;AAEpG,MAAM,CAAC,GAAG,cAAc,CAAC;AACzB,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,aAAa,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,EAAW,CAAC;AACtF,uEAAuE;AACvE,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,YAAY,G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js L14–106 (2x2x2 box downsample with clamped edge\n// taps, the mip atlas layout), as an f32 compute pass.\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: GPU compute over a pool grid; the base level is the area-weighted box filter of\n// `vdbResampleGrid`; f16 packing is three's `DataUtils.toHalfFloat`. Divergences: DIVERGES.md (K3.2a row).\n\n/**\n * `vdbCreateBoxPyramid` (K3.2a): the sparse source's coarse pyramid (K3.2 `'coarse-pyramid'`) built on\n * the GPU from a pool grid, recorded into the host's encoder. CPU twin: `@pmndrs/vdb/tools`\n * `vdbBoxPyramid` + three's `DataUtils.toHalfFloat` (the K3.2 CPU path); parity ≤ 1 f16 ulp\n * (e2e/k3-pyramid.spec.ts).\n *\n * Passes, one compute pass (dispatches see each other's writes):\n * 1. **base** (one thread per base texel): the area-weighted box mean of the grid's voxels over the\n * texel's cell, `vdbResampleGrid`'s `'box'` filter on the index cell box `[min − ½, max + ½]` with\n * `⌈texels / 2^L₀⌉` texels. Overlaps are exact integers in units of 1/dims voxel (no f32 rounding\n * of the footprint), summed separably x → y → z in the CPU's order. A texel whose taps touch an\n * active voxel flags its 8³ texel block (atomicOr). A texel whose footprint lies in inactive\n * zero tiles only (no leaf: `vdbGetDim` > 1) is 0 without the voxel loop, as on the CPU.\n * 2. **mask**: texels of an unflagged block become 0 (the CPU path drops leaves with no active voxel,\n * and its dense readout fills them with 0).\n * 3. **levels**: his 2x2x2 box mips with clamped edge taps, level by level, into his atlas layout\n * (`vdbBoxPyramidLayout`), from the f32 base (not the f16 one, as the CPU).\n * 4. **pack**: f32 → f16 (three's `toHalfFloat`: truncation, its denormal and overflow tables) into\n * 256-byte rows, then `copyBufferToTexture` into the r16float base and atlas textures.\n *\n * The textures are the pyramid's own (`TEXTURE_BINDING | COPY_DST | COPY_SRC`) or, with `targets`,\n * the host's (a three texture's `GPUTexture`): r16float, `COPY_DST`, the layout's sizes; then the\n * pyramid never destroys them. Scratch buffers (f32 levels, block flags, the packed rows, parameters)\n * stay alive for rebuilds (a sequence replaces the grid every frame) until `destroy()`.\n */\nimport type { VDBGridPool } from \"../pool/pool.js\";\nimport type { VDBVec3 } from \"../pool/layout.js\";\nimport type { VDBGridTypeName } from \"../types.js\";\nimport { VDBError } from \"../errors.js\";\nimport { vdbModuleEntries, vdbModuleWgsl } from \"../wgsl/generate.js\";\nimport { checkTarget, COMPUTE_SLOT, USAGE, WORKGROUP_AXIS } from \"./shared.js\";\nimport { vdbBoxPyramidLayout, type VDBBoxPyramidLayout } from \"../../tools/frame/pyramid-layout.js\";\n\nconst W = WORKGROUP_AXIS;\nconst STAGE_COMPUTE = 0x4;\nconst TEXTURE_USAGE = { COPY_SRC: 0x1, COPY_DST: 0x2, TEXTURE_BINDING: 0x4 } as const;\n/** Uniform slot stride (minUniformBufferOffsetAlignment's default). */\nconst SLOT = 256;\nconst PARAMS_BYTES = 96;\n\nconst PARAMS_WGSL = /* wgsl */ `\nstruct PyrParams {\n grid: u32,\n srcFromBase: u32,\n srcOffset: u32,\n dstOffset: u32,\n boxMin: vec3i,\n rowWords: u32,\n texels: vec3u,\n blocksX: u32,\n dims: vec3u,\n blocksY: u32,\n srcDims: vec3u,\n pad1: u32,\n atlasDims: vec3u,\n pad2: u32,\n};\n@group(0) @binding(1) var<uniform> pyr: PyrParams;\n@group(1) @binding(0) var<storage, read_write> pyrBase: array<f32>;\n@group(1) @binding(1) var<storage, read_write> pyrAtlas: array<f32>;\n@group(1) @binding(2) var<storage, read_write> pyrFlags: array<atomic<u32>>;\n@group(1) @binding(3) var<storage, read_write> pyrPacked: array<u32>;\n`;\n\nconst KERNELS_WGSL = /* wgsl */ `\nfn pyrBlock(j: vec3u) -> u32 {\n let b = j >> vec3u(3u);\n return b.x + (b.y + b.z * pyr.blocksY) * pyr.blocksX;\n}\n\n// Box filter of the voxels under texel j (vdbResampleGrid 'box'): texel j covers [j·T, (j+1)·T] and voxel\n// r covers [r·D, (r+1)·D] in units of 1/D voxel (T texels of the box, D base texels), so overlaps are\n// exact integers and the weights ov / T. Summed x, then y, then z, in the CPU's order.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrBase(@builtin(global_invocation_id) j: vec3u) {\n let D = pyr.dims;\n if any(j >= D) {\n return;\n }\n let T = pyr.texels;\n let b0 = j * T;\n let b1 = b0 + T;\n let r0 = b0 / D;\n let r1 = (b1 + D - vec3u(1u)) / D - vec3u(1u);\n let tf = vec3f(T);\n var acc = vdbAccessorInit(pyr.grid);\n // Empty space: when every 8³ cell under the footprint is an inactive tile of value 0 (no leaf), the CPU\n // sum is exactly 0 with no active tap. Skips the voxel loop for most texels of a sparse cloud.\n let c0 = (pyr.boxMin + vec3i(r0)) >> vec3u(3u);\n let c1 = (pyr.boxMin + vec3i(r1)) >> vec3u(3u);\n var empty = true;\n for (var cz = c0.z; cz <= c1.z && empty; cz++) {\n for (var cy = c0.y; cy <= c1.y && empty; cy++) {\n for (var cx = c0.x; cx <= c1.x && empty; cx++) {\n let c = vec3i(cx, cy, cz) * 8;\n empty = vdbGetDim(&acc, c) > 1u && vdbReadValue(&acc, c) == 0.0 && !vdbIsActive(&acc, c);\n }\n }\n }\n if empty {\n pyrBase[j.x + (j.y + j.z * D.y) * D.x] = 0.0;\n return;\n }\n var touched = false;\n var sz = 0.0;\n for (var z = r0.z; z <= r1.z; z++) {\n let wz = f32(min(b1.z, (z + 1u) * D.z) - max(b0.z, z * D.z)) / tf.z;\n var sy = 0.0;\n for (var y = r0.y; y <= r1.y; y++) {\n let wy = f32(min(b1.y, (y + 1u) * D.y) - max(b0.y, y * D.y)) / tf.y;\n var sx = 0.0;\n for (var x = r0.x; x <= r1.x; x++) {\n let wx = f32(min(b1.x, (x + 1u) * D.x) - max(b0.x, x * D.x)) / tf.x;\n let ijk = pyr.boxMin + vec3i(vec3u(x, y, z));\n sx += wx * vdbReadValue(&acc, ijk);\n touched = touched || vdbIsActive(&acc, ijk);\n }\n sy += wy * sx;\n }\n sz += wz * sy;\n }\n pyrBase[j.x + (j.y + j.z * D.y) * D.x] = sz;\n if touched {\n atomicOr(&pyrFlags[pyrBlock(j)], 1u);\n }\n}\n\n// Texels of an 8³ block with no active tap read 0 (the CPU drops that leaf; its readout fills 0).\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrMask(@builtin(global_invocation_id) j: vec3u) {\n let D = pyr.dims;\n if any(j >= D) {\n return;\n }\n if atomicLoad(&pyrFlags[pyrBlock(j)]) == 0u {\n pyrBase[j.x + (j.y + j.z * D.y) * D.x] = 0.0;\n }\n}\n\nfn pyrSrc(x: u32, y: u32, z: u32) -> f32 {\n if pyr.srcFromBase != 0u {\n return pyrBase[x + (y + z * pyr.srcDims.y) * pyr.srcDims.x];\n }\n return pyrAtlas[pyr.srcOffset + x + (y + z * pyr.atlasDims.y) * pyr.atlasDims.x];\n}\n\n// His downsample (frameMipmaps.js): the 2x2x2 mean with edge taps clamped, into the atlas at dstOffset.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrLevel(@builtin(global_invocation_id) p: vec3u) {\n if any(p >= pyr.dims) {\n return;\n }\n let s = pyr.srcDims - vec3u(1u);\n let x0 = min(p.x * 2u, s.x);\n let x1 = min(p.x * 2u + 1u, s.x);\n let y0 = min(p.y * 2u, s.y);\n let y1 = min(p.y * 2u + 1u, s.y);\n let z0 = min(p.z * 2u, s.z);\n let z1 = min(p.z * 2u + 1u, s.z);\n let sum = pyrSrc(x0, y0, z0) + pyrSrc(x1, y0, z0) + pyrSrc(x0, y1, z0) + pyrSrc(x1, y1, z0)\n + pyrSrc(x0, y0, z1) + pyrSrc(x1, y0, z1) + pyrSrc(x0, y1, z1) + pyrSrc(x1, y1, z1);\n pyrAtlas[pyr.dstOffset + p.x + (p.y + p.z * pyr.atlasDims.y) * pyr.atlasDims.x] = sum / 8.0;\n}\n\n// three's DataUtils.toHalfFloat (fox-toolkit tables: truncation, denormals, overflow to infinity).\nfn pyrHalf(v: f32) -> u32 {\n let f = bitcast<u32>(clamp(v, -65504.0, 65504.0));\n let e = i32((f >> 23u) & 0xffu) - 127;\n var base = 0u;\n var shift = 24u;\n if e < -27 {\n base = 0u;\n shift = 24u;\n } else if e < -14 {\n base = 0x400u >> u32(-e - 14);\n shift = u32(-e - 1);\n } else if e <= 15 {\n base = u32(e + 15) << 10u;\n shift = 13u;\n } else if e < 128 {\n base = 0x7c00u;\n shift = 24u;\n } else {\n base = 0x7c00u;\n shift = 13u;\n }\n if (f & 0x80000000u) != 0u {\n base = base | 0x8000u;\n }\n return base + ((f & 0x7fffffu) >> shift);\n}\n\n// Two texels per word, rows of rowWords words (bytesPerRow multiple of 256), at dstOffset words.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrPack(@builtin(global_invocation_id) p: vec3u) {\n let size = pyr.srcDims;\n let words = (size.x + 1u) / 2u;\n if p.x >= words || p.y >= size.y || p.z >= size.z {\n return;\n }\n let x = p.x * 2u;\n var lo = 0u;\n var hi = 0u;\n if pyr.srcFromBase != 0u {\n let row = (p.y + p.z * size.y) * size.x;\n lo = pyrHalf(pyrBase[row + x]);\n if x + 1u < size.x {\n hi = pyrHalf(pyrBase[row + x + 1u]);\n }\n } else {\n let row = (p.y + p.z * size.y) * size.x;\n lo = pyrHalf(pyrAtlas[row + x]);\n if x + 1u < size.x {\n hi = pyrHalf(pyrAtlas[row + x + 1u]);\n }\n }\n pyrPacked[pyr.dstOffset + (p.y + p.z * size.y) * pyr.rowWords + p.x] = lo | (hi << 16u);\n}\n`;\n\n/** The WGSL of the pyramid kernels for grids of `type` (exported for tests and the size of the shader). */\nexport function boxPyramidWgsl(type: VDBGridTypeName): string {\n return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types: [type], profile: \"march\" })}\\n${PARAMS_WGSL}\\n${KERNELS_WGSL}`;\n}\n\ninterface PyramidPipelines {\n base: GPUComputePipeline;\n mask: GPUComputePipeline;\n level: GPUComputePipeline;\n pack: GPUComputePipeline;\n group0: GPUBindGroupLayout;\n group1: GPUBindGroupLayout;\n error: Promise<GPUError | null>;\n}\n\nconst pipelines = new WeakMap<GPUDevice, Map<VDBGridTypeName, PyramidPipelines>>();\n\nfunction pyramidPipelines(device: GPUDevice, type: VDBGridTypeName): PyramidPipelines {\n let byType = pipelines.get(device);\n if (!byType) pipelines.set(device, (byType = new Map()));\n const cached = byType.get(type);\n if (cached) return cached;\n device.pushErrorScope(\"validation\");\n const group0 = device.createBindGroupLayout({\n label: `vdb boxPyramid ${type} group 0`,\n entries: [\n ...vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }),\n { binding: 1, visibility: STAGE_COMPUTE, buffer: { type: \"uniform\", hasDynamicOffset: true, minBindingSize: PARAMS_BYTES } },\n ],\n });\n const group1 = device.createBindGroupLayout({\n label: `vdb boxPyramid ${type} group 1`,\n entries: [0, 1, 2, 3].map((binding) => ({ binding, visibility: STAGE_COMPUTE, buffer: { type: \"storage\" as const } })),\n });\n const module = device.createShaderModule({ label: `vdb boxPyramid ${type}`, code: boxPyramidWgsl(type) });\n const layout = device.createPipelineLayout({ bindGroupLayouts: [group0, group1] });\n const make = (entryPoint: string) => device.createComputePipeline({ label: `vdb boxPyramid ${entryPoint} ${type}`, layout, compute: { module, entryPoint } });\n const p: PyramidPipelines = {\n base: make(\"csPyrBase\"),\n mask: make(\"csPyrMask\"),\n level: make(\"csPyrLevel\"),\n pack: make(\"csPyrPack\"),\n group0,\n group1,\n error: device.popErrorScope(),\n };\n byType.set(type, p);\n return p;\n}\n\n/**\n * @internal Compiles (once per device and type, cached) the pyramid pipelines for grids of `types`, so a later\n * pyramid over a grid of one of them (G16a: a sparse source following a coarse-first swap to another grid type)\n * creates no pipeline. Returns the pipelines' validation results.\n */\nexport function warmBoxPyramidPipelines(device: GPUDevice, types: Iterable<VDBGridTypeName>): Promise<GPUError | null>[] {\n return [...types].map((type) => pyramidPipelines(device, type).error);\n}\n\n/** Options of {@link vdbCreateBoxPyramid}. */\nexport interface VDBBoxPyramidGpuOptions {\n /** Inclusive voxel index box the pyramid covers. Default: the grid's index bbox now (fixed afterwards). */\n indexBox?: { min: VDBVec3; max: VDBVec3 };\n /** Texels on the longest side of the base level at most (default 128). */\n pyramidMax?: number;\n /** Base level override (default `vdbPyramidBaseLevel`). */\n level?: number;\n /**\n * Write into these r16float textures (`COPY_DST`, the layout's sizes; `atlas` null exactly when the\n * layout has no atlas) instead of allocating. The pyramid never destroys them (a three texture's\n * `GPUTexture`, for example).\n */\n targets?: { base: GPUTexture; atlas: GPUTexture | null };\n label?: string;\n}\n\n/** Options of {@link VDBBoxPyramidGpu.record}. */\nexport interface VDBBoxPyramidRecordOptions {\n /** Timestamps around the build's one compute pass (the `timestamp-query` feature). */\n timestampWrites?: GPUComputePassTimestampWrites;\n}\n\n/** A coarse pyramid on the GPU (see the file comment). */\nexport interface VDBBoxPyramidGpu {\n readonly gridId: number;\n readonly layout: VDBBoxPyramidLayout;\n /** r16float, the base level (`layout.dimensions`). */\n readonly base: GPUTexture;\n /** r16float, his atlas of the levels above (`layout.atlas.dimensions`), or null. */\n readonly atlas: GPUTexture | null;\n /** Bytes: `textures` (r16f; counted whoever owns them) and `scratch` (this pyramid's buffers). */\n readonly gpuBytes: { readonly textures: number; readonly scratch: number };\n /** The grid's `imageRevision` the last recorded build read, or null before the first. */\n readonly builtRevision: number | null;\n /** True when the grid's image changed since the last recorded build (or none was recorded). */\n readonly stale: boolean;\n /** Pipeline validation (null = valid); the first build's errors surface here. */\n readonly error: Promise<GPUError | null>;\n /**\n * Records a (re)build into `encoder`. The grid must be resident (`pool.update(encoder)` recorded\n * earlier in this encoder or submitted before); call after the pool's update, as for bind groups.\n */\n record(encoder: GPUCommandEncoder, options?: VDBBoxPyramidRecordOptions): void;\n /** Records a rebuild when {@link stale} and the grid is resident; returns whether it did. */\n update(encoder: GPUCommandEncoder): boolean;\n /** Frees the scratch buffers and the textures this pyramid allocated (not `targets`). Idempotent. */\n destroy(): void;\n}\n\nconst align = (n: number, a: number) => Math.ceil(n / a) * a;\nconst bad = (message: string): never => {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbCreateBoxPyramid: ${message}`);\n};\n\nclass BoxPyramidGpu implements VDBBoxPyramidGpu {\n readonly gridId: number;\n readonly layout: VDBBoxPyramidLayout;\n readonly base: GPUTexture;\n readonly atlas: GPUTexture | null;\n readonly gpuBytes: { textures: number; scratch: number };\n builtRevision: number | null = null;\n error: Promise<GPUError | null>;\n readonly #device: GPUDevice;\n readonly #pool: VDBGridPool;\n readonly #boxMin: VDBVec3;\n readonly #owned: (GPUBuffer | GPUTexture)[] = [];\n readonly #baseF32: GPUBuffer;\n readonly #atlasF32: GPUBuffer;\n readonly #flags: GPUBuffer;\n readonly #packed: GPUBuffer;\n readonly #params: GPUBuffer;\n readonly #rows: { base: number; atlas: number; atlasOffset: number };\n readonly #blocks: [number, number, number];\n #group1: GPUBindGroup | null = null;\n #destroyed = false;\n\n constructor(device: GPUDevice, pool: VDBGridPool, gridId: number, o: VDBBoxPyramidGpuOptions) {\n if (!device || typeof (device as { createBuffer?: unknown }).createBuffer !== \"function\") bad(\"expected a GPUDevice as the first argument.\");\n if (!pool || typeof (pool as { info?: unknown }).info !== \"function\") bad(\"expected a VDBGridPool as the second argument.\");\n if (pool.device !== device) bad(\"the pool lives on a different GPUDevice. Pass pool.device.\");\n // Residency is checked when a build is recorded; creating needs only the grid's info.\n const info = pool.info(gridId);\n const box = o.indexBox ?? info.indexBBox;\n const texels = [0, 1, 2].map((a) => box.max[a]! - box.min[a]! + 1);\n if (texels.some((t) => !(t > 0) || !Number.isInteger(t))) bad(`empty or non-integer index box ${JSON.stringify(box)}.`);\n this.layout = vdbBoxPyramidLayout(texels, { ...(o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {}), ...(o.level !== undefined ? { level: o.level } : {}) });\n this.#device = device;\n this.#pool = pool;\n this.gridId = gridId;\n this.#boxMin = [box.min[0], box.min[1], box.min[2]];\n const label = o.label ?? `vdb boxPyramid grid ${gridId}`;\n const { dimensions: dims, atlas } = this.layout;\n const baseCount = dims[0] * dims[1] * dims[2];\n const atlasCount = atlas ? atlas.dimensions[0] * atlas.dimensions[1] * atlas.dimensions[2] : 0;\n\n if (o.targets) {\n const check = (t: GPUTexture | null, want: readonly number[] | null, what: string) => {\n if (!want) {\n if (t) bad(`targets.${what} must be null: the layout has no ${what}.`);\n return;\n }\n if (!t) return bad(`targets.${what} is missing (the layout has one, ${want.join(\"x\")}).`);\n if (t.format !== \"r16float\" || t.width !== want[0] || t.height !== want[1] || t.depthOrArrayLayers !== want[2] || (t.usage & TEXTURE_USAGE.COPY_DST) === 0) {\n bad(`targets.${what} must be an r16float 3D texture of ${want.join(\"x\")} with COPY_DST (got ${t.format} ${t.width}x${t.height}x${t.depthOrArrayLayers}, usage ${t.usage}).`);\n }\n };\n check(o.targets.base, dims, \"base\");\n check(o.targets.atlas, atlas?.dimensions ?? null, \"atlas\");\n this.base = o.targets.base;\n this.atlas = o.targets.atlas;\n } else {\n const texture = (size: readonly number[], what: string) => {\n const t = device.createTexture({\n label: `${label} ${what}`,\n size: [size[0]!, size[1]!, size[2]!],\n dimension: \"3d\",\n format: \"r16float\",\n usage: TEXTURE_USAGE.TEXTURE_BINDING | TEXTURE_USAGE.COPY_DST | TEXTURE_USAGE.COPY_SRC,\n });\n this.#owned.push(t);\n return t;\n };\n this.base = texture(dims, \"base\");\n this.atlas = atlas ? texture(atlas.dimensions, \"atlas\") : null;\n }\n\n const rowWords = (w: number) => align(w * 2, 256) / 4;\n const baseWords = rowWords(dims[0]) * dims[1] * dims[2];\n const atlasWords = atlas ? rowWords(atlas.dimensions[0]) * atlas.dimensions[1] * atlas.dimensions[2] : 0;\n this.#rows = { base: rowWords(dims[0]), atlas: atlas ? rowWords(atlas.dimensions[0]) : 0, atlasOffset: align(baseWords, 64) };\n this.#blocks = [Math.ceil(dims[0] / 8), Math.ceil(dims[1] / 8), Math.ceil(dims[2] / 8)];\n const buffer = (size: number, usage: number, what: string) => {\n const b = device.createBuffer({ label: `${label} ${what}`, size: align(Math.max(4, size), 4), usage });\n this.#owned.push(b);\n return b;\n };\n this.#baseF32 = buffer(baseCount * 4, USAGE.STORAGE, \"base f32\");\n this.#atlasF32 = buffer(atlasCount * 4, USAGE.STORAGE | USAGE.COPY_DST, \"atlas f32\");\n this.#flags = buffer(this.#blocks[0] * this.#blocks[1] * this.#blocks[2] * 4, USAGE.STORAGE | USAGE.COPY_DST, \"block flags\");\n this.#packed = buffer((this.#rows.atlasOffset + atlasWords) * 4, USAGE.STORAGE | USAGE.COPY_SRC, \"packed f16\");\n const slots = 4 + (atlas?.levels.length ?? 0);\n this.#params = buffer(slots * SLOT, USAGE.UNIFORM | USAGE.COPY_DST, \"params\");\n this.gpuBytes = {\n textures: 2 * (baseCount + atlasCount),\n scratch: [this.#baseF32, this.#atlasF32, this.#flags, this.#packed, this.#params].reduce((s, b) => s + b.size, 0),\n };\n this.error = pyramidPipelines(device, info.type).error;\n this.#writeParams();\n }\n\n get stale(): boolean {\n if (this.#destroyed) return false;\n return this.builtRevision === null || this.#pool.info(this.gridId).imageRevision !== this.builtRevision;\n }\n\n /** Per-dispatch parameter slots: 0 base/mask, 1 pack base, 2 pack atlas, 3.. levels. */\n #writeParams(): void {\n const { dimensions: dims, atlas, texels } = this.layout;\n const slots = 4 + (atlas?.levels.length ?? 0);\n const bytes = new ArrayBuffer(slots * SLOT);\n const put = (slot: number, p: { srcFromBase?: number; srcOffset?: number; dstOffset?: number; rowWords?: number; dims: readonly number[]; srcDims?: readonly number[] }) => {\n const u = new Uint32Array(bytes, slot * SLOT, PARAMS_BYTES / 4);\n const i = new Int32Array(bytes, slot * SLOT, PARAMS_BYTES / 4);\n u[0] = this.gridId;\n u[1] = p.srcFromBase ?? 0;\n u[2] = p.srcOffset ?? 0;\n u[3] = p.dstOffset ?? 0;\n for (let a = 0; a < 3; a++) {\n i[4 + a] = this.#boxMin[a]!;\n u[8 + a] = texels[a]!;\n u[12 + a] = p.dims[a]!;\n u[16 + a] = p.srcDims?.[a] ?? 0;\n u[20 + a] = atlas?.dimensions[a] ?? 1;\n }\n u[7] = p.rowWords ?? 0;\n u[11] = this.#blocks[0];\n u[15] = this.#blocks[1];\n };\n put(0, { dims });\n put(1, { srcFromBase: 1, rowWords: this.#rows.base, dims, srcDims: dims });\n if (atlas) {\n put(2, { srcFromBase: 0, rowWords: this.#rows.atlas, dstOffset: this.#rows.atlasOffset, dims: atlas.dimensions, srcDims: atlas.dimensions });\n atlas.levels.forEach((level, l) => {\n const below = l === 0 ? { offset: 0, dimensions: dims } : atlas.levels[l - 1]!;\n put(3 + l, { srcFromBase: l === 0 ? 1 : 0, srcOffset: below.offset, dstOffset: level.offset, dims: level.dimensions, srcDims: below.dimensions });\n });\n }\n this.#device.queue.writeBuffer(this.#params, 0, bytes);\n }\n\n record(encoder: GPUCommandEncoder, options: VDBBoxPyramidRecordOptions = {}): void {\n if (this.#destroyed) throw new VDBError(\"VDB_DISPOSED\", \"vdbCreateBoxPyramid: record() after destroy().\");\n const info = checkTarget(\"vdbCreateBoxPyramid\", this.#device, this.#pool, this.gridId);\n const p = pyramidPipelines(this.#device, info.type);\n // Group 0 names the pool's current buffer: rebuilt every record (a growth replaces it).\n const group0 = this.#device.createBindGroup({\n layout: p.group0,\n entries: [this.#pool.bindGroupEntry(COMPUTE_SLOT), { binding: 1, resource: { buffer: this.#params, size: PARAMS_BYTES } }],\n });\n this.#group1 ??= this.#device.createBindGroup({\n layout: p.group1,\n entries: [this.#baseF32, this.#atlasF32, this.#flags, this.#packed].map((buffer, binding) => ({ binding, resource: { buffer } })),\n });\n const { dimensions: dims, atlas } = this.layout;\n const groups = (size: readonly number[]): [number, number, number] => [Math.ceil(size[0]! / W), Math.ceil(size[1]! / W), Math.ceil(size[2]! / W)];\n encoder.clearBuffer(this.#flags);\n if (atlas) encoder.clearBuffer(this.#atlasF32);\n const pass = encoder.beginComputePass({ label: \"vdb boxPyramid\", ...(options.timestampWrites ? { timestampWrites: options.timestampWrites } : {}) });\n pass.setBindGroup(1, this.#group1);\n const dispatch = (pipeline: GPUComputePipeline, slot: number, size: readonly number[]) => {\n pass.setPipeline(pipeline);\n pass.setBindGroup(0, group0, [slot * SLOT]);\n pass.dispatchWorkgroups(...groups(size));\n };\n dispatch(p.base, 0, dims);\n dispatch(p.mask, 0, dims);\n atlas?.levels.forEach((level, l) => dispatch(p.level, 3 + l, level.dimensions));\n dispatch(p.pack, 1, [Math.ceil(dims[0] / 2), dims[1], dims[2]]);\n if (atlas) dispatch(p.pack, 2, [Math.ceil(atlas.dimensions[0] / 2), atlas.dimensions[1], atlas.dimensions[2]]);\n pass.end();\n encoder.copyBufferToTexture({ buffer: this.#packed, offset: 0, bytesPerRow: this.#rows.base * 4, rowsPerImage: dims[1] }, { texture: this.base }, [dims[0], dims[1], dims[2]]);\n if (atlas && this.atlas) {\n const [aw, ah, ad] = atlas.dimensions;\n encoder.copyBufferToTexture({ buffer: this.#packed, offset: this.#rows.atlasOffset * 4, bytesPerRow: this.#rows.atlas * 4, rowsPerImage: ah }, { texture: this.atlas }, [aw, ah, ad]);\n }\n this.builtRevision = info.imageRevision;\n }\n\n update(encoder: GPUCommandEncoder): boolean {\n if (this.#destroyed) return false;\n const info = this.#pool.info(this.gridId);\n if (!info.resident || info.imageRevision === this.builtRevision) return false;\n this.record(encoder);\n return true;\n }\n\n destroy(): void {\n if (this.#destroyed) return;\n this.#destroyed = true;\n for (const r of this.#owned) r.destroy();\n }\n}\n\n/**\n * Creates the coarse pyramid of pool grid `gridId` on the GPU (see the file comment) and returns it\n * unbuilt: record the build with `pyramid.record(encoder)` (the grid must be resident), submit, and\n * rebuild with `pyramid.update(encoder)` after the grid's image changes (`imageRevision`). The pool\n * must live on `device`. Frees only what it allocated (`destroy()`).\n *\n * const pyramid = vdbCreateBoxPyramid(device, pool, id);\n * pool.update(encoder);\n * pyramid.update(encoder); // first build, then only on a replace\n * device.queue.submit([encoder.finish()]);\n */\nexport function vdbCreateBoxPyramid(device: GPUDevice, pool: VDBGridPool, gridId: number, options: VDBBoxPyramidGpuOptions = {}): VDBBoxPyramidGpu {\n return new BoxPyramidGpu(device, pool, gridId, options);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pyramid.js","sourceRoot":"","sources":["../../../src/core/compute/pyramid.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,mGAAmG;AACnG,yDAAyD;AACzD,4GAA4G;AAC5G,2FAA2F;AAC3F,2GAA2G;AA8B3G,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAA4B,MAAM,qCAAqC,CAAC;AAEpG,MAAM,CAAC,GAAG,cAAc,CAAC;AACzB,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,aAAa,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,EAAW,CAAC;AACtF,uEAAuE;AACvE,MAAM,IAAI,GAAG,GAAG,CAAC;AACjB,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB,MAAM,WAAW,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;CAsB9B,CAAC;AAEF,MAAM,YAAY,GAAG,UAAU,CAAC;;;;;;;;;2BASL,CAAC,KAAK,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAuDb,CAAC,KAAK,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;2BAmBb,CAAC,KAAK,CAAC,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA8Cb,CAAC,KAAK,CAAC,KAAK,CAAC;;;;;;;;;;;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I,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,aAAa;YAAE,OAAO,KAAK,CAAC;QAC9E,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM;YAAE,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3C,CAAC;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,IAAiB,EAAE,MAAc,EAAE,UAAgC,EAAE;IAC1H,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC","sourcesContent":["// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):\n// src/three-openvdb/frame/webgpu/frameMipmaps.js L14–106 (2x2x2 box downsample with clamped edge\n// taps, the mip atlas layout), as an f32 compute pass.\n// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).\n// Changes: GPU compute over a pool grid; the base level is the area-weighted box filter of\n// `vdbResampleGrid`; f16 packing is three's `DataUtils.toHalfFloat`. Divergences: DIVERGES.md (K3.2a row).\n\n/**\n * `vdbCreateBoxPyramid` (K3.2a): the sparse source's coarse pyramid (K3.2 `'coarse-pyramid'`) built on\n * the GPU from a pool grid, recorded into the host's encoder. CPU twin: `@pmndrs/vdb/tools`\n * `vdbBoxPyramid` + three's `DataUtils.toHalfFloat` (the K3.2 CPU path); parity ≤ 1 f16 ulp\n * (e2e/k3-pyramid.spec.ts).\n *\n * Passes, one compute pass (dispatches see each other's writes):\n * 1. **base** (one thread per base texel): the area-weighted box mean of the grid's voxels over the\n * texel's cell, `vdbResampleGrid`'s `'box'` filter on the index cell box `[min − ½, max + ½]` with\n * `⌈texels / 2^L₀⌉` texels. Overlaps are exact integers in units of 1/dims voxel (no f32 rounding\n * of the footprint), summed separably x → y → z in the CPU's order. A texel whose taps touch an\n * active voxel flags its 8³ texel block (atomicOr). A texel whose footprint lies in inactive\n * zero tiles only (no leaf: `vdbGetDim` > 1) is 0 without the voxel loop, as on the CPU.\n * 2. **mask**: texels of an unflagged block become 0 (the CPU path drops leaves with no active voxel,\n * and its dense readout fills them with 0).\n * 3. **levels**: his 2x2x2 box mips with clamped edge taps, level by level, into his atlas layout\n * (`vdbBoxPyramidLayout`), from the f32 base (not the f16 one, as the CPU).\n * 4. **pack**: f32 → f16 (three's `toHalfFloat`: truncation, its denormal and overflow tables) into\n * 256-byte rows, then `copyBufferToTexture` into the r16float base and atlas textures.\n *\n * The textures are the pyramid's own (`TEXTURE_BINDING | COPY_DST | COPY_SRC`) or, with `targets`,\n * the host's (a three texture's `GPUTexture`): r16float, `COPY_DST`, the layout's sizes; then the\n * pyramid never destroys them. Scratch buffers (f32 levels, block flags, the packed rows, parameters)\n * stay alive for rebuilds (a sequence replaces the grid every frame) until `destroy()`.\n */\nimport type { VDBGridPool } from \"../pool/pool.js\";\nimport type { VDBVec3 } from \"../pool/layout.js\";\nimport type { VDBGridTypeName } from \"../types.js\";\nimport { VDBError } from \"../errors.js\";\nimport { vdbModuleEntries, vdbModuleWgsl } from \"../wgsl/generate.js\";\nimport { checkTarget, COMPUTE_SLOT, USAGE, WORKGROUP_AXIS } from \"./shared.js\";\nimport { vdbBoxPyramidLayout, type VDBBoxPyramidLayout } from \"../../tools/frame/pyramid-layout.js\";\n\nconst W = WORKGROUP_AXIS;\nconst STAGE_COMPUTE = 0x4;\nconst TEXTURE_USAGE = { COPY_SRC: 0x1, COPY_DST: 0x2, TEXTURE_BINDING: 0x4 } as const;\n/** Uniform slot stride (minUniformBufferOffsetAlignment's default). */\nconst SLOT = 256;\nconst PARAMS_BYTES = 96;\n\nconst PARAMS_WGSL = /* wgsl */ `\nstruct PyrParams {\n grid: u32,\n srcFromBase: u32,\n srcOffset: u32,\n dstOffset: u32,\n boxMin: vec3i,\n rowWords: u32,\n texels: vec3u,\n blocksX: u32,\n dims: vec3u,\n blocksY: u32,\n srcDims: vec3u,\n pad1: u32,\n atlasDims: vec3u,\n pad2: u32,\n};\n@group(0) @binding(1) var<uniform> pyr: PyrParams;\n@group(1) @binding(0) var<storage, read_write> pyrBase: array<f32>;\n@group(1) @binding(1) var<storage, read_write> pyrAtlas: array<f32>;\n@group(1) @binding(2) var<storage, read_write> pyrFlags: array<atomic<u32>>;\n@group(1) @binding(3) var<storage, read_write> pyrPacked: array<u32>;\n`;\n\nconst KERNELS_WGSL = /* wgsl */ `\nfn pyrBlock(j: vec3u) -> u32 {\n let b = j >> vec3u(3u);\n return b.x + (b.y + b.z * pyr.blocksY) * pyr.blocksX;\n}\n\n// Box filter of the voxels under texel j (vdbResampleGrid 'box'): texel j covers [j·T, (j+1)·T] and voxel\n// r covers [r·D, (r+1)·D] in units of 1/D voxel (T texels of the box, D base texels), so overlaps are\n// exact integers and the weights ov / T. Summed x, then y, then z, in the CPU's order.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrBase(@builtin(global_invocation_id) j: vec3u) {\n let D = pyr.dims;\n if any(j >= D) {\n return;\n }\n let T = pyr.texels;\n let b0 = j * T;\n let b1 = b0 + T;\n let r0 = b0 / D;\n let r1 = (b1 + D - vec3u(1u)) / D - vec3u(1u);\n let tf = vec3f(T);\n var acc = vdbAccessorInit(pyr.grid);\n // Empty space: when every 8³ cell under the footprint is an inactive tile of value 0 (no leaf), the CPU\n // sum is exactly 0 with no active tap. Skips the voxel loop for most texels of a sparse cloud.\n let c0 = (pyr.boxMin + vec3i(r0)) >> vec3u(3u);\n let c1 = (pyr.boxMin + vec3i(r1)) >> vec3u(3u);\n var empty = true;\n for (var cz = c0.z; cz <= c1.z && empty; cz++) {\n for (var cy = c0.y; cy <= c1.y && empty; cy++) {\n for (var cx = c0.x; cx <= c1.x && empty; cx++) {\n let c = vec3i(cx, cy, cz) * 8;\n empty = vdbGetDim(&acc, c) > 1u && vdbReadValue(&acc, c) == 0.0 && !vdbIsActive(&acc, c);\n }\n }\n }\n if empty {\n pyrBase[j.x + (j.y + j.z * D.y) * D.x] = 0.0;\n return;\n }\n var touched = false;\n var sz = 0.0;\n for (var z = r0.z; z <= r1.z; z++) {\n let wz = f32(min(b1.z, (z + 1u) * D.z) - max(b0.z, z * D.z)) / tf.z;\n var sy = 0.0;\n for (var y = r0.y; y <= r1.y; y++) {\n let wy = f32(min(b1.y, (y + 1u) * D.y) - max(b0.y, y * D.y)) / tf.y;\n var sx = 0.0;\n for (var x = r0.x; x <= r1.x; x++) {\n let wx = f32(min(b1.x, (x + 1u) * D.x) - max(b0.x, x * D.x)) / tf.x;\n let ijk = pyr.boxMin + vec3i(vec3u(x, y, z));\n sx += wx * vdbReadValue(&acc, ijk);\n touched = touched || vdbIsActive(&acc, ijk);\n }\n sy += wy * sx;\n }\n sz += wz * sy;\n }\n pyrBase[j.x + (j.y + j.z * D.y) * D.x] = sz;\n if touched {\n atomicOr(&pyrFlags[pyrBlock(j)], 1u);\n }\n}\n\n// Texels of an 8³ block with no active tap read 0 (the CPU drops that leaf; its readout fills 0).\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrMask(@builtin(global_invocation_id) j: vec3u) {\n let D = pyr.dims;\n if any(j >= D) {\n return;\n }\n if atomicLoad(&pyrFlags[pyrBlock(j)]) == 0u {\n pyrBase[j.x + (j.y + j.z * D.y) * D.x] = 0.0;\n }\n}\n\nfn pyrSrc(x: u32, y: u32, z: u32) -> f32 {\n if pyr.srcFromBase != 0u {\n return pyrBase[x + (y + z * pyr.srcDims.y) * pyr.srcDims.x];\n }\n return pyrAtlas[pyr.srcOffset + x + (y + z * pyr.atlasDims.y) * pyr.atlasDims.x];\n}\n\n// His downsample (frameMipmaps.js): the 2x2x2 mean with edge taps clamped, into the atlas at dstOffset.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrLevel(@builtin(global_invocation_id) p: vec3u) {\n if any(p >= pyr.dims) {\n return;\n }\n let s = pyr.srcDims - vec3u(1u);\n let x0 = min(p.x * 2u, s.x);\n let x1 = min(p.x * 2u + 1u, s.x);\n let y0 = min(p.y * 2u, s.y);\n let y1 = min(p.y * 2u + 1u, s.y);\n let z0 = min(p.z * 2u, s.z);\n let z1 = min(p.z * 2u + 1u, s.z);\n let sum = pyrSrc(x0, y0, z0) + pyrSrc(x1, y0, z0) + pyrSrc(x0, y1, z0) + pyrSrc(x1, y1, z0)\n + pyrSrc(x0, y0, z1) + pyrSrc(x1, y0, z1) + pyrSrc(x0, y1, z1) + pyrSrc(x1, y1, z1);\n pyrAtlas[pyr.dstOffset + p.x + (p.y + p.z * pyr.atlasDims.y) * pyr.atlasDims.x] = sum / 8.0;\n}\n\n// three's DataUtils.toHalfFloat (fox-toolkit tables: truncation, denormals, overflow to infinity).\nfn pyrHalf(v: f32) -> u32 {\n let f = bitcast<u32>(clamp(v, -65504.0, 65504.0));\n let e = i32((f >> 23u) & 0xffu) - 127;\n var base = 0u;\n var shift = 24u;\n if e < -27 {\n base = 0u;\n shift = 24u;\n } else if e < -14 {\n base = 0x400u >> u32(-e - 14);\n shift = u32(-e - 1);\n } else if e <= 15 {\n base = u32(e + 15) << 10u;\n shift = 13u;\n } else if e < 128 {\n base = 0x7c00u;\n shift = 24u;\n } else {\n base = 0x7c00u;\n shift = 13u;\n }\n if (f & 0x80000000u) != 0u {\n base = base | 0x8000u;\n }\n return base + ((f & 0x7fffffu) >> shift);\n}\n\n// Two texels per word, rows of rowWords words (bytesPerRow multiple of 256), at dstOffset words.\n@compute @workgroup_size(${W}, ${W}, ${W})\nfn csPyrPack(@builtin(global_invocation_id) p: vec3u) {\n let size = pyr.srcDims;\n let words = (size.x + 1u) / 2u;\n if p.x >= words || p.y >= size.y || p.z >= size.z {\n return;\n }\n let x = p.x * 2u;\n var lo = 0u;\n var hi = 0u;\n if pyr.srcFromBase != 0u {\n let row = (p.y + p.z * size.y) * size.x;\n lo = pyrHalf(pyrBase[row + x]);\n if x + 1u < size.x {\n hi = pyrHalf(pyrBase[row + x + 1u]);\n }\n } else {\n let row = (p.y + p.z * size.y) * size.x;\n lo = pyrHalf(pyrAtlas[row + x]);\n if x + 1u < size.x {\n hi = pyrHalf(pyrAtlas[row + x + 1u]);\n }\n }\n pyrPacked[pyr.dstOffset + (p.y + p.z * size.y) * pyr.rowWords + p.x] = lo | (hi << 16u);\n}\n`;\n\n/** The WGSL of the pyramid kernels for grids of `type` (exported for tests and the size of the shader). */\nexport function boxPyramidWgsl(type: VDBGridTypeName): string {\n return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types: [type], profile: \"march\" })}\\n${PARAMS_WGSL}\\n${KERNELS_WGSL}`;\n}\n\ninterface PyramidPipelines {\n base: GPUComputePipeline;\n mask: GPUComputePipeline;\n level: GPUComputePipeline;\n pack: GPUComputePipeline;\n group0: GPUBindGroupLayout;\n group1: GPUBindGroupLayout;\n error: Promise<GPUError | null>;\n}\n\nconst pipelines = new WeakMap<GPUDevice, Map<VDBGridTypeName, PyramidPipelines>>();\n\nfunction pyramidPipelines(device: GPUDevice, type: VDBGridTypeName): PyramidPipelines {\n let byType = pipelines.get(device);\n if (!byType) pipelines.set(device, (byType = new Map()));\n const cached = byType.get(type);\n if (cached) return cached;\n device.pushErrorScope(\"validation\");\n const group0 = device.createBindGroupLayout({\n label: `vdb boxPyramid ${type} group 0`,\n entries: [\n ...vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }),\n { binding: 1, visibility: STAGE_COMPUTE, buffer: { type: \"uniform\", hasDynamicOffset: true, minBindingSize: PARAMS_BYTES } },\n ],\n });\n const group1 = device.createBindGroupLayout({\n label: `vdb boxPyramid ${type} group 1`,\n entries: [0, 1, 2, 3].map((binding) => ({ binding, visibility: STAGE_COMPUTE, buffer: { type: \"storage\" as const } })),\n });\n const module = device.createShaderModule({ label: `vdb boxPyramid ${type}`, code: boxPyramidWgsl(type) });\n const layout = device.createPipelineLayout({ bindGroupLayouts: [group0, group1] });\n const make = (entryPoint: string) => device.createComputePipeline({ label: `vdb boxPyramid ${entryPoint} ${type}`, layout, compute: { module, entryPoint } });\n const p: PyramidPipelines = {\n base: make(\"csPyrBase\"),\n mask: make(\"csPyrMask\"),\n level: make(\"csPyrLevel\"),\n pack: make(\"csPyrPack\"),\n group0,\n group1,\n error: device.popErrorScope(),\n };\n byType.set(type, p);\n return p;\n}\n\n/**\n * @internal Compiles (once per device and type, cached) the pyramid pipelines for grids of `types`, so a later\n * pyramid over a grid of one of them (G16a: a sparse source following a coarse-first swap to another grid type)\n * creates no pipeline. Returns the pipelines' validation results.\n */\nexport function warmBoxPyramidPipelines(device: GPUDevice, types: Iterable<VDBGridTypeName>): Promise<GPUError | null>[] {\n return [...types].map((type) => pyramidPipelines(device, type).error);\n}\n\n/** Options of {@link vdbCreateBoxPyramid}. */\nexport interface VDBBoxPyramidOptions {\n /** Inclusive voxel index box the pyramid covers. Default: the grid's index bbox now (fixed afterwards). */\n indexBox?: { min: VDBVec3; max: VDBVec3 };\n /** Texels on the longest side of the base level at most (default 128). */\n pyramidMax?: number;\n /** Base level override (default `vdbPyramidBaseLevel`). */\n level?: number;\n /**\n * Write into these r16float textures (`COPY_DST`; `atlas` null exactly when the layout has no atlas)\n * instead of allocating. The pyramid never destroys them (a three texture's `GPUTexture`, for example).\n * Without origins they must have the layout's sizes; with `baseOrigin` / `atlasOrigin` (K6.7: the core\n * sparse source packs every volume's pyramid into one texture) the block at the origin must fit, and\n * `base` and `atlas` may be the same texture.\n */\n targets?: { base: GPUTexture; atlas: GPUTexture | null; baseOrigin?: VDBVec3; atlasOrigin?: VDBVec3 };\n /** Debug label of the GPU objects. */\n label?: string;\n}\n\n/** Options of {@link VDBBoxPyramid.record}. */\nexport interface VDBBoxPyramidRecordOptions {\n /** Timestamps around the build's one compute pass (the `timestamp-query` feature). */\n timestampWrites?: GPUComputePassTimestampWrites;\n}\n\n/** A coarse pyramid on the GPU (see the file comment). */\nexport interface VDBBoxPyramid {\n /** The pool id of the grid the pyramid is built from. */\n readonly gridId: number;\n /** The sizes and level layout of the textures. */\n readonly layout: VDBBoxPyramidLayout;\n /** r16float, the base level (`layout.dimensions`). */\n readonly base: GPUTexture;\n /** r16float, his atlas of the levels above (`layout.atlas.dimensions`), or null. */\n readonly atlas: GPUTexture | null;\n /** Bytes: `textures` (r16f; counted whoever owns them) and `scratch` (this pyramid's buffers). */\n readonly gpuBytes: { readonly textures: number; readonly scratch: number };\n /** The grid's `imageRevision` the last recorded build read, or null before the first. */\n readonly builtRevision: number | null;\n /** True when the grid's image changed since the last recorded build (or none was recorded). */\n readonly stale: boolean;\n /** Pipeline validation (null = valid); the first build's errors surface here. */\n readonly error: Promise<GPUError | null>;\n /**\n * Records a (re)build into `encoder`. The grid must be resident (`pool.update(encoder)` recorded\n * earlier in this encoder or submitted before); call after the pool's update, as for bind groups.\n *\n * @param encoder The encoder the build is recorded into; the host submits it.\n * @param options Timestamp writes for the build pass.\n */\n record(encoder: GPUCommandEncoder, options?: VDBBoxPyramidRecordOptions): void;\n /** Records a rebuild when {@link stale} and the grid is resident; returns whether it did. */\n update(encoder: GPUCommandEncoder): boolean;\n /** Frees the scratch buffers and the textures this pyramid allocated (not `targets`). Idempotent. */\n destroy(): void;\n}\n\nconst align = (n: number, a: number) => Math.ceil(n / a) * a;\nconst bad = (message: string): never => {\n throw new VDBError(\"VDB_BAD_OPTION\", `vdbCreateBoxPyramid: ${message}`);\n};\n\nclass BoxPyramid implements VDBBoxPyramid {\n readonly gridId: number;\n readonly layout: VDBBoxPyramidLayout;\n readonly base: GPUTexture;\n readonly atlas: GPUTexture | null;\n readonly gpuBytes: { textures: number; scratch: number };\n builtRevision: number | null = null;\n error: Promise<GPUError | null>;\n readonly #device: GPUDevice;\n readonly #pool: VDBGridPool;\n readonly #boxMin: VDBVec3;\n readonly #owned: (GPUBuffer | GPUTexture)[] = [];\n readonly #baseF32: GPUBuffer;\n readonly #atlasF32: GPUBuffer;\n readonly #flags: GPUBuffer;\n readonly #packed: GPUBuffer;\n readonly #params: GPUBuffer;\n readonly #rows: { base: number; atlas: number; atlasOffset: number };\n readonly #blocks: [number, number, number];\n /** Where the base and the atlas land in their textures (K6.7 packing; 0 otherwise). */\n #origins: { base: VDBVec3; atlas: VDBVec3 } = { base: [0, 0, 0], atlas: [0, 0, 0] };\n #group1: GPUBindGroup | null = null;\n #destroyed = false;\n\n constructor(device: GPUDevice, pool: VDBGridPool, gridId: number, o: VDBBoxPyramidOptions) {\n if (!device || typeof (device as { createBuffer?: unknown }).createBuffer !== \"function\") bad(\"expected a GPUDevice as the first argument.\");\n if (!pool || typeof (pool as { info?: unknown }).info !== \"function\") bad(\"expected a VDBGridPool as the second argument.\");\n if (pool.device !== device) bad(\"the pool lives on a different GPUDevice. Pass pool.device.\");\n // Residency is checked when a build is recorded; creating needs only the grid's info.\n const info = pool.info(gridId);\n const box = o.indexBox ?? info.indexBBox;\n const texels = [0, 1, 2].map((a) => box.max[a]! - box.min[a]! + 1);\n if (texels.some((t) => !(t > 0) || !Number.isInteger(t))) bad(`empty or non-integer index box ${JSON.stringify(box)}.`);\n this.layout = vdbBoxPyramidLayout(texels, { ...(o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {}), ...(o.level !== undefined ? { level: o.level } : {}) });\n this.#device = device;\n this.#pool = pool;\n this.gridId = gridId;\n this.#boxMin = [box.min[0], box.min[1], box.min[2]];\n const label = o.label ?? `vdb boxPyramid grid ${gridId}`;\n const { dimensions: dims, atlas } = this.layout;\n const baseCount = dims[0] * dims[1] * dims[2];\n const atlasCount = atlas ? atlas.dimensions[0] * atlas.dimensions[1] * atlas.dimensions[2] : 0;\n\n if (o.targets) {\n const check = (t: GPUTexture | null, want: readonly number[] | null, origin: VDBVec3 | undefined, what: string) => {\n if (!want) {\n if (t) bad(`targets.${what} must be null: the layout has no ${what}.`);\n return;\n }\n if (!t) return bad(`targets.${what} is missing (the layout has one, ${want.join(\"x\")}).`);\n const size = [t.width, t.height, t.depthOrArrayLayers];\n const fits = origin\n ? origin.every((v, a) => Number.isInteger(v) && v >= 0 && v + want[a]! <= size[a]!)\n : size.every((v, a) => v === want[a]);\n if (t.format !== \"r16float\" || !fits || (t.usage & TEXTURE_USAGE.COPY_DST) === 0) {\n const where = origin ? ` holding ${want.join(\"x\")} at ${origin.join(\",\")}` : ` of ${want.join(\"x\")}`;\n bad(`targets.${what} must be an r16float 3D texture${where} with COPY_DST (got ${t.format} ${t.width}x${t.height}x${t.depthOrArrayLayers}, usage ${t.usage}).`);\n }\n };\n check(o.targets.base, dims, o.targets.baseOrigin, \"base\");\n check(o.targets.atlas, atlas?.dimensions ?? null, o.targets.atlasOrigin, \"atlas\");\n this.#origins = { base: o.targets.baseOrigin ?? [0, 0, 0], atlas: o.targets.atlasOrigin ?? [0, 0, 0] };\n this.base = o.targets.base;\n this.atlas = o.targets.atlas;\n } else {\n const texture = (size: readonly number[], what: string) => {\n const t = device.createTexture({\n label: `${label} ${what}`,\n size: [size[0]!, size[1]!, size[2]!],\n dimension: \"3d\",\n format: \"r16float\",\n usage: TEXTURE_USAGE.TEXTURE_BINDING | TEXTURE_USAGE.COPY_DST | TEXTURE_USAGE.COPY_SRC,\n });\n this.#owned.push(t);\n return t;\n };\n this.base = texture(dims, \"base\");\n this.atlas = atlas ? texture(atlas.dimensions, \"atlas\") : null;\n }\n\n const rowWords = (w: number) => align(w * 2, 256) / 4;\n const baseWords = rowWords(dims[0]) * dims[1] * dims[2];\n const atlasWords = atlas ? rowWords(atlas.dimensions[0]) * atlas.dimensions[1] * atlas.dimensions[2] : 0;\n this.#rows = { base: rowWords(dims[0]), atlas: atlas ? rowWords(atlas.dimensions[0]) : 0, atlasOffset: align(baseWords, 64) };\n this.#blocks = [Math.ceil(dims[0] / 8), Math.ceil(dims[1] / 8), Math.ceil(dims[2] / 8)];\n const buffer = (size: number, usage: number, what: string) => {\n const b = device.createBuffer({ label: `${label} ${what}`, size: align(Math.max(4, size), 4), usage });\n this.#owned.push(b);\n return b;\n };\n this.#baseF32 = buffer(baseCount * 4, USAGE.STORAGE, \"base f32\");\n this.#atlasF32 = buffer(atlasCount * 4, USAGE.STORAGE | USAGE.COPY_DST, \"atlas f32\");\n this.#flags = buffer(this.#blocks[0] * this.#blocks[1] * this.#blocks[2] * 4, USAGE.STORAGE | USAGE.COPY_DST, \"block flags\");\n this.#packed = buffer((this.#rows.atlasOffset + atlasWords) * 4, USAGE.STORAGE | USAGE.COPY_SRC, \"packed f16\");\n const slots = 4 + (atlas?.levels.length ?? 0);\n this.#params = buffer(slots * SLOT, USAGE.UNIFORM | USAGE.COPY_DST, \"params\");\n this.gpuBytes = {\n textures: 2 * (baseCount + atlasCount),\n scratch: [this.#baseF32, this.#atlasF32, this.#flags, this.#packed, this.#params].reduce((s, b) => s + b.size, 0),\n };\n this.error = pyramidPipelines(device, info.type).error;\n this.#writeParams();\n }\n\n get stale(): boolean {\n if (this.#destroyed) return false;\n return this.builtRevision === null || this.#pool.info(this.gridId).imageRevision !== this.builtRevision;\n }\n\n /** Per-dispatch parameter slots: 0 base/mask, 1 pack base, 2 pack atlas, 3.. levels. */\n #writeParams(): void {\n const { dimensions: dims, atlas, texels } = this.layout;\n const slots = 4 + (atlas?.levels.length ?? 0);\n const bytes = new ArrayBuffer(slots * SLOT);\n const put = (slot: number, p: { srcFromBase?: number; srcOffset?: number; dstOffset?: number; rowWords?: number; dims: readonly number[]; srcDims?: readonly number[] }) => {\n const u = new Uint32Array(bytes, slot * SLOT, PARAMS_BYTES / 4);\n const i = new Int32Array(bytes, slot * SLOT, PARAMS_BYTES / 4);\n u[0] = this.gridId;\n u[1] = p.srcFromBase ?? 0;\n u[2] = p.srcOffset ?? 0;\n u[3] = p.dstOffset ?? 0;\n for (let a = 0; a < 3; a++) {\n i[4 + a] = this.#boxMin[a]!;\n u[8 + a] = texels[a]!;\n u[12 + a] = p.dims[a]!;\n u[16 + a] = p.srcDims?.[a] ?? 0;\n u[20 + a] = atlas?.dimensions[a] ?? 1;\n }\n u[7] = p.rowWords ?? 0;\n u[11] = this.#blocks[0];\n u[15] = this.#blocks[1];\n };\n put(0, { dims });\n put(1, { srcFromBase: 1, rowWords: this.#rows.base, dims, srcDims: dims });\n if (atlas) {\n put(2, { srcFromBase: 0, rowWords: this.#rows.atlas, dstOffset: this.#rows.atlasOffset, dims: atlas.dimensions, srcDims: atlas.dimensions });\n atlas.levels.forEach((level, l) => {\n const below = l === 0 ? { offset: 0, dimensions: dims } : atlas.levels[l - 1]!;\n put(3 + l, { srcFromBase: l === 0 ? 1 : 0, srcOffset: below.offset, dstOffset: level.offset, dims: level.dimensions, srcDims: below.dimensions });\n });\n }\n this.#device.queue.writeBuffer(this.#params, 0, bytes);\n }\n\n record(encoder: GPUCommandEncoder, options: VDBBoxPyramidRecordOptions = {}): void {\n if (this.#destroyed) throw new VDBError(\"VDB_DISPOSED\", \"vdbCreateBoxPyramid: record() after destroy().\");\n const info = checkTarget(\"vdbCreateBoxPyramid\", this.#device, this.#pool, this.gridId);\n const p = pyramidPipelines(this.#device, info.type);\n // Group 0 names the pool's current buffer: rebuilt every record (a growth replaces it).\n const group0 = this.#device.createBindGroup({\n layout: p.group0,\n entries: [this.#pool.bindGroupEntry(COMPUTE_SLOT), { binding: 1, resource: { buffer: this.#params, size: PARAMS_BYTES } }],\n });\n this.#group1 ??= this.#device.createBindGroup({\n layout: p.group1,\n entries: [this.#baseF32, this.#atlasF32, this.#flags, this.#packed].map((buffer, binding) => ({ binding, resource: { buffer } })),\n });\n const { dimensions: dims, atlas } = this.layout;\n const groups = (size: readonly number[]): [number, number, number] => [Math.ceil(size[0]! / W), Math.ceil(size[1]! / W), Math.ceil(size[2]! / W)];\n encoder.clearBuffer(this.#flags);\n if (atlas) encoder.clearBuffer(this.#atlasF32);\n const pass = encoder.beginComputePass({ label: \"vdb boxPyramid\", ...(options.timestampWrites ? { timestampWrites: options.timestampWrites } : {}) });\n pass.setBindGroup(1, this.#group1);\n const dispatch = (pipeline: GPUComputePipeline, slot: number, size: readonly number[]) => {\n pass.setPipeline(pipeline);\n pass.setBindGroup(0, group0, [slot * SLOT]);\n pass.dispatchWorkgroups(...groups(size));\n };\n dispatch(p.base, 0, dims);\n dispatch(p.mask, 0, dims);\n atlas?.levels.forEach((level, l) => dispatch(p.level, 3 + l, level.dimensions));\n dispatch(p.pack, 1, [Math.ceil(dims[0] / 2), dims[1], dims[2]]);\n if (atlas) dispatch(p.pack, 2, [Math.ceil(atlas.dimensions[0] / 2), atlas.dimensions[1], atlas.dimensions[2]]);\n pass.end();\n encoder.copyBufferToTexture({ buffer: this.#packed, offset: 0, bytesPerRow: this.#rows.base * 4, rowsPerImage: dims[1] }, { texture: this.base, origin: this.#origins.base }, [dims[0], dims[1], dims[2]]);\n if (atlas && this.atlas) {\n const [aw, ah, ad] = atlas.dimensions;\n encoder.copyBufferToTexture({ buffer: this.#packed, offset: this.#rows.atlasOffset * 4, bytesPerRow: this.#rows.atlas * 4, rowsPerImage: ah }, { texture: this.atlas, origin: this.#origins.atlas }, [aw, ah, ad]);\n }\n this.builtRevision = info.imageRevision;\n }\n\n update(encoder: GPUCommandEncoder): boolean {\n if (this.#destroyed) return false;\n const info = this.#pool.info(this.gridId);\n if (!info.resident || info.imageRevision === this.builtRevision) return false;\n this.record(encoder);\n return true;\n }\n\n destroy(): void {\n if (this.#destroyed) return;\n this.#destroyed = true;\n for (const r of this.#owned) r.destroy();\n }\n}\n\n/**\n * Creates the coarse pyramid of pool grid `gridId` on the GPU (see the file comment) and returns it\n * unbuilt: record the build with `pyramid.record(encoder)` (the grid must be resident), submit, and\n * rebuild with `pyramid.update(encoder)` after the grid's image changes (`imageRevision`). The pool\n * must live on `device`. Frees only what it allocated (`destroy()`).\n *\n * const pyramid = vdbCreateBoxPyramid(device, pool, id);\n * pool.update(encoder);\n * pyramid.update(encoder); // first build, then only on a replace\n * device.queue.submit([encoder.finish()]);\n *\n * @param device The host's `GPUDevice`; the pool must live on it.\n * @param pool The pool that holds the grid.\n * @param gridId The grid's pool id.\n * @param options Index box, size cap, level, target textures and label ({@link VDBBoxPyramidOptions}).\n */\nexport function vdbCreateBoxPyramid(device: GPUDevice, pool: VDBGridPool, gridId: number, options: VDBBoxPyramidOptions = {}): VDBBoxPyramid {\n return new BoxPyramid(device, pool, gridId, options);\n}\n"]}
|
|
@@ -96,6 +96,7 @@ export interface VDBReadback<T> {
|
|
|
96
96
|
* call {@link submitted} first (else rejects with `VDB_BAD_OPTION`).
|
|
97
97
|
*/
|
|
98
98
|
read(): Promise<T>;
|
|
99
|
+
/** Drops the work without reading it and frees the tool's buffers. */
|
|
99
100
|
dispose(): void;
|
|
100
101
|
}
|
|
101
102
|
/** Owns the buffers of one tool call; frees exactly those. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/core/compute/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEtE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAY,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;AAEnE,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAW,CAAC;AAC5G,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,aAAa,GAAG,GAAG,CA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AAC;YACpI,MAAM,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YACtC,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAChD,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM;YAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,UAAU,WAAW,CACzB,MAAiB,EACjB,KAAoC,EACpC,KAAa;IAEb,IAAI,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAI,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACxE,MAAM,OAAO,GAAG,MAAM,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;AACjG,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["/**\n * Shared plumbing of the core compute tools (K2.3): kernel assembly on a\n * slot-mode VDB module, per-device pipeline caching, and the readback handle.\n *\n * Each kernel is one shader: `vdbModuleWgsl({ slot: COMPUTE_SLOT, types:\n * [type], profile: 'sample' })` plus a host footer that calls only the public\n * `vdb*` API. Group 0 holds the pool (binding 0, `vdbModuleEntries`) and the\n * kernel's uniform parameters (binding 1); group 1 holds the kernel's\n * outputs. Default module options, so the WGSL size snapshot is unchanged.\n */\nimport { VDBError } from \"../errors.js\";\nimport type { VDBGridInfo, VDBGridPool } from \"../pool/pool.js\";\nimport type { VDBGridTypeName, VDBSlot } from \"../types.js\";\nimport { vdbModuleEntries, vdbModuleWgsl } from \"../wgsl/generate.js\";\n\n/** Where the compute kernels bind the pool. */\nexport const COMPUTE_SLOT: VDBSlot = { group: 0, firstBinding: 0 };\n\n/** Threads per workgroup per axis (4 x 4 x 4 = 64). */\nexport const WORKGROUP_AXIS = 4;\n\n/** WebGPU flag values, restated so the core loads where the globals don't exist (Node). */\nexport const USAGE = { MAP_READ: 0x1, COPY_SRC: 0x4, COPY_DST: 0x8, UNIFORM: 0x40, STORAGE: 0x80 } as const;\nconst STAGE_COMPUTE = 0x4;\nconst MAP_MODE_READ = 0x1;\n\n/** Bytes of `CsParams` below. */\nexport const PARAMS_BYTES = 80;\n\n/**\n * Uniform parameters shared by every kernel (`CsParams`, 80 B):\n * `grid, bins, filter, _` u32 at 0..15; `regionMin` vec3i at 16; `regionSize`\n * vec3u at 32; `dims` vec3u at 48; `range` vec2f at 64.\n */\nexport interface KernelParams {\n grid: number;\n bins?: number;\n filter?: number;\n regionMin: readonly [number, number, number];\n regionSize: readonly [number, number, number];\n dims?: readonly [number, number, number];\n range?: { min: number; max: number };\n}\n\nconst PARAMS_WGSL = /* wgsl */ `\nstruct CsParams {\n grid: u32,\n bins: u32,\n filterMode: u32,\n pad0: u32,\n regionMin: vec3i,\n pad1: u32,\n regionSize: vec3u,\n pad2: u32,\n dims: vec3u,\n pad3: u32,\n range: vec2f,\n pad4: vec2f,\n};\n@group(0) @binding(1) var<uniform> csParams: CsParams;\n`;\n\n/** A kernel: its footer WGSL (after the module and `CsParams`) and its group-1 output bindings. */\nexport interface KernelSource {\n readonly entryPoint: string;\n readonly footer: string;\n readonly outputs: number;\n}\n\ninterface CachedPipeline {\n pipeline: GPUComputePipeline;\n group0: GPUBindGroupLayout;\n group1: GPUBindGroupLayout;\n /** Validation result of the module + pipeline creation (null = valid). */\n error: Promise<GPUError | null>;\n}\n\nconst pipelines = new WeakMap<GPUDevice, Map<string, CachedPipeline>>();\n\n/** The full WGSL of `kernel` for grids of `type` (exported for tests and the size of the shader). */\nexport function kernelWgsl(kernel: KernelSource, type: VDBGridTypeName): string {\n return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types: [type], profile: \"sample\" })}\\n${PARAMS_WGSL}\\n${kernel.footer}`;\n}\n\n/** The compute pipeline of `kernel` for `type` on `device`, created once per device. */\nexport function kernelPipeline(device: GPUDevice, kernel: KernelSource, type: VDBGridTypeName): CachedPipeline {\n let byKey = pipelines.get(device);\n if (!byKey) pipelines.set(device, (byKey = new Map()));\n const key = `${kernel.entryPoint}:${type}`;\n let cached = byKey.get(key);\n if (cached) return cached;\n device.pushErrorScope(\"validation\");\n const group0 = device.createBindGroupLayout({\n label: `vdb compute ${key} group 0`,\n entries: [\n ...vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }),\n { binding: 1, visibility: STAGE_COMPUTE, buffer: { type: \"uniform\" } },\n ],\n });\n const group1 = device.createBindGroupLayout({\n label: `vdb compute ${key} group 1`,\n entries: Array.from({ length: kernel.outputs }, (_, binding) => ({\n binding,\n visibility: STAGE_COMPUTE,\n buffer: { type: \"storage\" as const },\n })),\n });\n const module = device.createShaderModule({ label: `vdb compute ${key}`, code: kernelWgsl(kernel, type) });\n const pipeline = device.createComputePipeline({\n label: `vdb compute ${key}`,\n layout: device.createPipelineLayout({ bindGroupLayouts: [group0, group1] }),\n compute: { module, entryPoint: kernel.entryPoint },\n });\n cached = { pipeline, group0, group1, error: device.popErrorScope() };\n byKey.set(key, cached);\n return cached;\n}\n\nfunction badOption(message: string): never {\n throw new VDBError(\"VDB_BAD_OPTION\", message);\n}\n\n/** Checks `device` / `pool` / `gridId` and returns the grid's info. */\nexport function checkTarget(where: string, device: GPUDevice, pool: VDBGridPool, gridId: number): VDBGridInfo {\n if (!device || typeof (device as { createBuffer?: unknown }).createBuffer !== \"function\") {\n badOption(`${where}: expected a GPUDevice as the first argument (the device the pool lives on).`);\n }\n if (!pool || typeof (pool as { info?: unknown }).info !== \"function\") {\n badOption(`${where}: expected a VDBGridPool as the second argument.`);\n }\n if (pool.device !== device) {\n badOption(`${where}: the pool lives on a different GPUDevice. Pass pool.device (or create the pool on this device).`);\n }\n const info = pool.info(gridId);\n if (!info.resident) {\n badOption(\n `${where}: grid ${gridId} is not on the GPU yet. Call pool.update(encoder) (or pool.flush()) before recording compute work on it.`,\n );\n }\n const { min, max } = info.indexBBox;\n if (min.some((v, a) => v > max[a]!)) {\n badOption(`${where}: grid ${gridId} has an empty index bbox (${JSON.stringify(info.indexBBox)}); there are no voxels to process.`);\n }\n return info;\n}\n\n/** Checks a positive integer option. */\nexport function checkPositiveInt(where: string, name: string, value: number): void {\n if (!Number.isInteger(value) || value < 1) badOption(`${where}: ${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);\n}\n\n/** Creates a buffer with initial contents (mapped at creation, no queue write). */\nexport function createInitialized(device: GPUDevice, label: string, usage: number, data: ArrayBufferView, size = data.byteLength): GPUBuffer {\n const buffer = device.createBuffer({ label, size: align4(Math.max(4, size)), usage, mappedAtCreation: true });\n new Uint8Array(buffer.getMappedRange()).set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));\n buffer.unmap();\n return buffer;\n}\n\nexport function align4(n: number): number {\n return Math.ceil(n / 4) * 4;\n}\n\n/** The packed `CsParams` bytes. */\nexport function packParams(p: KernelParams): ArrayBuffer {\n const bytes = new ArrayBuffer(PARAMS_BYTES);\n const u = new Uint32Array(bytes);\n const i = new Int32Array(bytes);\n const f = new Float32Array(bytes);\n u[0] = p.grid;\n u[1] = p.bins ?? 0;\n u[2] = p.filter ?? 0;\n for (let a = 0; a < 3; a++) {\n i[4 + a] = p.regionMin[a]!;\n u[8 + a] = p.regionSize[a]!;\n u[12 + a] = p.dims?.[a] ?? 0;\n }\n f[16] = p.range?.min ?? 0;\n f[17] = p.range?.max ?? 0;\n return bytes;\n}\n\n/** Workgroup counts covering `size` threads per axis. */\nexport function workgroups(size: readonly [number, number, number]): [number, number, number] {\n return [Math.ceil(size[0] / WORKGROUP_AXIS), Math.ceil(size[1] / WORKGROUP_AXIS), Math.ceil(size[2] / WORKGROUP_AXIS)];\n}\n\n/**\n * Pending GPU work with a CPU result. Created by `gridStats` / `decodeToAtlas`\n * after their passes are recorded.\n *\n * Order of calls:\n * - **No `encoder` option** (the tool created and submitted its own): call\n * {@link read} at any time.\n * - **Host `encoder`**: the work sits in the host's encoder until the host\n * submits it. Submit, then call {@link submitted}, then {@link read}:\n *\n * const job = gridStats(device, pool, id, { encoder });\n * device.queue.submit([encoder.finish()]);\n * const stats = await job.submitted().read();\n *\n * `read()` before `submitted()` rejects with `VDB_BAD_OPTION` and touches\n * nothing: mapping (or freeing) the tool's buffers before the submit would\n * make that submit fail validation (\"used in submit while destroyed\" /\n * \"mapped\").\n *\n * `read()` maps the readback, frees every buffer the tool allocated and\n * resolves with the result; keep it outside timed regions. Call\n * {@link dispose} instead to drop the work without reading it (after its\n * submit, or with the encoder discarded).\n */\nexport interface VDBReadback<T> {\n /**\n * Tells the job the host submitted the encoder it recorded into; returns\n * the job (`job.submitted().read()`). A no-op for work the tool submitted\n * itself.\n */\n submitted(): this;\n /**\n * Maps the result and frees the tool's buffers. With a host `encoder`,\n * call {@link submitted} first (else rejects with `VDB_BAD_OPTION`).\n */\n read(): Promise<T>;\n dispose(): void;\n}\n\n/** Owns the buffers of one tool call; frees exactly those. */\nexport class ComputeJob<T> implements VDBReadback<T> {\n readonly #owned: GPUBuffer[];\n readonly #staging: GPUBuffer | null;\n readonly #finish: (bytes: ArrayBuffer) => T;\n readonly #error: Promise<GPUError | null>;\n readonly #where: string;\n #result: Promise<T> | null = null;\n #disposed = false;\n /** False until the host says it submitted its encoder; true when the tool submitted its own. */\n #submitted: boolean;\n\n constructor(\n where: string,\n owned: GPUBuffer[],\n staging: GPUBuffer | null,\n error: Promise<GPUError | null>,\n finish: (bytes: ArrayBuffer) => T,\n selfSubmitted = true,\n ) {\n this.#where = where;\n this.#owned = owned;\n this.#staging = staging;\n this.#error = error;\n this.#finish = finish;\n this.#submitted = selfSubmitted;\n }\n\n submitted(): this {\n this.#submitted = true;\n return this;\n }\n\n read(): Promise<T> {\n if (this.#result) return this.#result;\n if (this.#disposed) return Promise.reject(new VDBError(\"VDB_DISPOSED\", `${this.#where}: this result was disposed before read().`));\n if (!this.#submitted) {\n return Promise.reject(\n new VDBError(\n \"VDB_BAD_OPTION\",\n `${this.#where}: read() before the host submitted its encoder. The work was recorded into your encoder: ` +\n \"device.queue.submit([encoder.finish()]), then job.submitted().read(). (Nothing was mapped or freed.)\",\n ),\n );\n }\n this.#result = this.#read();\n return this.#result;\n }\n\n async #read(): Promise<T> {\n const staging = this.#staging;\n // Keeps the GPU output alive: the host frees it with dispose().\n if (!staging) throw new VDBError(\"VDB_BAD_OPTION\", `${this.#where}: created with readback: false; nothing to read. Use the buffer, then dispose().`);\n try {\n const error = await this.#error;\n if (error) throw new VDBError(\"VDB_UNSUPPORTED_DEVICE\", `${this.#where}: the compute pipeline failed validation: ${error.message}`);\n await staging.mapAsync(MAP_MODE_READ);\n const bytes = staging.getMappedRange().slice(0);\n staging.unmap();\n return this.#finish(bytes);\n } finally {\n this.dispose();\n }\n }\n\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n for (const b of this.#owned) b.destroy();\n this.#staging?.destroy();\n }\n}\n\n/** Creates an encoder when the host gave none; `submit` submits it only then. */\nexport function hostEncoder(\n device: GPUDevice,\n given: GPUCommandEncoder | undefined,\n label: string,\n): { encoder: GPUCommandEncoder; submit(): void; readonly selfSubmitted: boolean } {\n if (given) return { encoder: given, submit() {}, selfSubmitted: false };\n const encoder = device.createCommandEncoder({ label });\n return { encoder, submit: () => device.queue.submit([encoder.finish()]), selfSubmitted: true };\n}\n\nexport { MAP_MODE_READ };\n"]}
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/core/compute/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEtE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAY,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;AAEnE,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAW,CAAC;AAC5G,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,iCAAiC;AACjC,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC;AAiB/B,MAAM,WAAW,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;CAgB9B,CAAC;AAiBF,MAAM,SAAS,GAAG,IAAI,OAAO,EAA0C,CAAC;AAExE,qGAAqG;AACrG,MAAM,UAAU,UAAU,CAAC,MAAoB,EAAE,IAAqB;IACpE,OAAO,GAAG,aAAa,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,WAAW,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;AACxH,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,cAAc,CAAC,MAAiB,EAA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C;QACzC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,UAAU,WAAW,CACzB,MAAiB,EACjB,KAAoC,EACpC,KAAa;IAEb,IAAI,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAI,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACxE,MAAM,OAAO,GAAG,MAAM,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;AACjG,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC","sourcesContent":["/**\n * Shared plumbing of the core compute tools (K2.3): kernel assembly on a\n * slot-mode VDB module, per-device pipeline caching, and the readback handle.\n *\n * Each kernel is one shader: `vdbModuleWgsl({ slot: COMPUTE_SLOT, types:\n * [type], profile: 'sample' })` plus a host footer that calls only the public\n * `vdb*` API. Group 0 holds the pool (binding 0, `vdbModuleEntries`) and the\n * kernel's uniform parameters (binding 1); group 1 holds the kernel's\n * outputs. Default module options, so the WGSL size snapshot is unchanged.\n */\nimport { VDBError } from \"../errors.js\";\nimport type { VDBGridInfo, VDBGridPool } from \"../pool/pool.js\";\nimport type { VDBGridTypeName, VDBSlot } from \"../types.js\";\nimport { vdbModuleEntries, vdbModuleWgsl } from \"../wgsl/generate.js\";\n\n/** Where the compute kernels bind the pool. */\nexport const COMPUTE_SLOT: VDBSlot = { group: 0, firstBinding: 0 };\n\n/** Threads per workgroup per axis (4 x 4 x 4 = 64). */\nexport const WORKGROUP_AXIS = 4;\n\n/** WebGPU flag values, restated so the core loads where the globals don't exist (Node). */\nexport const USAGE = { MAP_READ: 0x1, COPY_SRC: 0x4, COPY_DST: 0x8, UNIFORM: 0x40, STORAGE: 0x80 } as const;\nconst STAGE_COMPUTE = 0x4;\nconst MAP_MODE_READ = 0x1;\n\n/** Bytes of `CsParams` below. */\nexport const PARAMS_BYTES = 80;\n\n/**\n * Uniform parameters shared by every kernel (`CsParams`, 80 B):\n * `grid, bins, filter, _` u32 at 0..15; `regionMin` vec3i at 16; `regionSize`\n * vec3u at 32; `dims` vec3u at 48; `range` vec2f at 64.\n */\nexport interface KernelParams {\n grid: number;\n bins?: number;\n filter?: number;\n regionMin: readonly [number, number, number];\n regionSize: readonly [number, number, number];\n dims?: readonly [number, number, number];\n range?: { min: number; max: number };\n}\n\nconst PARAMS_WGSL = /* wgsl */ `\nstruct CsParams {\n grid: u32,\n bins: u32,\n filterMode: u32,\n pad0: u32,\n regionMin: vec3i,\n pad1: u32,\n regionSize: vec3u,\n pad2: u32,\n dims: vec3u,\n pad3: u32,\n range: vec2f,\n pad4: vec2f,\n};\n@group(0) @binding(1) var<uniform> csParams: CsParams;\n`;\n\n/** A kernel: its footer WGSL (after the module and `CsParams`) and its group-1 output bindings. */\nexport interface KernelSource {\n readonly entryPoint: string;\n readonly footer: string;\n readonly outputs: number;\n}\n\ninterface CachedPipeline {\n pipeline: GPUComputePipeline;\n group0: GPUBindGroupLayout;\n group1: GPUBindGroupLayout;\n /** Validation result of the module + pipeline creation (null = valid). */\n error: Promise<GPUError | null>;\n}\n\nconst pipelines = new WeakMap<GPUDevice, Map<string, CachedPipeline>>();\n\n/** The full WGSL of `kernel` for grids of `type` (exported for tests and the size of the shader). */\nexport function kernelWgsl(kernel: KernelSource, type: VDBGridTypeName): string {\n return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types: [type], profile: \"sample\" })}\\n${PARAMS_WGSL}\\n${kernel.footer}`;\n}\n\n/** The compute pipeline of `kernel` for `type` on `device`, created once per device. */\nexport function kernelPipeline(device: GPUDevice, kernel: KernelSource, type: VDBGridTypeName): CachedPipeline {\n let byKey = pipelines.get(device);\n if (!byKey) pipelines.set(device, (byKey = new Map()));\n const key = `${kernel.entryPoint}:${type}`;\n let cached = byKey.get(key);\n if (cached) return cached;\n device.pushErrorScope(\"validation\");\n const group0 = device.createBindGroupLayout({\n label: `vdb compute ${key} group 0`,\n entries: [\n ...vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }),\n { binding: 1, visibility: STAGE_COMPUTE, buffer: { type: \"uniform\" } },\n ],\n });\n const group1 = device.createBindGroupLayout({\n label: `vdb compute ${key} group 1`,\n entries: Array.from({ length: kernel.outputs }, (_, binding) => ({\n binding,\n visibility: STAGE_COMPUTE,\n buffer: { type: \"storage\" as const },\n })),\n });\n const module = device.createShaderModule({ label: `vdb compute ${key}`, code: kernelWgsl(kernel, type) });\n const pipeline = device.createComputePipeline({\n label: `vdb compute ${key}`,\n layout: device.createPipelineLayout({ bindGroupLayouts: [group0, group1] }),\n compute: { module, entryPoint: kernel.entryPoint },\n });\n cached = { pipeline, group0, group1, error: device.popErrorScope() };\n byKey.set(key, cached);\n return cached;\n}\n\nfunction badOption(message: string): never {\n throw new VDBError(\"VDB_BAD_OPTION\", message);\n}\n\n/** Checks `device` / `pool` / `gridId` and returns the grid's info. */\nexport function checkTarget(where: string, device: GPUDevice, pool: VDBGridPool, gridId: number): VDBGridInfo {\n if (!device || typeof (device as { createBuffer?: unknown }).createBuffer !== \"function\") {\n badOption(`${where}: expected a GPUDevice as the first argument (the device the pool lives on).`);\n }\n if (!pool || typeof (pool as { info?: unknown }).info !== \"function\") {\n badOption(`${where}: expected a VDBGridPool as the second argument.`);\n }\n if (pool.device !== device) {\n badOption(`${where}: the pool lives on a different GPUDevice. Pass pool.device (or create the pool on this device).`);\n }\n const info = pool.info(gridId);\n if (!info.resident) {\n badOption(\n `${where}: grid ${gridId} is not on the GPU yet. Call pool.update(encoder) (or pool.flush()) before recording compute work on it.`,\n );\n }\n const { min, max } = info.indexBBox;\n if (min.some((v, a) => v > max[a]!)) {\n badOption(`${where}: grid ${gridId} has an empty index bbox (${JSON.stringify(info.indexBBox)}); there are no voxels to process.`);\n }\n return info;\n}\n\n/** Checks a positive integer option. */\nexport function checkPositiveInt(where: string, name: string, value: number): void {\n if (!Number.isInteger(value) || value < 1) badOption(`${where}: ${name} must be an integer >= 1, got ${JSON.stringify(value)}.`);\n}\n\n/** Creates a buffer with initial contents (mapped at creation, no queue write). */\nexport function createInitialized(device: GPUDevice, label: string, usage: number, data: ArrayBufferView, size = data.byteLength): GPUBuffer {\n const buffer = device.createBuffer({ label, size: align4(Math.max(4, size)), usage, mappedAtCreation: true });\n new Uint8Array(buffer.getMappedRange()).set(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));\n buffer.unmap();\n return buffer;\n}\n\nexport function align4(n: number): number {\n return Math.ceil(n / 4) * 4;\n}\n\n/** The packed `CsParams` bytes. */\nexport function packParams(p: KernelParams): ArrayBuffer {\n const bytes = new ArrayBuffer(PARAMS_BYTES);\n const u = new Uint32Array(bytes);\n const i = new Int32Array(bytes);\n const f = new Float32Array(bytes);\n u[0] = p.grid;\n u[1] = p.bins ?? 0;\n u[2] = p.filter ?? 0;\n for (let a = 0; a < 3; a++) {\n i[4 + a] = p.regionMin[a]!;\n u[8 + a] = p.regionSize[a]!;\n u[12 + a] = p.dims?.[a] ?? 0;\n }\n f[16] = p.range?.min ?? 0;\n f[17] = p.range?.max ?? 0;\n return bytes;\n}\n\n/** Workgroup counts covering `size` threads per axis. */\nexport function workgroups(size: readonly [number, number, number]): [number, number, number] {\n return [Math.ceil(size[0] / WORKGROUP_AXIS), Math.ceil(size[1] / WORKGROUP_AXIS), Math.ceil(size[2] / WORKGROUP_AXIS)];\n}\n\n/**\n * Pending GPU work with a CPU result. Created by `gridStats` / `decodeToAtlas`\n * after their passes are recorded.\n *\n * Order of calls:\n * - **No `encoder` option** (the tool created and submitted its own): call\n * {@link read} at any time.\n * - **Host `encoder`**: the work sits in the host's encoder until the host\n * submits it. Submit, then call {@link submitted}, then {@link read}:\n *\n * const job = gridStats(device, pool, id, { encoder });\n * device.queue.submit([encoder.finish()]);\n * const stats = await job.submitted().read();\n *\n * `read()` before `submitted()` rejects with `VDB_BAD_OPTION` and touches\n * nothing: mapping (or freeing) the tool's buffers before the submit would\n * make that submit fail validation (\"used in submit while destroyed\" /\n * \"mapped\").\n *\n * `read()` maps the readback, frees every buffer the tool allocated and\n * resolves with the result; keep it outside timed regions. Call\n * {@link dispose} instead to drop the work without reading it (after its\n * submit, or with the encoder discarded).\n */\nexport interface VDBReadback<T> {\n /**\n * Tells the job the host submitted the encoder it recorded into; returns\n * the job (`job.submitted().read()`). A no-op for work the tool submitted\n * itself.\n */\n submitted(): this;\n /**\n * Maps the result and frees the tool's buffers. With a host `encoder`,\n * call {@link submitted} first (else rejects with `VDB_BAD_OPTION`).\n */\n read(): Promise<T>;\n /** Drops the work without reading it and frees the tool's buffers. */\n dispose(): void;\n}\n\n/** Owns the buffers of one tool call; frees exactly those. */\nexport class ComputeJob<T> implements VDBReadback<T> {\n readonly #owned: GPUBuffer[];\n readonly #staging: GPUBuffer | null;\n readonly #finish: (bytes: ArrayBuffer) => T;\n readonly #error: Promise<GPUError | null>;\n readonly #where: string;\n #result: Promise<T> | null = null;\n #disposed = false;\n /** False until the host says it submitted its encoder; true when the tool submitted its own. */\n #submitted: boolean;\n\n constructor(\n where: string,\n owned: GPUBuffer[],\n staging: GPUBuffer | null,\n error: Promise<GPUError | null>,\n finish: (bytes: ArrayBuffer) => T,\n selfSubmitted = true,\n ) {\n this.#where = where;\n this.#owned = owned;\n this.#staging = staging;\n this.#error = error;\n this.#finish = finish;\n this.#submitted = selfSubmitted;\n }\n\n submitted(): this {\n this.#submitted = true;\n return this;\n }\n\n read(): Promise<T> {\n if (this.#result) return this.#result;\n if (this.#disposed) return Promise.reject(new VDBError(\"VDB_DISPOSED\", `${this.#where}: this result was disposed before read().`));\n if (!this.#submitted) {\n return Promise.reject(\n new VDBError(\n \"VDB_BAD_OPTION\",\n `${this.#where}: read() before the host submitted its encoder. The work was recorded into your encoder: ` +\n \"device.queue.submit([encoder.finish()]), then job.submitted().read(). (Nothing was mapped or freed.)\",\n ),\n );\n }\n this.#result = this.#read();\n return this.#result;\n }\n\n async #read(): Promise<T> {\n const staging = this.#staging;\n // Keeps the GPU output alive: the host frees it with dispose().\n if (!staging) throw new VDBError(\"VDB_BAD_OPTION\", `${this.#where}: created with readback: false; nothing to read. Use the buffer, then dispose().`);\n try {\n const error = await this.#error;\n if (error) throw new VDBError(\"VDB_UNSUPPORTED_DEVICE\", `${this.#where}: the compute pipeline failed validation: ${error.message}`);\n await staging.mapAsync(MAP_MODE_READ);\n const bytes = staging.getMappedRange().slice(0);\n staging.unmap();\n return this.#finish(bytes);\n } finally {\n this.dispose();\n }\n }\n\n dispose(): void {\n if (this.#disposed) return;\n this.#disposed = true;\n for (const b of this.#owned) b.destroy();\n this.#staging?.destroy();\n }\n}\n\n/** Creates an encoder when the host gave none; `submit` submits it only then. */\nexport function hostEncoder(\n device: GPUDevice,\n given: GPUCommandEncoder | undefined,\n label: string,\n): { encoder: GPUCommandEncoder; submit(): void; readonly selfSubmitted: boolean } {\n if (given) return { encoder: given, submit() {}, selfSubmitted: false };\n const encoder = device.createCommandEncoder({ label });\n return { encoder, submit: () => device.queue.submit([encoder.finish()]), selfSubmitted: true };\n}\n\nexport { MAP_MODE_READ };\n"]}
|