@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,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WGSL module generator (docs/dev/design/K1-core.md §3, task K1.4a).
|
|
3
|
+
*
|
|
4
|
+
* Roots for the profile and options (the vendored names the API layer uses)
|
|
5
|
+
* -> closure over the declaration table extracted from the unmodified vendored
|
|
6
|
+
* `pnanovdb.wgsl` -> generation transforms -> `pnanovdb_`→`vdb_` rename ->
|
|
7
|
+
* append the API layer -> prepend one SPDX line.
|
|
8
|
+
*
|
|
9
|
+
* Generation transforms (each one is a row in vendor/VENDOR.md, "Generation
|
|
10
|
+
* transforms"; none edits the vendored file):
|
|
11
|
+
* 1. `pnanovdb_buf_read_uint32` reads through `vdb_load`, the module's single
|
|
12
|
+
* buffer access site (§2).
|
|
13
|
+
* 2. The 27-row `pnanovdb_grid_type_constants` array becomes
|
|
14
|
+
* `fn vdb_gtc(grid_type)` returning only the compiled types' rows; its
|
|
15
|
+
* `[grid_type]` call sites become `vdb_gtc(grid_type)`.
|
|
16
|
+
* 3. `pnanovdb_read_float_typed` keeps only the compiled types' branches, so
|
|
17
|
+
* the other decoders drop out of the closure.
|
|
18
|
+
* 4. Declarations unreachable from the profile's roots are not emitted (the
|
|
19
|
+
* `pnanovdb_sample_trilinear_{float,fp8,fpn}` wrappers among them).
|
|
20
|
+
* 5. Every `pnanovdb_` / `PNANOVDB_` becomes `vdb_` / `VDB_`.
|
|
21
|
+
* 6. Comments are dropped (done at extraction).
|
|
22
|
+
* 7. `pnanovdb_leaf_get_stat_float` keeps only the compiled types' branch
|
|
23
|
+
* (the Fp leaf-stats decode, K1.4b), so a Float-only module has no
|
|
24
|
+
* uint16 decoder.
|
|
25
|
+
*
|
|
26
|
+
* Output is deterministic: the same options give the same bytes, and `types`
|
|
27
|
+
* is a set (order and duplicates do not matter).
|
|
28
|
+
*/
|
|
29
|
+
import { type VDBSlot } from "../types.js";
|
|
30
|
+
import type { VDBModuleOptions, VDBModulePoolLike, VDBModuleTypeCheck } from "./types.js";
|
|
31
|
+
/** First line of every generated module (§3.3). */
|
|
32
|
+
export declare const VDB_MODULE_BANNER = "// SPDX-License-Identifier: Apache-2.0 AND MIT. Derived from PNanoVDB.h (OpenVDB) via emcfarlane/webgpu-nanovdb; see NOTICE.";
|
|
33
|
+
/** Name of the storage binding `slot` mode declares. */
|
|
34
|
+
export declare const VDB_POOL_BINDING_NAME = "vdbPool";
|
|
35
|
+
/**
|
|
36
|
+
* Generate a WGSL module for the pool (docs/dev/design/K1-core.md §3.1).
|
|
37
|
+
* Deterministic: the same options give the same string.
|
|
38
|
+
*
|
|
39
|
+
* `types` must cover every grid type the host may add to the pool, not just
|
|
40
|
+
* the ones present now: a grid of a type the module wasn't generated for reads
|
|
41
|
+
* as 0. Either generate for every type up front (`VDB_ALL_SCALAR_TYPES`, or
|
|
42
|
+
* the host's known set) or regenerate the module and rebuild the pipeline when
|
|
43
|
+
* `vdbCheckModule(pool, options)` throws `VDB_TYPE_NOT_COMPILED` after an `add`.
|
|
44
|
+
*
|
|
45
|
+
* @throws VDBError `VDB_BAD_OPTION` for invalid options.
|
|
46
|
+
*/
|
|
47
|
+
export declare function vdbModuleWgsl(options: VDBModuleOptions): string;
|
|
48
|
+
/**
|
|
49
|
+
* The bind group layout entries a `slot` module declares: one read-only
|
|
50
|
+
* storage buffer at `slot.firstBinding` (layout 1).
|
|
51
|
+
*
|
|
52
|
+
* Takes the same `VDBSlot` as `vdbModuleWgsl({ slot })` and
|
|
53
|
+
* `pool.bindGroupEntry(slot)`, either bare or as `{ slot, visibility }`.
|
|
54
|
+
* `visibility` defaults to `GPUShaderStage.COMPUTE | GPUShaderStage.FRAGMENT`
|
|
55
|
+
* (read-only storage is legal in both stages), so render and compute hosts
|
|
56
|
+
* both work without it; pass it to narrow the layout.
|
|
57
|
+
*
|
|
58
|
+
* @throws VDBError `VDB_BAD_OPTION` for a malformed slot.
|
|
59
|
+
*/
|
|
60
|
+
export declare function vdbModuleEntries(slotOrOptions: VDBSlot | {
|
|
61
|
+
readonly slot: VDBSlot;
|
|
62
|
+
readonly visibility?: GPUShaderStageFlags | undefined;
|
|
63
|
+
}): GPUBindGroupLayoutEntry[];
|
|
64
|
+
/**
|
|
65
|
+
* Check that a module generated with `options` can read every grid in `pool`.
|
|
66
|
+
*
|
|
67
|
+
* `options` is either the full `vdbModuleWgsl` options (validated as such) or
|
|
68
|
+
* just `{ types, layoutVersion? }` for a type/layout-only check, e.g. from an
|
|
69
|
+
* engine adapter that builds its module elsewhere. `layoutVersion` is the
|
|
70
|
+
* layout the module targets (default: this generator's,
|
|
71
|
+
* `VDB_GPU_LAYOUT_VERSION`).
|
|
72
|
+
*
|
|
73
|
+
* After every `pool.add`: a module must be generated for every type the host
|
|
74
|
+
* may add, or regenerated and its pipeline rebuilt.
|
|
75
|
+
*
|
|
76
|
+
* @throws VDBError `VDB_LAYOUT_MISMATCH` if the pool's layout is not the one
|
|
77
|
+
* the module targets; `VDB_TYPE_NOT_COMPILED` if the pool holds a grid
|
|
78
|
+
* type the module would not decode; `VDB_BAD_OPTION` for invalid options.
|
|
79
|
+
*/
|
|
80
|
+
export declare function vdbCheckModule(pool: VDBModulePoolLike, options: VDBModuleOptions | VDBModuleTypeCheck): void;
|
|
81
|
+
/** @internal Vendored declarations (vendored names) a module with these options includes, in file order. For tests. */
|
|
82
|
+
export declare function vdbModuleDeclarations(options: VDBModuleOptions): string[];
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WGSL module generator (docs/dev/design/K1-core.md §3, task K1.4a).
|
|
3
|
+
*
|
|
4
|
+
* Roots for the profile and options (the vendored names the API layer uses)
|
|
5
|
+
* -> closure over the declaration table extracted from the unmodified vendored
|
|
6
|
+
* `pnanovdb.wgsl` -> generation transforms -> `pnanovdb_`→`vdb_` rename ->
|
|
7
|
+
* append the API layer -> prepend one SPDX line.
|
|
8
|
+
*
|
|
9
|
+
* Generation transforms (each one is a row in vendor/VENDOR.md, "Generation
|
|
10
|
+
* transforms"; none edits the vendored file):
|
|
11
|
+
* 1. `pnanovdb_buf_read_uint32` reads through `vdb_load`, the module's single
|
|
12
|
+
* buffer access site (§2).
|
|
13
|
+
* 2. The 27-row `pnanovdb_grid_type_constants` array becomes
|
|
14
|
+
* `fn vdb_gtc(grid_type)` returning only the compiled types' rows; its
|
|
15
|
+
* `[grid_type]` call sites become `vdb_gtc(grid_type)`.
|
|
16
|
+
* 3. `pnanovdb_read_float_typed` keeps only the compiled types' branches, so
|
|
17
|
+
* the other decoders drop out of the closure.
|
|
18
|
+
* 4. Declarations unreachable from the profile's roots are not emitted (the
|
|
19
|
+
* `pnanovdb_sample_trilinear_{float,fp8,fpn}` wrappers among them).
|
|
20
|
+
* 5. Every `pnanovdb_` / `PNANOVDB_` becomes `vdb_` / `VDB_`.
|
|
21
|
+
* 6. Comments are dropped (done at extraction).
|
|
22
|
+
* 7. `pnanovdb_leaf_get_stat_float` keeps only the compiled types' branch
|
|
23
|
+
* (the Fp leaf-stats decode, K1.4b), so a Float-only module has no
|
|
24
|
+
* uint16 decoder.
|
|
25
|
+
*
|
|
26
|
+
* Output is deterministic: the same options give the same bytes, and `types`
|
|
27
|
+
* is a set (order and duplicates do not matter).
|
|
28
|
+
*/
|
|
29
|
+
import { VDBError } from "../errors.js";
|
|
30
|
+
import { VDB_GPU_LAYOUT_VERSION, vdbPoolLayoutWgsl } from "../pool/layout.js";
|
|
31
|
+
import { VDB_GRID_TYPE_IDS, VDB_GRID_TYPE_NAMES } from "../types.js";
|
|
32
|
+
import { apiWgsl } from "./api.js";
|
|
33
|
+
import { WGSL_KEYWORDS, WGSL_RESERVED_WORDS } from "./reserved.js";
|
|
34
|
+
import { PNANOVDB_CHUNKS } from "./pnanovdb.chunks.generated.js";
|
|
35
|
+
/** First line of every generated module (§3.3). */
|
|
36
|
+
export const VDB_MODULE_BANNER = "// SPDX-License-Identifier: Apache-2.0 AND MIT. Derived from PNanoVDB.h (OpenVDB) via emcfarlane/webgpu-nanovdb; see NOTICE.";
|
|
37
|
+
/** Name of the storage binding `slot` mode declares. */
|
|
38
|
+
export const VDB_POOL_BINDING_NAME = "vdbPool";
|
|
39
|
+
/** Profiles in inclusion order; only the first `IMPLEMENTED_PROFILES` generate (`majorant` is deferred, D22). */
|
|
40
|
+
const PROFILES = ["read", "sample", "march", "majorant"];
|
|
41
|
+
const IMPLEMENTED_PROFILES = 3;
|
|
42
|
+
/** `GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE` (0x2 | 0x4); the global does not exist in Node. */
|
|
43
|
+
const SHADER_STAGE_FRAGMENT_COMPUTE = 0x2 | 0x4;
|
|
44
|
+
/** Opt-in helpers in canonical order, with the lowest profile rank each needs. */
|
|
45
|
+
const HELPERS = {
|
|
46
|
+
cellBoundTrilinear: { rank: 2 },
|
|
47
|
+
hddaCellEnd: { rank: 2 },
|
|
48
|
+
levelSet: { rank: 2 },
|
|
49
|
+
nodeAverage: { rank: 2 },
|
|
50
|
+
rayClipSupport: { rank: 1 },
|
|
51
|
+
fastTrilinear: { rank: 1 },
|
|
52
|
+
};
|
|
53
|
+
const HELPER_NAMES = Object.keys(HELPERS);
|
|
54
|
+
const IDENTIFIER = /[A-Za-z_][A-Za-z0-9_]*/g;
|
|
55
|
+
const BUFFER_EXPRESSION = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
56
|
+
function bad(message) {
|
|
57
|
+
return new VDBError("VDB_BAD_OPTION", message);
|
|
58
|
+
}
|
|
59
|
+
function checkSlot(slot, where) {
|
|
60
|
+
const s = slot;
|
|
61
|
+
if (s === null ||
|
|
62
|
+
typeof s !== "object" ||
|
|
63
|
+
!Number.isInteger(s.group) ||
|
|
64
|
+
!Number.isInteger(s.firstBinding) ||
|
|
65
|
+
s.group < 0 ||
|
|
66
|
+
s.firstBinding < 0) {
|
|
67
|
+
throw bad(`${where}: slot must be { group, firstBinding } with non-negative integers, got ${JSON.stringify(slot)}.`);
|
|
68
|
+
}
|
|
69
|
+
return { group: s.group, firstBinding: s.firstBinding };
|
|
70
|
+
}
|
|
71
|
+
/** The old bvh-style positional slot (`{ group, firstBinding }` at the top level of the module options) would be silently misread. */
|
|
72
|
+
function rejectPositionalSlot(where, options) {
|
|
73
|
+
if ("group" in options || "firstBinding" in options) {
|
|
74
|
+
throw bad(`${where}: got 'group' or 'firstBinding' at the top level. Pass { slot: { group, firstBinding } }.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function normalizeHelpers(helpers, profile, profileRank, where) {
|
|
78
|
+
if (helpers === undefined)
|
|
79
|
+
return [];
|
|
80
|
+
if (helpers === null || typeof helpers === "string" || typeof helpers[Symbol.iterator] !== "function") {
|
|
81
|
+
throw bad(`${where}: helpers must be an array or set of helper names (${HELPER_NAMES.join(", ")}), got ${JSON.stringify(helpers)}.`);
|
|
82
|
+
}
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
for (const h of helpers) {
|
|
85
|
+
if (typeof h !== "string" || !HELPER_NAMES.includes(h)) {
|
|
86
|
+
throw bad(`${where}: unknown helper ${JSON.stringify(h)}; use ${HELPER_NAMES.join(", ")}.`);
|
|
87
|
+
}
|
|
88
|
+
const need = HELPERS[h].rank;
|
|
89
|
+
if (profileRank < need) {
|
|
90
|
+
throw bad(`${where}: helper '${h}' needs profile '${PROFILES[need]}' or above, got '${profile}'.`);
|
|
91
|
+
}
|
|
92
|
+
seen.add(h);
|
|
93
|
+
}
|
|
94
|
+
return HELPER_NAMES.filter((h) => seen.has(h));
|
|
95
|
+
}
|
|
96
|
+
function normalizeTypes(types, where) {
|
|
97
|
+
if (types === undefined || types === null || typeof types === "string" || typeof types[Symbol.iterator] !== "function") {
|
|
98
|
+
throw bad(`${where}: types must be an array or set of grid type names (${VDB_GRID_TYPE_NAMES.join(", ")}), e.g. [...pool.types].`);
|
|
99
|
+
}
|
|
100
|
+
const seen = new Set();
|
|
101
|
+
for (const t of types) {
|
|
102
|
+
if (typeof t !== "string" || !VDB_GRID_TYPE_NAMES.includes(t)) {
|
|
103
|
+
throw bad(`${where}: unknown grid type ${JSON.stringify(t)}; use ${VDB_GRID_TYPE_NAMES.join(", ")}.`);
|
|
104
|
+
}
|
|
105
|
+
seen.add(t);
|
|
106
|
+
}
|
|
107
|
+
if (seen.size === 0) {
|
|
108
|
+
throw bad(`${where}: types is empty. Compile at least one grid type, e.g. ['float'], or pass [...pool.types] after adding a grid.`);
|
|
109
|
+
}
|
|
110
|
+
return VDB_GRID_TYPE_NAMES.filter((t) => seen.has(t));
|
|
111
|
+
}
|
|
112
|
+
function normalize(options, where) {
|
|
113
|
+
if (options === null || typeof options !== "object") {
|
|
114
|
+
throw bad(`${where}: expected an options object { slot | buffer, types, profile }.`);
|
|
115
|
+
}
|
|
116
|
+
rejectPositionalSlot(where, options);
|
|
117
|
+
const hasSlot = options.slot !== undefined;
|
|
118
|
+
const hasBuffer = options.buffer !== undefined;
|
|
119
|
+
if (hasSlot === hasBuffer) {
|
|
120
|
+
throw bad(`${where}: pass exactly one of slot: { group, firstBinding } (declares the binding) or buffer: '<wgsl expression>' (reads a host-declared array<u32>).`);
|
|
121
|
+
}
|
|
122
|
+
let binding;
|
|
123
|
+
if (hasSlot) {
|
|
124
|
+
binding = { kind: "slot", slot: checkSlot(options.slot, where) };
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const expression = options.buffer;
|
|
128
|
+
if (typeof expression !== "string" || !BUFFER_EXPRESSION.test(expression)) {
|
|
129
|
+
throw bad(`${where}: buffer must be a WGSL identifier or member chain such as 'vdbPool.value', got ${JSON.stringify(expression)}.`);
|
|
130
|
+
}
|
|
131
|
+
for (const part of expression.split(".")) {
|
|
132
|
+
if (part.startsWith("__")) {
|
|
133
|
+
throw bad(`${where}: buffer ${JSON.stringify(expression)} uses '${part}'; WGSL identifiers must not start with '__'. Rename the host binding.`);
|
|
134
|
+
}
|
|
135
|
+
if (part === "_" || WGSL_RESERVED_WORDS.has(part) || WGSL_KEYWORDS.has(part)) {
|
|
136
|
+
throw bad(`${where}: buffer ${JSON.stringify(expression)} uses '${part}', which WGSL reserves. Rename the host binding (e.g. 'vdbPool.value').`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
binding = { kind: "buffer", expression };
|
|
140
|
+
}
|
|
141
|
+
const profileRank = PROFILES.indexOf(options.profile);
|
|
142
|
+
if (profileRank < 0) {
|
|
143
|
+
throw bad(`${where}: profile must be one of ${PROFILES.map((p) => `'${p}'`).join(", ")}, got ${JSON.stringify(options.profile)}.`);
|
|
144
|
+
}
|
|
145
|
+
if (profileRank >= IMPLEMENTED_PROFILES) {
|
|
146
|
+
throw bad(`${where}: profile '${options.profile}' is deferred past 0.1 (D22). Use 'read', 'sample' or 'march'.`);
|
|
147
|
+
}
|
|
148
|
+
const sampler = options.sampler ?? "trilinear";
|
|
149
|
+
if (sampler !== "trilinear" && sampler !== "nearest") {
|
|
150
|
+
throw bad(`${where}: sampler must be 'trilinear' or 'nearest', got ${JSON.stringify(sampler)}.`);
|
|
151
|
+
}
|
|
152
|
+
const outside = options.outside ?? "background";
|
|
153
|
+
if (outside !== "background" && outside !== "zero") {
|
|
154
|
+
throw bad(`${where}: outside must be 'background' or 'zero', got ${JSON.stringify(outside)}.`);
|
|
155
|
+
}
|
|
156
|
+
const isActive = options.isActive ?? true;
|
|
157
|
+
if (typeof isActive !== "boolean") {
|
|
158
|
+
throw bad(`${where}: isActive must be a boolean, got ${JSON.stringify(isActive)}.`);
|
|
159
|
+
}
|
|
160
|
+
// Sample-only options do not change a `read` module; normalize them away so
|
|
161
|
+
// equal modules share one cache key.
|
|
162
|
+
const sampleOnly = profileRank >= 1;
|
|
163
|
+
return {
|
|
164
|
+
profile: options.profile,
|
|
165
|
+
profileRank,
|
|
166
|
+
binding,
|
|
167
|
+
types: normalizeTypes(options.types, where),
|
|
168
|
+
isActive,
|
|
169
|
+
sampler: sampleOnly ? sampler : "trilinear",
|
|
170
|
+
outside: sampleOnly ? outside : "background",
|
|
171
|
+
helpers: checkHelperSampler(normalizeHelpers(options.helpers, options.profile, profileRank, where), sampleOnly ? sampler : "trilinear", where),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/** `fastTrilinear` shares one leaf between the 8 trilinear taps; `nearest` has one tap. */
|
|
175
|
+
function checkHelperSampler(helpers, sampler, where) {
|
|
176
|
+
if (sampler === "nearest" && helpers.includes("fastTrilinear")) {
|
|
177
|
+
throw bad(`${where}: helper 'fastTrilinear' needs sampler 'trilinear' (nearest reads one voxel; call vdbSample).`);
|
|
178
|
+
}
|
|
179
|
+
return helpers;
|
|
180
|
+
}
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
// Declaration table and transforms
|
|
183
|
+
const CHUNKS = new Map(PNANOVDB_CHUNKS.map((c) => [c.name, c]));
|
|
184
|
+
const ORDER = new Map(PNANOVDB_CHUNKS.map((c, i) => [c.name, i]));
|
|
185
|
+
function chunk(name) {
|
|
186
|
+
const c = CHUNKS.get(name);
|
|
187
|
+
if (!c)
|
|
188
|
+
throw new Error(`@pmndrs/vdb: vendored declaration ${name} is missing; re-run scripts/extract-wgsl-chunks.mjs`);
|
|
189
|
+
return c;
|
|
190
|
+
}
|
|
191
|
+
const TYPE_TABLE = "pnanovdb_grid_type_constants";
|
|
192
|
+
const TYPE_TABLE_FN = "pnanovdb_gtc";
|
|
193
|
+
const TYPE_TABLE_CALL_SITE = /\bpnanovdb_grid_type_constants\[([^\]]+)\]/g;
|
|
194
|
+
/** Names the transforms introduce, resolved to the declaration they replace. */
|
|
195
|
+
const ALIASES = new Map([[TYPE_TABLE_FN, TYPE_TABLE]]);
|
|
196
|
+
const GRID_TYPE_CONSTANT_PRE = {
|
|
197
|
+
float: "PNANOVDB_GRID_TYPE_FLOAT",
|
|
198
|
+
fp4: "PNANOVDB_GRID_TYPE_FP4",
|
|
199
|
+
fp8: "PNANOVDB_GRID_TYPE_FP8",
|
|
200
|
+
fp16: "PNANOVDB_GRID_TYPE_FP16",
|
|
201
|
+
fpn: "PNANOVDB_GRID_TYPE_FPN",
|
|
202
|
+
};
|
|
203
|
+
/** Field names of the vendored `pnanovdb_grid_type_constants_t`, in order. */
|
|
204
|
+
const TYPE_TABLE_FIELDS = [...chunk("pnanovdb_grid_type_constants_t").text.matchAll(/^\s+(\w+)\s*:/gm)].map((m) => m[1]);
|
|
205
|
+
/** The 27 rows of the vendored type table, as argument lists. */
|
|
206
|
+
const TYPE_TABLE_ROWS = (() => {
|
|
207
|
+
const rows = [...chunk(TYPE_TABLE).text.matchAll(/pnanovdb_grid_type_constants_t\(([^)]*)\)/g)].map((m) => m[1].split(",").map((v) => v.trim()));
|
|
208
|
+
if (rows.length !== 27 || rows.some((r) => r.length !== TYPE_TABLE_FIELDS.length)) {
|
|
209
|
+
throw new Error(`@pmndrs/vdb: unexpected vendored grid type table shape; re-check generate.ts against vendor/pnanovdb.wgsl`);
|
|
210
|
+
}
|
|
211
|
+
return rows;
|
|
212
|
+
})();
|
|
213
|
+
/** Transform 1: the single buffer access. */
|
|
214
|
+
function bufReadOverride() {
|
|
215
|
+
return `fn pnanovdb_buf_read_uint32(buf: pnanovdb_buf_t, byte_offset: u32) -> u32 {
|
|
216
|
+
return vdb_load((buf.byte_offset >> 2u) + (byte_offset >> 2u));
|
|
217
|
+
}`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Transform 2: the type table cut to the compiled types. Fields no emitted code
|
|
221
|
+
* reads are written as 0u, and types whose remaining rows are equal share one
|
|
222
|
+
* branch (Fp4/Fp8/Fp16/FpN differ only in the unread `leaf_size`). One distinct
|
|
223
|
+
* row: a constant, no branch.
|
|
224
|
+
*/
|
|
225
|
+
function typeTableOverride({ o, fields }) {
|
|
226
|
+
const groups = [];
|
|
227
|
+
for (const t of o.types) {
|
|
228
|
+
const values = TYPE_TABLE_ROWS[VDB_GRID_TYPE_IDS[t]];
|
|
229
|
+
const row = `pnanovdb_grid_type_constants_t(${values
|
|
230
|
+
.map((v, i) => (fields === null || fields.has(TYPE_TABLE_FIELDS[i]) ? v : "0u"))
|
|
231
|
+
.join(", ")})`;
|
|
232
|
+
const group = groups.find((g) => g.row === row);
|
|
233
|
+
if (group)
|
|
234
|
+
group.types.push(t);
|
|
235
|
+
else
|
|
236
|
+
groups.push({ row, types: [t] });
|
|
237
|
+
}
|
|
238
|
+
const lines = [`fn ${TYPE_TABLE_FN}(grid_type: u32) -> pnanovdb_grid_type_constants_t {`];
|
|
239
|
+
groups.forEach((g, i) => {
|
|
240
|
+
if (i === groups.length - 1) {
|
|
241
|
+
lines.push(` return ${g.row};`);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
lines.push(` if ${g.types.map((t) => `grid_type == ${GRID_TYPE_CONSTANT_PRE[t]}`).join(" || ")} {`);
|
|
245
|
+
lines.push(` return ${g.row};`);
|
|
246
|
+
lines.push(` }`);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
lines.push("}");
|
|
250
|
+
return lines.join("\n");
|
|
251
|
+
}
|
|
252
|
+
/** Transform 3: typed decode limited to the compiled types. */
|
|
253
|
+
function readFloatTypedOverride({ o }) {
|
|
254
|
+
const text = chunk("pnanovdb_read_float_typed").text;
|
|
255
|
+
const signature = text.slice(0, text.indexOf("{") + 1);
|
|
256
|
+
const fpTypes = o.types.filter((t) => t !== "float");
|
|
257
|
+
const decode = (t) => `pnanovdb_root_${t}_read_float(buf, address, ijk, level)`;
|
|
258
|
+
const lines = [signature];
|
|
259
|
+
// Without Float, the last Fp type is the fallthrough: `ok` already rejects
|
|
260
|
+
// every other type before a read reaches here.
|
|
261
|
+
const branches = o.types.includes("float") ? fpTypes : fpTypes.slice(0, -1);
|
|
262
|
+
for (const t of branches) {
|
|
263
|
+
lines.push(` if grid_type == ${GRID_TYPE_CONSTANT_PRE[t]} {`);
|
|
264
|
+
lines.push(` return ${decode(t)};`);
|
|
265
|
+
lines.push(` }`);
|
|
266
|
+
}
|
|
267
|
+
lines.push(o.types.includes("float") ? " return pnanovdb_read_float(buf, address);" : ` return ${decode(fpTypes[fpTypes.length - 1])};`);
|
|
268
|
+
lines.push("}");
|
|
269
|
+
return lines.join("\n");
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Transform 7: the leaf-stat dispatch limited to the compiled types. No Fp type
|
|
273
|
+
* compiled: a plain f32 read (the code decoder drops out). Only Fp types: the
|
|
274
|
+
* decode, unconditionally. Both: one branch over the compiled Fp types.
|
|
275
|
+
*/
|
|
276
|
+
function leafStatOverride({ o }) {
|
|
277
|
+
const text = chunk("pnanovdb_leaf_get_stat_float").text;
|
|
278
|
+
const signature = text.slice(0, text.indexOf("{") + 1);
|
|
279
|
+
const fpTypes = o.types.filter((t) => t !== "float");
|
|
280
|
+
const decode = "return pnanovdb_leaf_fp_get_stat_float(grid_type, buf, node, address, with_minimum);";
|
|
281
|
+
const plain = "return pnanovdb_read_float(buf, address);";
|
|
282
|
+
const lines = [signature];
|
|
283
|
+
if (fpTypes.length === 0) {
|
|
284
|
+
lines.push(` ${plain}`);
|
|
285
|
+
}
|
|
286
|
+
else if (!o.types.includes("float")) {
|
|
287
|
+
lines.push(` ${decode}`);
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
lines.push(` if ${fpTypes.map((t) => `grid_type == ${GRID_TYPE_CONSTANT_PRE[t]}`).join(" || ")} {`);
|
|
291
|
+
lines.push(` ${decode}`);
|
|
292
|
+
lines.push(" }");
|
|
293
|
+
lines.push(` ${plain}`);
|
|
294
|
+
}
|
|
295
|
+
lines.push("}");
|
|
296
|
+
return lines.join("\n");
|
|
297
|
+
}
|
|
298
|
+
const OVERRIDES = new Map([
|
|
299
|
+
["pnanovdb_buf_read_uint32", bufReadOverride],
|
|
300
|
+
[TYPE_TABLE, typeTableOverride],
|
|
301
|
+
["pnanovdb_read_float_typed", readFloatTypedOverride],
|
|
302
|
+
["pnanovdb_leaf_get_stat_float", leafStatOverride],
|
|
303
|
+
]);
|
|
304
|
+
function effectiveText(c, ctx) {
|
|
305
|
+
const override = OVERRIDES.get(c.name);
|
|
306
|
+
if (override)
|
|
307
|
+
return override(ctx);
|
|
308
|
+
return c.text.replace(TYPE_TABLE_CALL_SITE, `${TYPE_TABLE_FN}($1)`);
|
|
309
|
+
}
|
|
310
|
+
function referencedChunks(text, self) {
|
|
311
|
+
const out = new Set();
|
|
312
|
+
for (const m of text.matchAll(IDENTIFIER)) {
|
|
313
|
+
const name = ALIASES.get(m[0]) ?? m[0];
|
|
314
|
+
if (name !== self && CHUNKS.has(name))
|
|
315
|
+
out.add(name);
|
|
316
|
+
}
|
|
317
|
+
return [...out];
|
|
318
|
+
}
|
|
319
|
+
/** Map a final (`vdb_` / `VDB_`) name back to its vendored declaration, if it is one. */
|
|
320
|
+
function vendoredName(finalName) {
|
|
321
|
+
let name;
|
|
322
|
+
if (finalName.startsWith("vdb_"))
|
|
323
|
+
name = `pnanovdb_${finalName.slice(4)}`;
|
|
324
|
+
else if (finalName.startsWith("VDB_"))
|
|
325
|
+
name = `PNANOVDB_${finalName.slice(4)}`;
|
|
326
|
+
if (name === undefined)
|
|
327
|
+
return undefined;
|
|
328
|
+
name = ALIASES.get(name) ?? name;
|
|
329
|
+
return CHUNKS.has(name) ? name : undefined;
|
|
330
|
+
}
|
|
331
|
+
function rename(text) {
|
|
332
|
+
return text.replace(/\bpnanovdb_/g, "vdb_").replace(/\bPNANOVDB_/g, "VDB_");
|
|
333
|
+
}
|
|
334
|
+
/** Vendored declarations a module needs, in file order. */
|
|
335
|
+
function closurePass(api, ctx) {
|
|
336
|
+
const roots = new Set();
|
|
337
|
+
for (const m of api.matchAll(IDENTIFIER)) {
|
|
338
|
+
const name = vendoredName(m[0]);
|
|
339
|
+
if (name)
|
|
340
|
+
roots.add(name);
|
|
341
|
+
}
|
|
342
|
+
const included = new Set();
|
|
343
|
+
const stack = [...roots];
|
|
344
|
+
while (stack.length > 0) {
|
|
345
|
+
const name = stack.pop();
|
|
346
|
+
if (included.has(name))
|
|
347
|
+
continue;
|
|
348
|
+
included.add(name);
|
|
349
|
+
const c = chunk(name);
|
|
350
|
+
for (const d of referencedChunks(effectiveText(c, ctx), name))
|
|
351
|
+
if (!included.has(d))
|
|
352
|
+
stack.push(d);
|
|
353
|
+
}
|
|
354
|
+
return [...included].sort((a, b) => ORDER.get(a) - ORDER.get(b));
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Vendored declarations a module needs, in file order, and the context to
|
|
358
|
+
* emit them with. Two passes: the first (whole type-table rows) finds which
|
|
359
|
+
* type-table fields the closure reads; the second emits only those, which can
|
|
360
|
+
* only shrink the closure.
|
|
361
|
+
*/
|
|
362
|
+
function closure(api, o) {
|
|
363
|
+
const first = closurePass(api, { o, fields: null });
|
|
364
|
+
const fields = new Set();
|
|
365
|
+
for (const name of first) {
|
|
366
|
+
if (name === TYPE_TABLE || name === "pnanovdb_grid_type_constants_t")
|
|
367
|
+
continue;
|
|
368
|
+
for (const m of chunk(name).text.matchAll(/\.([A-Za-z_]\w*)/g)) {
|
|
369
|
+
if (TYPE_TABLE_FIELDS.includes(m[1]))
|
|
370
|
+
fields.add(m[1]);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const ctx = { o, fields };
|
|
374
|
+
return { names: closurePass(api, ctx), ctx };
|
|
375
|
+
}
|
|
376
|
+
const cache = new Map();
|
|
377
|
+
function build(o) {
|
|
378
|
+
const api = apiWgsl(o.profileRank, o);
|
|
379
|
+
const access = o.binding.kind === "slot" ? VDB_POOL_BINDING_NAME : o.binding.expression;
|
|
380
|
+
const load = `fn vdb_load(vdb_i: u32) -> u32 {
|
|
381
|
+
return ${access}[vdb_i];
|
|
382
|
+
}`;
|
|
383
|
+
const { names, ctx } = closure(api, o);
|
|
384
|
+
const vendored = names.map((name) => rename(effectiveText(chunk(name), ctx))).join("\n");
|
|
385
|
+
const body = [vendored, load, api].join("\n");
|
|
386
|
+
// Layout constants come from core/pool/layout.ts (one source of truth); keep
|
|
387
|
+
// only the `const` lines the body references.
|
|
388
|
+
const constants = vdbPoolLayoutWgsl()
|
|
389
|
+
.split("\n")
|
|
390
|
+
.filter((line) => {
|
|
391
|
+
const name = /^const\s+(\w+)/.exec(line)?.[1];
|
|
392
|
+
return name !== undefined && new RegExp(`\\b${name}\\b`).test(body);
|
|
393
|
+
});
|
|
394
|
+
const head = [VDB_MODULE_BANNER];
|
|
395
|
+
if (o.binding.kind === "slot") {
|
|
396
|
+
head.push(`@group(${o.binding.slot.group}) @binding(${o.binding.slot.firstBinding}) var<storage, read> ${VDB_POOL_BINDING_NAME}: array<u32>;`);
|
|
397
|
+
}
|
|
398
|
+
return [...head, ...constants, body].join("\n") + "\n";
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Generate a WGSL module for the pool (docs/dev/design/K1-core.md §3.1).
|
|
402
|
+
* Deterministic: the same options give the same string.
|
|
403
|
+
*
|
|
404
|
+
* `types` must cover every grid type the host may add to the pool, not just
|
|
405
|
+
* the ones present now: a grid of a type the module wasn't generated for reads
|
|
406
|
+
* as 0. Either generate for every type up front (`VDB_ALL_SCALAR_TYPES`, or
|
|
407
|
+
* the host's known set) or regenerate the module and rebuild the pipeline when
|
|
408
|
+
* `vdbCheckModule(pool, options)` throws `VDB_TYPE_NOT_COMPILED` after an `add`.
|
|
409
|
+
*
|
|
410
|
+
* @throws VDBError `VDB_BAD_OPTION` for invalid options.
|
|
411
|
+
*/
|
|
412
|
+
export function vdbModuleWgsl(options) {
|
|
413
|
+
const o = normalize(options, "vdbModuleWgsl");
|
|
414
|
+
const key = JSON.stringify(o);
|
|
415
|
+
let code = cache.get(key);
|
|
416
|
+
if (code === undefined) {
|
|
417
|
+
code = build(o);
|
|
418
|
+
cache.set(key, code);
|
|
419
|
+
}
|
|
420
|
+
return code;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* The bind group layout entries a `slot` module declares: one read-only
|
|
424
|
+
* storage buffer at `slot.firstBinding` (layout 1).
|
|
425
|
+
*
|
|
426
|
+
* Takes the same `VDBSlot` as `vdbModuleWgsl({ slot })` and
|
|
427
|
+
* `pool.bindGroupEntry(slot)`, either bare or as `{ slot, visibility }`.
|
|
428
|
+
* `visibility` defaults to `GPUShaderStage.COMPUTE | GPUShaderStage.FRAGMENT`
|
|
429
|
+
* (read-only storage is legal in both stages), so render and compute hosts
|
|
430
|
+
* both work without it; pass it to narrow the layout.
|
|
431
|
+
*
|
|
432
|
+
* @throws VDBError `VDB_BAD_OPTION` for a malformed slot.
|
|
433
|
+
*/
|
|
434
|
+
export function vdbModuleEntries(slotOrOptions) {
|
|
435
|
+
const where = "vdbModuleEntries";
|
|
436
|
+
if (slotOrOptions === null || typeof slotOrOptions !== "object")
|
|
437
|
+
throw bad(`${where}: expected a slot { group, firstBinding } or { slot, visibility? }.`);
|
|
438
|
+
let slot;
|
|
439
|
+
let visibility = SHADER_STAGE_FRAGMENT_COMPUTE;
|
|
440
|
+
if ("slot" in slotOrOptions) {
|
|
441
|
+
rejectPositionalSlot(where, slotOrOptions);
|
|
442
|
+
slot = checkSlot(slotOrOptions.slot, where);
|
|
443
|
+
const v = slotOrOptions.visibility;
|
|
444
|
+
if (v !== undefined) {
|
|
445
|
+
if (!Number.isInteger(v) || v <= 0)
|
|
446
|
+
throw bad(`${where}: visibility must be GPUShaderStage flags (a positive integer), got ${JSON.stringify(v)}.`);
|
|
447
|
+
visibility = v;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
if ("visibility" in slotOrOptions)
|
|
452
|
+
throw bad(`${where}: pass visibility as { slot: { group, firstBinding }, visibility }.`);
|
|
453
|
+
slot = checkSlot(slotOrOptions, where);
|
|
454
|
+
}
|
|
455
|
+
return [{ binding: slot.firstBinding, visibility, buffer: { type: "read-only-storage" } }];
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Check that a module generated with `options` can read every grid in `pool`.
|
|
459
|
+
*
|
|
460
|
+
* `options` is either the full `vdbModuleWgsl` options (validated as such) or
|
|
461
|
+
* just `{ types, layoutVersion? }` for a type/layout-only check, e.g. from an
|
|
462
|
+
* engine adapter that builds its module elsewhere. `layoutVersion` is the
|
|
463
|
+
* layout the module targets (default: this generator's,
|
|
464
|
+
* `VDB_GPU_LAYOUT_VERSION`).
|
|
465
|
+
*
|
|
466
|
+
* After every `pool.add`: a module must be generated for every type the host
|
|
467
|
+
* may add, or regenerated and its pipeline rebuilt.
|
|
468
|
+
*
|
|
469
|
+
* @throws VDBError `VDB_LAYOUT_MISMATCH` if the pool's layout is not the one
|
|
470
|
+
* the module targets; `VDB_TYPE_NOT_COMPILED` if the pool holds a grid
|
|
471
|
+
* type the module would not decode; `VDB_BAD_OPTION` for invalid options.
|
|
472
|
+
*/
|
|
473
|
+
export function vdbCheckModule(pool, options) {
|
|
474
|
+
const where = "vdbCheckModule";
|
|
475
|
+
let o;
|
|
476
|
+
let target = VDB_GPU_LAYOUT_VERSION;
|
|
477
|
+
if (options !== null && typeof options === "object" && !("slot" in options) && !("buffer" in options) && !("profile" in options)) {
|
|
478
|
+
// Type/layout-only form.
|
|
479
|
+
o = { types: normalizeTypes(options.types, where) };
|
|
480
|
+
const v = options.layoutVersion;
|
|
481
|
+
if (v !== undefined) {
|
|
482
|
+
if (!Number.isInteger(v) || v < 0)
|
|
483
|
+
throw bad(`${where}: layoutVersion must be a non-negative integer, got ${JSON.stringify(v)}.`);
|
|
484
|
+
target = v;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
o = normalize(options, where);
|
|
489
|
+
}
|
|
490
|
+
if (pool.layoutVersion !== target) {
|
|
491
|
+
throw new VDBError("VDB_LAYOUT_MISMATCH", `the pool uses layout ${pool.layoutVersion} but the module targets layout ${target}. Use one @pmndrs/vdb version for both.`);
|
|
492
|
+
}
|
|
493
|
+
const missing = [...new Set(pool.types)].filter((t) => !o.types.includes(t));
|
|
494
|
+
if (missing.length > 0) {
|
|
495
|
+
throw new VDBError("VDB_TYPE_NOT_COMPILED", `the pool holds ${missing.join(", ")} grids but the module compiles only ${o.types.join(", ")}; those grids would read 0. ` +
|
|
496
|
+
`A module must be generated for every type the host may add: regenerate it with types that include ${missing.join(", ")} ` +
|
|
497
|
+
`(e.g. [...pool.types], or VDB_ALL_SCALAR_TYPES to never rebuild) and rebuild the pipeline that uses it.`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/** @internal Vendored declarations (vendored names) a module with these options includes, in file order. For tests. */
|
|
501
|
+
export function vdbModuleDeclarations(options) {
|
|
502
|
+
const o = normalize(options, "vdbModuleDeclarations");
|
|
503
|
+
return closure(apiWgsl(o.profileRank, o), o).names;
|
|
504
|
+
}
|
|
505
|
+
//# sourceMappingURL=generate.js.map
|