@pmndrs/vdb 0.0.0-stage → 0.1.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 +137 -0
- package/LICENSE +21 -0
- package/README.md +448 -2
- package/THIRD_PARTY_NOTICES.md +147 -0
- package/dist/core/compute/atlas.d.ts +94 -0
- package/dist/core/compute/atlas.js +98 -0
- package/dist/core/compute/atlas.js.map +1 -0
- package/dist/core/compute/index.d.ts +13 -0
- package/dist/core/compute/index.js +9 -0
- package/dist/core/compute/index.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +105 -0
- package/dist/core/compute/pyramid.js +455 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +115 -0
- package/dist/core/compute/shared.js +211 -0
- package/dist/core/compute/shared.js.map +1 -0
- package/dist/core/compute/stats.d.ts +71 -0
- package/dist/core/compute/stats.js +188 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +23 -0
- package/dist/core/compute/value-transform.js +58 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +11 -0
- package/dist/core/errors.js +9 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.js +27 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +15 -0
- package/dist/core/internal.js +15 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/pool/affine.d.ts +34 -0
- package/dist/core/pool/affine.js +100 -0
- package/dist/core/pool/affine.js.map +1 -0
- package/dist/core/pool/allocator.d.ts +32 -0
- package/dist/core/pool/allocator.js +81 -0
- package/dist/core/pool/allocator.js.map +1 -0
- package/dist/core/pool/image-header.d.ts +82 -0
- package/dist/core/pool/image-header.js +175 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +164 -0
- package/dist/core/pool/layout.js +267 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +40 -0
- package/dist/core/pool/limits.js +79 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +279 -0
- package/dist/core/pool/pool.js +953 -0
- package/dist/core/pool/pool.js.map +1 -0
- package/dist/core/source/dense.d.ts +19 -0
- package/dist/core/source/dense.js +287 -0
- package/dist/core/source/dense.js.map +1 -0
- package/dist/core/source/types.d.ts +63 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- package/dist/core/types.d.ts +28 -0
- package/dist/core/types.js +28 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +41 -0
- package/dist/core/wgsl/api.js +463 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +82 -0
- package/dist/core/wgsl/generate.js +505 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +54 -0
- package/dist/core/wgsl/level-set.js +194 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
- package/dist/core/wgsl/reserved.d.ts +9 -0
- package/dist/core/wgsl/reserved.js +26 -0
- package/dist/core/wgsl/reserved.js.map +1 -0
- package/dist/core/wgsl/types.d.ts +104 -0
- package/dist/core/wgsl/types.js +2 -0
- package/dist/core/wgsl/types.js.map +1 -0
- package/dist/three/coarse-first.d.ts +162 -0
- package/dist/three/coarse-first.js +187 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +63 -0
- package/dist/three/compute.js +56 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +59 -0
- package/dist/three/device.js +59 -0
- package/dist/three/device.js.map +1 -0
- package/dist/three/frame/blackbody.d.ts +42 -0
- package/dist/three/frame/blackbody.js +74 -0
- package/dist/three/frame/blackbody.js.map +1 -0
- package/dist/three/frame/chunks.d.ts +157 -0
- package/dist/three/frame/chunks.js +559 -0
- package/dist/three/frame/chunks.js.map +1 -0
- package/dist/three/frame/density-material.d.ts +53 -0
- package/dist/three/frame/density-material.js +353 -0
- package/dist/three/frame/density-material.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +167 -0
- package/dist/three/frame/emission-light.js +655 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/environment-grid-material.d.ts +21 -0
- package/dist/three/frame/environment-grid-material.js +184 -0
- package/dist/three/frame/environment-grid-material.js.map +1 -0
- package/dist/three/frame/environment-material.d.ts +22 -0
- package/dist/three/frame/environment-material.js +87 -0
- package/dist/three/frame/environment-material.js.map +1 -0
- package/dist/three/frame/grid-mip-material.d.ts +12 -0
- package/dist/three/frame/grid-mip-material.js +61 -0
- package/dist/three/frame/grid-mip-material.js.map +1 -0
- package/dist/three/frame/index.d.ts +39 -0
- package/dist/three/frame/index.js +35 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/inject-material.d.ts +56 -0
- package/dist/three/frame/inject-material.js +424 -0
- package/dist/three/frame/inject-material.js.map +1 -0
- package/dist/three/frame/integrate-material.d.ts +26 -0
- package/dist/three/frame/integrate-material.js +198 -0
- package/dist/three/frame/integrate-material.js.map +1 -0
- package/dist/three/frame/layout.d.ts +34 -0
- package/dist/three/frame/layout.js +48 -0
- package/dist/three/frame/layout.js.map +1 -0
- package/dist/three/frame/lighting-material.d.ts +41 -0
- package/dist/three/frame/lighting-material.js +257 -0
- package/dist/three/frame/lighting-material.js.map +1 -0
- package/dist/three/frame/lights.d.ts +11 -0
- package/dist/three/frame/lights.js +16 -0
- package/dist/three/frame/lights.js.map +1 -0
- package/dist/three/frame/medium.d.ts +21 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/neural.d.ts +14 -0
- package/dist/three/frame/neural.js +105 -0
- package/dist/three/frame/neural.js.map +1 -0
- package/dist/three/frame/phase.d.ts +44 -0
- package/dist/three/frame/phase.js +80 -0
- package/dist/three/frame/phase.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +493 -0
- package/dist/three/frame/renderer.js +1498 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/shadow-density-material.d.ts +30 -0
- package/dist/three/frame/shadow-density-material.js +123 -0
- package/dist/three/frame/shadow-density-material.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +18 -0
- package/dist/three/frame/spectrum.js +36 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/temporal-material.d.ts +29 -0
- package/dist/three/frame/temporal-material.js +152 -0
- package/dist/three/frame/temporal-material.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +65 -0
- package/dist/three/frame/three-internals.js +150 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/transmittance-material.d.ts +31 -0
- package/dist/three/frame/transmittance-material.js +315 -0
- package/dist/three/frame/transmittance-material.js.map +1 -0
- package/dist/three/frame/view.d.ts +103 -0
- package/dist/three/frame/view.js +296 -0
- package/dist/three/frame/view.js.map +1 -0
- package/dist/three/frame/volume-shadow-material.d.ts +36 -0
- package/dist/three/frame/volume-shadow-material.js +128 -0
- package/dist/three/frame/volume-shadow-material.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +153 -0
- package/dist/three/frame/volume-shadows.js +756 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +172 -0
- package/dist/three/frame/volume.js +256 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +196 -0
- package/dist/three/grid-node.js +510 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +43 -0
- package/dist/three/index.js +49 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +14 -0
- package/dist/three/internal.js +14 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +112 -0
- package/dist/three/level-set-material.js +204 -0
- package/dist/three/level-set-material.js.map +1 -0
- package/dist/three/material.d.ts +194 -0
- package/dist/three/material.js +359 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +84 -0
- package/dist/three/points.js +130 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sequence.d.ts +317 -0
- package/dist/three/sequence.js +526 -0
- package/dist/three/sequence.js.map +1 -0
- package/dist/three/sparse-source.d.ts +233 -0
- package/dist/three/sparse-source.js +876 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +167 -0
- package/dist/three/volume-source.js +353 -0
- package/dist/three/volume-source.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +97 -0
- package/dist/tools/cpu/compute.js +218 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +72 -0
- package/dist/tools/cpu/level-set.js +261 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +206 -0
- package/dist/tools/cpu/march.js +575 -0
- package/dist/tools/cpu/march.js.map +1 -0
- package/dist/tools/cpu/probe-coords.d.ts +70 -0
- package/dist/tools/cpu/probe-coords.js +116 -0
- package/dist/tools/cpu/probe-coords.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +31 -0
- package/dist/tools/cpu/read-value.js +336 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
- package/dist/tools/cpu/sample-trilinear.js +156 -0
- package/dist/tools/cpu/sample-trilinear.js.map +1 -0
- package/dist/tools/cpu/stride-tables.d.ts +56 -0
- package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
- package/dist/tools/cpu/stride-tables.generated.js +1266 -0
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
- package/dist/tools/cpu/stride-tables.js +78 -0
- package/dist/tools/cpu/stride-tables.js.map +1 -0
- package/dist/tools/errors.d.ts +57 -0
- package/dist/tools/errors.js +58 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +42 -0
- package/dist/tools/frame/blackbody.js +116 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +128 -0
- package/dist/tools/frame/emission.js +282 -0
- package/dist/tools/frame/emission.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +105 -0
- package/dist/tools/frame/environment.js +268 -0
- package/dist/tools/frame/environment.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +302 -0
- package/dist/tools/frame/grid.js +703 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +136 -0
- package/dist/tools/frame/index.js +348 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +61 -0
- package/dist/tools/frame/medium.js +99 -0
- package/dist/tools/frame/medium.js.map +1 -0
- package/dist/tools/frame/mie-table.d.ts +6 -0
- package/dist/tools/frame/mie-table.js +16 -0
- package/dist/tools/frame/mie-table.js.map +1 -0
- package/dist/tools/frame/mie.d.ts +54 -0
- package/dist/tools/frame/mie.js +176 -0
- package/dist/tools/frame/mie.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +9 -0
- package/dist/tools/frame/neural-weights.js +245 -0
- package/dist/tools/frame/neural-weights.js.map +1 -0
- package/dist/tools/frame/neural.d.ts +80 -0
- package/dist/tools/frame/neural.js +150 -0
- package/dist/tools/frame/neural.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +38 -0
- package/dist/tools/frame/pyramid-layout.js +53 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +80 -0
- package/dist/tools/frame/shadows.js +182 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +65 -0
- package/dist/tools/frame/sparse.js +191 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +203 -0
- package/dist/tools/frame/spectral.js +550 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- package/dist/tools/index.d.ts +106 -0
- package/dist/tools/index.js +88 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +46 -0
- package/dist/tools/internal.js +31 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
- package/dist/tools/nanovdb/build-from-vdb.js +92 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +220 -0
- package/dist/tools/nanovdb/bytes.js +345 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
- package/dist/tools/nanovdb/coarse-first.js +86 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +32 -0
- package/dist/tools/nanovdb/index.js +24 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +24 -0
- package/dist/tools/nanovdb/inspect.js +63 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
- package/dist/tools/nanovdb/leaf-codec.js +320 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +43 -0
- package/dist/tools/nanovdb/quantize.js +277 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +160 -0
- package/dist/tools/nanovdb/resample.js +679 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +145 -0
- package/dist/tools/nanovdb/serialize.js +395 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +58 -0
- package/dist/tools/nanovdb/stats.js +149 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +26 -0
- package/dist/tools/nanovdb/transform.js +91 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +175 -0
- package/dist/tools/nanovdb/tree.js +518 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
- package/dist/tools/nanovdb/write-nvdb.js +210 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +195 -0
- package/dist/tools/nvdb-file.js +606 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +138 -0
- package/dist/tools/nvdb-stream.js +365 -0
- package/dist/tools/nvdb-stream.js.map +1 -0
- package/dist/tools/vdb/bit-utils.d.ts +20 -0
- package/dist/tools/vdb/bit-utils.js +42 -0
- package/dist/tools/vdb/bit-utils.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +56 -0
- package/dist/tools/vdb/blosc.js +231 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +40 -0
- package/dist/tools/vdb/byte-reader.js +139 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +73 -0
- package/dist/tools/vdb/compression.js +249 -0
- package/dist/tools/vdb/compression.js.map +1 -0
- package/dist/tools/vdb/errors.d.ts +10 -0
- package/dist/tools/vdb/errors.js +11 -0
- package/dist/tools/vdb/errors.js.map +1 -0
- package/dist/tools/vdb/grid.d.ts +37 -0
- package/dist/tools/vdb/grid.js +147 -0
- package/dist/tools/vdb/grid.js.map +1 -0
- package/dist/tools/vdb/half-float.d.ts +9 -0
- package/dist/tools/vdb/half-float.js +24 -0
- package/dist/tools/vdb/half-float.js.map +1 -0
- package/dist/tools/vdb/index.d.ts +3 -0
- package/dist/tools/vdb/index.js +3 -0
- package/dist/tools/vdb/index.js.map +1 -0
- package/dist/tools/vdb/inflate.d.ts +24 -0
- package/dist/tools/vdb/inflate.js +334 -0
- package/dist/tools/vdb/inflate.js.map +1 -0
- package/dist/tools/vdb/metadata.d.ts +17 -0
- package/dist/tools/vdb/metadata.js +72 -0
- package/dist/tools/vdb/metadata.js.map +1 -0
- package/dist/tools/vdb/parse.d.ts +25 -0
- package/dist/tools/vdb/parse.js +171 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +31 -0
- package/dist/tools/vdb/point-render-data.js +57 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +160 -0
- package/dist/tools/vdb/points.js +794 -0
- package/dist/tools/vdb/points.js.map +1 -0
- package/dist/tools/vdb/transform.d.ts +23 -0
- package/dist/tools/vdb/transform.js +54 -0
- package/dist/tools/vdb/transform.js.map +1 -0
- package/dist/tools/vdb/tree.d.ts +111 -0
- package/dist/tools/vdb/tree.js +228 -0
- package/dist/tools/vdb/tree.js.map +1 -0
- package/dist/tools/vdb/types.d.ts +138 -0
- package/dist/tools/vdb/types.js +3 -0
- package/dist/tools/vdb/types.js.map +1 -0
- package/dist/tools/wvdb/bake.d.ts +116 -0
- package/dist/tools/wvdb/bake.js +311 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +112 -0
- package/dist/tools/wvdb/dense.js +309 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +161 -0
- package/dist/tools/wvdb/format.js +303 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +13 -0
- package/dist/tools/wvdb/index.js +14 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +48 -0
- package/dist/tools/wvdb/level-set.js +153 -0
- package/dist/tools/wvdb/level-set.js.map +1 -0
- package/dist/tools/wvdb/nanovdb.d.ts +54 -0
- package/dist/tools/wvdb/nanovdb.js +60 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +260 -0
- package/dist/tools/wvdb/read.js +743 -0
- package/dist/tools/wvdb/read.js.map +1 -0
- package/dist/tools/wvdb/sha256.d.ts +7 -0
- package/dist/tools/wvdb/sha256.js +76 -0
- package/dist/tools/wvdb/sha256.js.map +1 -0
- package/dist/tools/wvdb/write.d.ts +127 -0
- package/dist/tools/wvdb/write.js +396 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +82 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +85 -0
- package/vendor/pnanovdb.wgsl +1539 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
// Portions derived from mjurczyk/openvdb (MIT), commit 75e7345 (v0.26.0):
|
|
2
|
+
// src/three-openvdb/frame/webgpu/frameMipmaps.js L14–106 (2x2x2 box downsample with clamped edge
|
|
3
|
+
// taps, the mip atlas layout), as an f32 compute pass.
|
|
4
|
+
// Copyright (c) mjurczyk/openvdb contributors. Licensed under the MIT License (see THIRD_PARTY_NOTICES.md).
|
|
5
|
+
// Changes: GPU compute over a pool grid; the base level is the area-weighted box filter of
|
|
6
|
+
// `vdbResampleGrid`; f16 packing is three's `DataUtils.toHalfFloat`. Divergences: DIVERGES.md (K3.2a row).
|
|
7
|
+
import { VDBError } from "../errors.js";
|
|
8
|
+
import { vdbModuleEntries, vdbModuleWgsl } from "../wgsl/generate.js";
|
|
9
|
+
import { checkTarget, COMPUTE_SLOT, USAGE, WORKGROUP_AXIS } from "./shared.js";
|
|
10
|
+
import { vdbBoxPyramidLayout } from "../../tools/frame/pyramid-layout.js";
|
|
11
|
+
const W = WORKGROUP_AXIS;
|
|
12
|
+
const STAGE_COMPUTE = 0x4;
|
|
13
|
+
const TEXTURE_USAGE = { COPY_SRC: 0x1, COPY_DST: 0x2, TEXTURE_BINDING: 0x4 };
|
|
14
|
+
/** Uniform slot stride (minUniformBufferOffsetAlignment's default). */
|
|
15
|
+
const SLOT = 256;
|
|
16
|
+
const PARAMS_BYTES = 96;
|
|
17
|
+
const PARAMS_WGSL = /* wgsl */ `
|
|
18
|
+
struct PyrParams {
|
|
19
|
+
grid: u32,
|
|
20
|
+
srcFromBase: u32,
|
|
21
|
+
srcOffset: u32,
|
|
22
|
+
dstOffset: u32,
|
|
23
|
+
boxMin: vec3i,
|
|
24
|
+
rowWords: u32,
|
|
25
|
+
texels: vec3u,
|
|
26
|
+
blocksX: u32,
|
|
27
|
+
dims: vec3u,
|
|
28
|
+
blocksY: u32,
|
|
29
|
+
srcDims: vec3u,
|
|
30
|
+
pad1: u32,
|
|
31
|
+
atlasDims: vec3u,
|
|
32
|
+
pad2: u32,
|
|
33
|
+
};
|
|
34
|
+
@group(0) @binding(1) var<uniform> pyr: PyrParams;
|
|
35
|
+
@group(1) @binding(0) var<storage, read_write> pyrBase: array<f32>;
|
|
36
|
+
@group(1) @binding(1) var<storage, read_write> pyrAtlas: array<f32>;
|
|
37
|
+
@group(1) @binding(2) var<storage, read_write> pyrFlags: array<atomic<u32>>;
|
|
38
|
+
@group(1) @binding(3) var<storage, read_write> pyrPacked: array<u32>;
|
|
39
|
+
`;
|
|
40
|
+
const KERNELS_WGSL = /* wgsl */ `
|
|
41
|
+
fn pyrBlock(j: vec3u) -> u32 {
|
|
42
|
+
let b = j >> vec3u(3u);
|
|
43
|
+
return b.x + (b.y + b.z * pyr.blocksY) * pyr.blocksX;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Box filter of the voxels under texel j (vdbResampleGrid 'box'): texel j covers [j·T, (j+1)·T] and voxel
|
|
47
|
+
// r covers [r·D, (r+1)·D] in units of 1/D voxel (T texels of the box, D base texels), so overlaps are
|
|
48
|
+
// exact integers and the weights ov / T. Summed x, then y, then z, in the CPU's order.
|
|
49
|
+
@compute @workgroup_size(${W}, ${W}, ${W})
|
|
50
|
+
fn csPyrBase(@builtin(global_invocation_id) j: vec3u) {
|
|
51
|
+
let D = pyr.dims;
|
|
52
|
+
if any(j >= D) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let T = pyr.texels;
|
|
56
|
+
let b0 = j * T;
|
|
57
|
+
let b1 = b0 + T;
|
|
58
|
+
let r0 = b0 / D;
|
|
59
|
+
let r1 = (b1 + D - vec3u(1u)) / D - vec3u(1u);
|
|
60
|
+
let tf = vec3f(T);
|
|
61
|
+
var acc = vdbAccessorInit(pyr.grid);
|
|
62
|
+
// Empty space: when every 8³ cell under the footprint is an inactive tile of value 0 (no leaf), the CPU
|
|
63
|
+
// sum is exactly 0 with no active tap. Skips the voxel loop for most texels of a sparse cloud.
|
|
64
|
+
let c0 = (pyr.boxMin + vec3i(r0)) >> vec3u(3u);
|
|
65
|
+
let c1 = (pyr.boxMin + vec3i(r1)) >> vec3u(3u);
|
|
66
|
+
var empty = true;
|
|
67
|
+
for (var cz = c0.z; cz <= c1.z && empty; cz++) {
|
|
68
|
+
for (var cy = c0.y; cy <= c1.y && empty; cy++) {
|
|
69
|
+
for (var cx = c0.x; cx <= c1.x && empty; cx++) {
|
|
70
|
+
let c = vec3i(cx, cy, cz) * 8;
|
|
71
|
+
empty = vdbGetDim(&acc, c) > 1u && vdbReadValue(&acc, c) == 0.0 && !vdbIsActive(&acc, c);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if empty {
|
|
76
|
+
pyrBase[j.x + (j.y + j.z * D.y) * D.x] = 0.0;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var touched = false;
|
|
80
|
+
var sz = 0.0;
|
|
81
|
+
for (var z = r0.z; z <= r1.z; z++) {
|
|
82
|
+
let wz = f32(min(b1.z, (z + 1u) * D.z) - max(b0.z, z * D.z)) / tf.z;
|
|
83
|
+
var sy = 0.0;
|
|
84
|
+
for (var y = r0.y; y <= r1.y; y++) {
|
|
85
|
+
let wy = f32(min(b1.y, (y + 1u) * D.y) - max(b0.y, y * D.y)) / tf.y;
|
|
86
|
+
var sx = 0.0;
|
|
87
|
+
for (var x = r0.x; x <= r1.x; x++) {
|
|
88
|
+
let wx = f32(min(b1.x, (x + 1u) * D.x) - max(b0.x, x * D.x)) / tf.x;
|
|
89
|
+
let ijk = pyr.boxMin + vec3i(vec3u(x, y, z));
|
|
90
|
+
sx += wx * vdbReadValue(&acc, ijk);
|
|
91
|
+
touched = touched || vdbIsActive(&acc, ijk);
|
|
92
|
+
}
|
|
93
|
+
sy += wy * sx;
|
|
94
|
+
}
|
|
95
|
+
sz += wz * sy;
|
|
96
|
+
}
|
|
97
|
+
pyrBase[j.x + (j.y + j.z * D.y) * D.x] = sz;
|
|
98
|
+
if touched {
|
|
99
|
+
atomicOr(&pyrFlags[pyrBlock(j)], 1u);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Texels of an 8³ block with no active tap read 0 (the CPU drops that leaf; its readout fills 0).
|
|
104
|
+
@compute @workgroup_size(${W}, ${W}, ${W})
|
|
105
|
+
fn csPyrMask(@builtin(global_invocation_id) j: vec3u) {
|
|
106
|
+
let D = pyr.dims;
|
|
107
|
+
if any(j >= D) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if atomicLoad(&pyrFlags[pyrBlock(j)]) == 0u {
|
|
111
|
+
pyrBase[j.x + (j.y + j.z * D.y) * D.x] = 0.0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
fn pyrSrc(x: u32, y: u32, z: u32) -> f32 {
|
|
116
|
+
if pyr.srcFromBase != 0u {
|
|
117
|
+
return pyrBase[x + (y + z * pyr.srcDims.y) * pyr.srcDims.x];
|
|
118
|
+
}
|
|
119
|
+
return pyrAtlas[pyr.srcOffset + x + (y + z * pyr.atlasDims.y) * pyr.atlasDims.x];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// His downsample (frameMipmaps.js): the 2x2x2 mean with edge taps clamped, into the atlas at dstOffset.
|
|
123
|
+
@compute @workgroup_size(${W}, ${W}, ${W})
|
|
124
|
+
fn csPyrLevel(@builtin(global_invocation_id) p: vec3u) {
|
|
125
|
+
if any(p >= pyr.dims) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let s = pyr.srcDims - vec3u(1u);
|
|
129
|
+
let x0 = min(p.x * 2u, s.x);
|
|
130
|
+
let x1 = min(p.x * 2u + 1u, s.x);
|
|
131
|
+
let y0 = min(p.y * 2u, s.y);
|
|
132
|
+
let y1 = min(p.y * 2u + 1u, s.y);
|
|
133
|
+
let z0 = min(p.z * 2u, s.z);
|
|
134
|
+
let z1 = min(p.z * 2u + 1u, s.z);
|
|
135
|
+
let sum = pyrSrc(x0, y0, z0) + pyrSrc(x1, y0, z0) + pyrSrc(x0, y1, z0) + pyrSrc(x1, y1, z0)
|
|
136
|
+
+ pyrSrc(x0, y0, z1) + pyrSrc(x1, y0, z1) + pyrSrc(x0, y1, z1) + pyrSrc(x1, y1, z1);
|
|
137
|
+
pyrAtlas[pyr.dstOffset + p.x + (p.y + p.z * pyr.atlasDims.y) * pyr.atlasDims.x] = sum / 8.0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// three's DataUtils.toHalfFloat (fox-toolkit tables: truncation, denormals, overflow to infinity).
|
|
141
|
+
fn pyrHalf(v: f32) -> u32 {
|
|
142
|
+
let f = bitcast<u32>(clamp(v, -65504.0, 65504.0));
|
|
143
|
+
let e = i32((f >> 23u) & 0xffu) - 127;
|
|
144
|
+
var base = 0u;
|
|
145
|
+
var shift = 24u;
|
|
146
|
+
if e < -27 {
|
|
147
|
+
base = 0u;
|
|
148
|
+
shift = 24u;
|
|
149
|
+
} else if e < -14 {
|
|
150
|
+
base = 0x400u >> u32(-e - 14);
|
|
151
|
+
shift = u32(-e - 1);
|
|
152
|
+
} else if e <= 15 {
|
|
153
|
+
base = u32(e + 15) << 10u;
|
|
154
|
+
shift = 13u;
|
|
155
|
+
} else if e < 128 {
|
|
156
|
+
base = 0x7c00u;
|
|
157
|
+
shift = 24u;
|
|
158
|
+
} else {
|
|
159
|
+
base = 0x7c00u;
|
|
160
|
+
shift = 13u;
|
|
161
|
+
}
|
|
162
|
+
if (f & 0x80000000u) != 0u {
|
|
163
|
+
base = base | 0x8000u;
|
|
164
|
+
}
|
|
165
|
+
return base + ((f & 0x7fffffu) >> shift);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Two texels per word, rows of rowWords words (bytesPerRow multiple of 256), at dstOffset words.
|
|
169
|
+
@compute @workgroup_size(${W}, ${W}, ${W})
|
|
170
|
+
fn csPyrPack(@builtin(global_invocation_id) p: vec3u) {
|
|
171
|
+
let size = pyr.srcDims;
|
|
172
|
+
let words = (size.x + 1u) / 2u;
|
|
173
|
+
if p.x >= words || p.y >= size.y || p.z >= size.z {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
let x = p.x * 2u;
|
|
177
|
+
var lo = 0u;
|
|
178
|
+
var hi = 0u;
|
|
179
|
+
if pyr.srcFromBase != 0u {
|
|
180
|
+
let row = (p.y + p.z * size.y) * size.x;
|
|
181
|
+
lo = pyrHalf(pyrBase[row + x]);
|
|
182
|
+
if x + 1u < size.x {
|
|
183
|
+
hi = pyrHalf(pyrBase[row + x + 1u]);
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
let row = (p.y + p.z * size.y) * size.x;
|
|
187
|
+
lo = pyrHalf(pyrAtlas[row + x]);
|
|
188
|
+
if x + 1u < size.x {
|
|
189
|
+
hi = pyrHalf(pyrAtlas[row + x + 1u]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
pyrPacked[pyr.dstOffset + (p.y + p.z * size.y) * pyr.rowWords + p.x] = lo | (hi << 16u);
|
|
193
|
+
}
|
|
194
|
+
`;
|
|
195
|
+
/** The WGSL of the pyramid kernels for grids of `type` (exported for tests and the size of the shader). */
|
|
196
|
+
export function boxPyramidWgsl(type) {
|
|
197
|
+
return `${vdbModuleWgsl({ slot: COMPUTE_SLOT, types: [type], profile: "march" })}\n${PARAMS_WGSL}\n${KERNELS_WGSL}`;
|
|
198
|
+
}
|
|
199
|
+
const pipelines = new WeakMap();
|
|
200
|
+
function pyramidPipelines(device, type) {
|
|
201
|
+
let byType = pipelines.get(device);
|
|
202
|
+
if (!byType)
|
|
203
|
+
pipelines.set(device, (byType = new Map()));
|
|
204
|
+
const cached = byType.get(type);
|
|
205
|
+
if (cached)
|
|
206
|
+
return cached;
|
|
207
|
+
device.pushErrorScope("validation");
|
|
208
|
+
const group0 = device.createBindGroupLayout({
|
|
209
|
+
label: `vdb boxPyramid ${type} group 0`,
|
|
210
|
+
entries: [
|
|
211
|
+
...vdbModuleEntries({ slot: COMPUTE_SLOT, visibility: STAGE_COMPUTE }),
|
|
212
|
+
{ binding: 1, visibility: STAGE_COMPUTE, buffer: { type: "uniform", hasDynamicOffset: true, minBindingSize: PARAMS_BYTES } },
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
const group1 = device.createBindGroupLayout({
|
|
216
|
+
label: `vdb boxPyramid ${type} group 1`,
|
|
217
|
+
entries: [0, 1, 2, 3].map((binding) => ({ binding, visibility: STAGE_COMPUTE, buffer: { type: "storage" } })),
|
|
218
|
+
});
|
|
219
|
+
const module = device.createShaderModule({ label: `vdb boxPyramid ${type}`, code: boxPyramidWgsl(type) });
|
|
220
|
+
const layout = device.createPipelineLayout({ bindGroupLayouts: [group0, group1] });
|
|
221
|
+
const make = (entryPoint) => device.createComputePipeline({ label: `vdb boxPyramid ${entryPoint} ${type}`, layout, compute: { module, entryPoint } });
|
|
222
|
+
const p = {
|
|
223
|
+
base: make("csPyrBase"),
|
|
224
|
+
mask: make("csPyrMask"),
|
|
225
|
+
level: make("csPyrLevel"),
|
|
226
|
+
pack: make("csPyrPack"),
|
|
227
|
+
group0,
|
|
228
|
+
group1,
|
|
229
|
+
error: device.popErrorScope(),
|
|
230
|
+
};
|
|
231
|
+
byType.set(type, p);
|
|
232
|
+
return p;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* @internal Compiles (once per device and type, cached) the pyramid pipelines for grids of `types`, so a later
|
|
236
|
+
* pyramid over a grid of one of them (G16a: a sparse source following a coarse-first swap to another grid type)
|
|
237
|
+
* creates no pipeline. Returns the pipelines' validation results.
|
|
238
|
+
*/
|
|
239
|
+
export function warmBoxPyramidPipelines(device, types) {
|
|
240
|
+
return [...types].map((type) => pyramidPipelines(device, type).error);
|
|
241
|
+
}
|
|
242
|
+
const align = (n, a) => Math.ceil(n / a) * a;
|
|
243
|
+
const bad = (message) => {
|
|
244
|
+
throw new VDBError("VDB_BAD_OPTION", `vdbCreateBoxPyramid: ${message}`);
|
|
245
|
+
};
|
|
246
|
+
class BoxPyramidGpu {
|
|
247
|
+
gridId;
|
|
248
|
+
layout;
|
|
249
|
+
base;
|
|
250
|
+
atlas;
|
|
251
|
+
gpuBytes;
|
|
252
|
+
builtRevision = null;
|
|
253
|
+
error;
|
|
254
|
+
#device;
|
|
255
|
+
#pool;
|
|
256
|
+
#boxMin;
|
|
257
|
+
#owned = [];
|
|
258
|
+
#baseF32;
|
|
259
|
+
#atlasF32;
|
|
260
|
+
#flags;
|
|
261
|
+
#packed;
|
|
262
|
+
#params;
|
|
263
|
+
#rows;
|
|
264
|
+
#blocks;
|
|
265
|
+
#group1 = null;
|
|
266
|
+
#destroyed = false;
|
|
267
|
+
constructor(device, pool, gridId, o) {
|
|
268
|
+
if (!device || typeof device.createBuffer !== "function")
|
|
269
|
+
bad("expected a GPUDevice as the first argument.");
|
|
270
|
+
if (!pool || typeof pool.info !== "function")
|
|
271
|
+
bad("expected a VDBGridPool as the second argument.");
|
|
272
|
+
if (pool.device !== device)
|
|
273
|
+
bad("the pool lives on a different GPUDevice. Pass pool.device.");
|
|
274
|
+
// Residency is checked when a build is recorded; creating needs only the grid's info.
|
|
275
|
+
const info = pool.info(gridId);
|
|
276
|
+
const box = o.indexBox ?? info.indexBBox;
|
|
277
|
+
const texels = [0, 1, 2].map((a) => box.max[a] - box.min[a] + 1);
|
|
278
|
+
if (texels.some((t) => !(t > 0) || !Number.isInteger(t)))
|
|
279
|
+
bad(`empty or non-integer index box ${JSON.stringify(box)}.`);
|
|
280
|
+
this.layout = vdbBoxPyramidLayout(texels, { ...(o.pyramidMax !== undefined ? { pyramidMax: o.pyramidMax } : {}), ...(o.level !== undefined ? { level: o.level } : {}) });
|
|
281
|
+
this.#device = device;
|
|
282
|
+
this.#pool = pool;
|
|
283
|
+
this.gridId = gridId;
|
|
284
|
+
this.#boxMin = [box.min[0], box.min[1], box.min[2]];
|
|
285
|
+
const label = o.label ?? `vdb boxPyramid grid ${gridId}`;
|
|
286
|
+
const { dimensions: dims, atlas } = this.layout;
|
|
287
|
+
const baseCount = dims[0] * dims[1] * dims[2];
|
|
288
|
+
const atlasCount = atlas ? atlas.dimensions[0] * atlas.dimensions[1] * atlas.dimensions[2] : 0;
|
|
289
|
+
if (o.targets) {
|
|
290
|
+
const check = (t, want, what) => {
|
|
291
|
+
if (!want) {
|
|
292
|
+
if (t)
|
|
293
|
+
bad(`targets.${what} must be null: the layout has no ${what}.`);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (!t)
|
|
297
|
+
return bad(`targets.${what} is missing (the layout has one, ${want.join("x")}).`);
|
|
298
|
+
if (t.format !== "r16float" || t.width !== want[0] || t.height !== want[1] || t.depthOrArrayLayers !== want[2] || (t.usage & TEXTURE_USAGE.COPY_DST) === 0) {
|
|
299
|
+
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}).`);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
check(o.targets.base, dims, "base");
|
|
303
|
+
check(o.targets.atlas, atlas?.dimensions ?? null, "atlas");
|
|
304
|
+
this.base = o.targets.base;
|
|
305
|
+
this.atlas = o.targets.atlas;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
const texture = (size, what) => {
|
|
309
|
+
const t = device.createTexture({
|
|
310
|
+
label: `${label} ${what}`,
|
|
311
|
+
size: [size[0], size[1], size[2]],
|
|
312
|
+
dimension: "3d",
|
|
313
|
+
format: "r16float",
|
|
314
|
+
usage: TEXTURE_USAGE.TEXTURE_BINDING | TEXTURE_USAGE.COPY_DST | TEXTURE_USAGE.COPY_SRC,
|
|
315
|
+
});
|
|
316
|
+
this.#owned.push(t);
|
|
317
|
+
return t;
|
|
318
|
+
};
|
|
319
|
+
this.base = texture(dims, "base");
|
|
320
|
+
this.atlas = atlas ? texture(atlas.dimensions, "atlas") : null;
|
|
321
|
+
}
|
|
322
|
+
const rowWords = (w) => align(w * 2, 256) / 4;
|
|
323
|
+
const baseWords = rowWords(dims[0]) * dims[1] * dims[2];
|
|
324
|
+
const atlasWords = atlas ? rowWords(atlas.dimensions[0]) * atlas.dimensions[1] * atlas.dimensions[2] : 0;
|
|
325
|
+
this.#rows = { base: rowWords(dims[0]), atlas: atlas ? rowWords(atlas.dimensions[0]) : 0, atlasOffset: align(baseWords, 64) };
|
|
326
|
+
this.#blocks = [Math.ceil(dims[0] / 8), Math.ceil(dims[1] / 8), Math.ceil(dims[2] / 8)];
|
|
327
|
+
const buffer = (size, usage, what) => {
|
|
328
|
+
const b = device.createBuffer({ label: `${label} ${what}`, size: align(Math.max(4, size), 4), usage });
|
|
329
|
+
this.#owned.push(b);
|
|
330
|
+
return b;
|
|
331
|
+
};
|
|
332
|
+
this.#baseF32 = buffer(baseCount * 4, USAGE.STORAGE, "base f32");
|
|
333
|
+
this.#atlasF32 = buffer(atlasCount * 4, USAGE.STORAGE | USAGE.COPY_DST, "atlas f32");
|
|
334
|
+
this.#flags = buffer(this.#blocks[0] * this.#blocks[1] * this.#blocks[2] * 4, USAGE.STORAGE | USAGE.COPY_DST, "block flags");
|
|
335
|
+
this.#packed = buffer((this.#rows.atlasOffset + atlasWords) * 4, USAGE.STORAGE | USAGE.COPY_SRC, "packed f16");
|
|
336
|
+
const slots = 4 + (atlas?.levels.length ?? 0);
|
|
337
|
+
this.#params = buffer(slots * SLOT, USAGE.UNIFORM | USAGE.COPY_DST, "params");
|
|
338
|
+
this.gpuBytes = {
|
|
339
|
+
textures: 2 * (baseCount + atlasCount),
|
|
340
|
+
scratch: [this.#baseF32, this.#atlasF32, this.#flags, this.#packed, this.#params].reduce((s, b) => s + b.size, 0),
|
|
341
|
+
};
|
|
342
|
+
this.error = pyramidPipelines(device, info.type).error;
|
|
343
|
+
this.#writeParams();
|
|
344
|
+
}
|
|
345
|
+
get stale() {
|
|
346
|
+
if (this.#destroyed)
|
|
347
|
+
return false;
|
|
348
|
+
return this.builtRevision === null || this.#pool.info(this.gridId).imageRevision !== this.builtRevision;
|
|
349
|
+
}
|
|
350
|
+
/** Per-dispatch parameter slots: 0 base/mask, 1 pack base, 2 pack atlas, 3.. levels. */
|
|
351
|
+
#writeParams() {
|
|
352
|
+
const { dimensions: dims, atlas, texels } = this.layout;
|
|
353
|
+
const slots = 4 + (atlas?.levels.length ?? 0);
|
|
354
|
+
const bytes = new ArrayBuffer(slots * SLOT);
|
|
355
|
+
const put = (slot, p) => {
|
|
356
|
+
const u = new Uint32Array(bytes, slot * SLOT, PARAMS_BYTES / 4);
|
|
357
|
+
const i = new Int32Array(bytes, slot * SLOT, PARAMS_BYTES / 4);
|
|
358
|
+
u[0] = this.gridId;
|
|
359
|
+
u[1] = p.srcFromBase ?? 0;
|
|
360
|
+
u[2] = p.srcOffset ?? 0;
|
|
361
|
+
u[3] = p.dstOffset ?? 0;
|
|
362
|
+
for (let a = 0; a < 3; a++) {
|
|
363
|
+
i[4 + a] = this.#boxMin[a];
|
|
364
|
+
u[8 + a] = texels[a];
|
|
365
|
+
u[12 + a] = p.dims[a];
|
|
366
|
+
u[16 + a] = p.srcDims?.[a] ?? 0;
|
|
367
|
+
u[20 + a] = atlas?.dimensions[a] ?? 1;
|
|
368
|
+
}
|
|
369
|
+
u[7] = p.rowWords ?? 0;
|
|
370
|
+
u[11] = this.#blocks[0];
|
|
371
|
+
u[15] = this.#blocks[1];
|
|
372
|
+
};
|
|
373
|
+
put(0, { dims });
|
|
374
|
+
put(1, { srcFromBase: 1, rowWords: this.#rows.base, dims, srcDims: dims });
|
|
375
|
+
if (atlas) {
|
|
376
|
+
put(2, { srcFromBase: 0, rowWords: this.#rows.atlas, dstOffset: this.#rows.atlasOffset, dims: atlas.dimensions, srcDims: atlas.dimensions });
|
|
377
|
+
atlas.levels.forEach((level, l) => {
|
|
378
|
+
const below = l === 0 ? { offset: 0, dimensions: dims } : atlas.levels[l - 1];
|
|
379
|
+
put(3 + l, { srcFromBase: l === 0 ? 1 : 0, srcOffset: below.offset, dstOffset: level.offset, dims: level.dimensions, srcDims: below.dimensions });
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
this.#device.queue.writeBuffer(this.#params, 0, bytes);
|
|
383
|
+
}
|
|
384
|
+
record(encoder, options = {}) {
|
|
385
|
+
if (this.#destroyed)
|
|
386
|
+
throw new VDBError("VDB_DISPOSED", "vdbCreateBoxPyramid: record() after destroy().");
|
|
387
|
+
const info = checkTarget("vdbCreateBoxPyramid", this.#device, this.#pool, this.gridId);
|
|
388
|
+
const p = pyramidPipelines(this.#device, info.type);
|
|
389
|
+
// Group 0 names the pool's current buffer: rebuilt every record (a growth replaces it).
|
|
390
|
+
const group0 = this.#device.createBindGroup({
|
|
391
|
+
layout: p.group0,
|
|
392
|
+
entries: [this.#pool.bindGroupEntry(COMPUTE_SLOT), { binding: 1, resource: { buffer: this.#params, size: PARAMS_BYTES } }],
|
|
393
|
+
});
|
|
394
|
+
this.#group1 ??= this.#device.createBindGroup({
|
|
395
|
+
layout: p.group1,
|
|
396
|
+
entries: [this.#baseF32, this.#atlasF32, this.#flags, this.#packed].map((buffer, binding) => ({ binding, resource: { buffer } })),
|
|
397
|
+
});
|
|
398
|
+
const { dimensions: dims, atlas } = this.layout;
|
|
399
|
+
const groups = (size) => [Math.ceil(size[0] / W), Math.ceil(size[1] / W), Math.ceil(size[2] / W)];
|
|
400
|
+
encoder.clearBuffer(this.#flags);
|
|
401
|
+
if (atlas)
|
|
402
|
+
encoder.clearBuffer(this.#atlasF32);
|
|
403
|
+
const pass = encoder.beginComputePass({ label: "vdb boxPyramid", ...(options.timestampWrites ? { timestampWrites: options.timestampWrites } : {}) });
|
|
404
|
+
pass.setBindGroup(1, this.#group1);
|
|
405
|
+
const dispatch = (pipeline, slot, size) => {
|
|
406
|
+
pass.setPipeline(pipeline);
|
|
407
|
+
pass.setBindGroup(0, group0, [slot * SLOT]);
|
|
408
|
+
pass.dispatchWorkgroups(...groups(size));
|
|
409
|
+
};
|
|
410
|
+
dispatch(p.base, 0, dims);
|
|
411
|
+
dispatch(p.mask, 0, dims);
|
|
412
|
+
atlas?.levels.forEach((level, l) => dispatch(p.level, 3 + l, level.dimensions));
|
|
413
|
+
dispatch(p.pack, 1, [Math.ceil(dims[0] / 2), dims[1], dims[2]]);
|
|
414
|
+
if (atlas)
|
|
415
|
+
dispatch(p.pack, 2, [Math.ceil(atlas.dimensions[0] / 2), atlas.dimensions[1], atlas.dimensions[2]]);
|
|
416
|
+
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]]);
|
|
418
|
+
if (atlas && this.atlas) {
|
|
419
|
+
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]);
|
|
421
|
+
}
|
|
422
|
+
this.builtRevision = info.imageRevision;
|
|
423
|
+
}
|
|
424
|
+
update(encoder) {
|
|
425
|
+
if (this.#destroyed)
|
|
426
|
+
return false;
|
|
427
|
+
const info = this.#pool.info(this.gridId);
|
|
428
|
+
if (!info.resident || info.imageRevision === this.builtRevision)
|
|
429
|
+
return false;
|
|
430
|
+
this.record(encoder);
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
destroy() {
|
|
434
|
+
if (this.#destroyed)
|
|
435
|
+
return;
|
|
436
|
+
this.#destroyed = true;
|
|
437
|
+
for (const r of this.#owned)
|
|
438
|
+
r.destroy();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Creates the coarse pyramid of pool grid `gridId` on the GPU (see the file comment) and returns it
|
|
443
|
+
* unbuilt: record the build with `pyramid.record(encoder)` (the grid must be resident), submit, and
|
|
444
|
+
* rebuild with `pyramid.update(encoder)` after the grid's image changes (`imageRevision`). The pool
|
|
445
|
+
* must live on `device`. Frees only what it allocated (`destroy()`).
|
|
446
|
+
*
|
|
447
|
+
* const pyramid = vdbCreateBoxPyramid(device, pool, id);
|
|
448
|
+
* pool.update(encoder);
|
|
449
|
+
* pyramid.update(encoder); // first build, then only on a replace
|
|
450
|
+
* device.queue.submit([encoder.finish()]);
|
|
451
|
+
*/
|
|
452
|
+
export function vdbCreateBoxPyramid(device, pool, gridId, options = {}) {
|
|
453
|
+
return new BoxPyramidGpu(device, pool, gridId, options);
|
|
454
|
+
}
|
|
455
|
+
//# sourceMappingURL=pyramid.js.map
|
|
@@ -0,0 +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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CAAC,CAAC,OAAO,EAAE,CAAC;IAC3C,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAiB,EAAE,IAAiB,EAAE,MAAc,EAAE,UAAmC,EAAE;IAC7H,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1D,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 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"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { VDBGridInfo, VDBGridPool } from "../pool/pool.js";
|
|
2
|
+
import type { VDBGridTypeName, VDBSlot } from "../types.js";
|
|
3
|
+
/** Where the compute kernels bind the pool. */
|
|
4
|
+
export declare const COMPUTE_SLOT: VDBSlot;
|
|
5
|
+
/** Threads per workgroup per axis (4 x 4 x 4 = 64). */
|
|
6
|
+
export declare const WORKGROUP_AXIS = 4;
|
|
7
|
+
/** WebGPU flag values, restated so the core loads where the globals don't exist (Node). */
|
|
8
|
+
export declare const USAGE: {
|
|
9
|
+
readonly MAP_READ: 1;
|
|
10
|
+
readonly COPY_SRC: 4;
|
|
11
|
+
readonly COPY_DST: 8;
|
|
12
|
+
readonly UNIFORM: 64;
|
|
13
|
+
readonly STORAGE: 128;
|
|
14
|
+
};
|
|
15
|
+
declare const MAP_MODE_READ = 1;
|
|
16
|
+
/** Bytes of `CsParams` below. */
|
|
17
|
+
export declare const PARAMS_BYTES = 80;
|
|
18
|
+
/**
|
|
19
|
+
* Uniform parameters shared by every kernel (`CsParams`, 80 B):
|
|
20
|
+
* `grid, bins, filter, _` u32 at 0..15; `regionMin` vec3i at 16; `regionSize`
|
|
21
|
+
* vec3u at 32; `dims` vec3u at 48; `range` vec2f at 64.
|
|
22
|
+
*/
|
|
23
|
+
export interface KernelParams {
|
|
24
|
+
grid: number;
|
|
25
|
+
bins?: number;
|
|
26
|
+
filter?: number;
|
|
27
|
+
regionMin: readonly [number, number, number];
|
|
28
|
+
regionSize: readonly [number, number, number];
|
|
29
|
+
dims?: readonly [number, number, number];
|
|
30
|
+
range?: {
|
|
31
|
+
min: number;
|
|
32
|
+
max: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** A kernel: its footer WGSL (after the module and `CsParams`) and its group-1 output bindings. */
|
|
36
|
+
export interface KernelSource {
|
|
37
|
+
readonly entryPoint: string;
|
|
38
|
+
readonly footer: string;
|
|
39
|
+
readonly outputs: number;
|
|
40
|
+
}
|
|
41
|
+
interface CachedPipeline {
|
|
42
|
+
pipeline: GPUComputePipeline;
|
|
43
|
+
group0: GPUBindGroupLayout;
|
|
44
|
+
group1: GPUBindGroupLayout;
|
|
45
|
+
/** Validation result of the module + pipeline creation (null = valid). */
|
|
46
|
+
error: Promise<GPUError | null>;
|
|
47
|
+
}
|
|
48
|
+
/** The full WGSL of `kernel` for grids of `type` (exported for tests and the size of the shader). */
|
|
49
|
+
export declare function kernelWgsl(kernel: KernelSource, type: VDBGridTypeName): string;
|
|
50
|
+
/** The compute pipeline of `kernel` for `type` on `device`, created once per device. */
|
|
51
|
+
export declare function kernelPipeline(device: GPUDevice, kernel: KernelSource, type: VDBGridTypeName): CachedPipeline;
|
|
52
|
+
/** Checks `device` / `pool` / `gridId` and returns the grid's info. */
|
|
53
|
+
export declare function checkTarget(where: string, device: GPUDevice, pool: VDBGridPool, gridId: number): VDBGridInfo;
|
|
54
|
+
/** Checks a positive integer option. */
|
|
55
|
+
export declare function checkPositiveInt(where: string, name: string, value: number): void;
|
|
56
|
+
/** Creates a buffer with initial contents (mapped at creation, no queue write). */
|
|
57
|
+
export declare function createInitialized(device: GPUDevice, label: string, usage: number, data: ArrayBufferView, size?: number): GPUBuffer;
|
|
58
|
+
export declare function align4(n: number): number;
|
|
59
|
+
/** The packed `CsParams` bytes. */
|
|
60
|
+
export declare function packParams(p: KernelParams): ArrayBuffer;
|
|
61
|
+
/** Workgroup counts covering `size` threads per axis. */
|
|
62
|
+
export declare function workgroups(size: readonly [number, number, number]): [number, number, number];
|
|
63
|
+
/**
|
|
64
|
+
* Pending GPU work with a CPU result. Created by `gridStats` / `decodeToAtlas`
|
|
65
|
+
* after their passes are recorded.
|
|
66
|
+
*
|
|
67
|
+
* Order of calls:
|
|
68
|
+
* - **No `encoder` option** (the tool created and submitted its own): call
|
|
69
|
+
* {@link read} at any time.
|
|
70
|
+
* - **Host `encoder`**: the work sits in the host's encoder until the host
|
|
71
|
+
* submits it. Submit, then call {@link submitted}, then {@link read}:
|
|
72
|
+
*
|
|
73
|
+
* const job = gridStats(device, pool, id, { encoder });
|
|
74
|
+
* device.queue.submit([encoder.finish()]);
|
|
75
|
+
* const stats = await job.submitted().read();
|
|
76
|
+
*
|
|
77
|
+
* `read()` before `submitted()` rejects with `VDB_BAD_OPTION` and touches
|
|
78
|
+
* nothing: mapping (or freeing) the tool's buffers before the submit would
|
|
79
|
+
* make that submit fail validation ("used in submit while destroyed" /
|
|
80
|
+
* "mapped").
|
|
81
|
+
*
|
|
82
|
+
* `read()` maps the readback, frees every buffer the tool allocated and
|
|
83
|
+
* resolves with the result; keep it outside timed regions. Call
|
|
84
|
+
* {@link dispose} instead to drop the work without reading it (after its
|
|
85
|
+
* submit, or with the encoder discarded).
|
|
86
|
+
*/
|
|
87
|
+
export interface VDBReadback<T> {
|
|
88
|
+
/**
|
|
89
|
+
* Tells the job the host submitted the encoder it recorded into; returns
|
|
90
|
+
* the job (`job.submitted().read()`). A no-op for work the tool submitted
|
|
91
|
+
* itself.
|
|
92
|
+
*/
|
|
93
|
+
submitted(): this;
|
|
94
|
+
/**
|
|
95
|
+
* Maps the result and frees the tool's buffers. With a host `encoder`,
|
|
96
|
+
* call {@link submitted} first (else rejects with `VDB_BAD_OPTION`).
|
|
97
|
+
*/
|
|
98
|
+
read(): Promise<T>;
|
|
99
|
+
dispose(): void;
|
|
100
|
+
}
|
|
101
|
+
/** Owns the buffers of one tool call; frees exactly those. */
|
|
102
|
+
export declare class ComputeJob<T> implements VDBReadback<T> {
|
|
103
|
+
#private;
|
|
104
|
+
constructor(where: string, owned: GPUBuffer[], staging: GPUBuffer | null, error: Promise<GPUError | null>, finish: (bytes: ArrayBuffer) => T, selfSubmitted?: boolean);
|
|
105
|
+
submitted(): this;
|
|
106
|
+
read(): Promise<T>;
|
|
107
|
+
dispose(): void;
|
|
108
|
+
}
|
|
109
|
+
/** Creates an encoder when the host gave none; `submit` submits it only then. */
|
|
110
|
+
export declare function hostEncoder(device: GPUDevice, given: GPUCommandEncoder | undefined, label: string): {
|
|
111
|
+
encoder: GPUCommandEncoder;
|
|
112
|
+
submit(): void;
|
|
113
|
+
readonly selfSubmitted: boolean;
|
|
114
|
+
};
|
|
115
|
+
export { MAP_MODE_READ };
|