@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,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the few NanoVDB `GridData` / `TreeData` / `RootData` fields a pool record
|
|
3
|
+
* needs, by byte offset (docs/dev/design/K1-core.md §1.4). The core never imports
|
|
4
|
+
* `tools` (D20), so the offsets are restated here; `test/core/image-header.test.ts`
|
|
5
|
+
* cross-checks every one against `tools`' constants and `vendor/stride-tables.json`
|
|
6
|
+
* (ABI 32.9.1, PNanoVDB.h).
|
|
7
|
+
*/
|
|
8
|
+
import { VDBError } from "../errors.js";
|
|
9
|
+
import { VDB_GRID_TYPE_IDS } from "../types.js";
|
|
10
|
+
/** Byte offsets inside a NanoVDB grid image used by the pool. */
|
|
11
|
+
export const NANOVDB_OFFSETS = {
|
|
12
|
+
/** `GridData` size; `TreeData` follows it. */
|
|
13
|
+
gridSize: 672,
|
|
14
|
+
gridMagic: 0,
|
|
15
|
+
gridVersion: 16,
|
|
16
|
+
gridFlags: 20,
|
|
17
|
+
/** u64 `mGridSize`. */
|
|
18
|
+
gridByteSize: 32,
|
|
19
|
+
gridName: 40,
|
|
20
|
+
gridNameMax: 256,
|
|
21
|
+
gridMap: 296,
|
|
22
|
+
mapMatD: 88,
|
|
23
|
+
mapInvMatD: 160,
|
|
24
|
+
mapVecD: 232,
|
|
25
|
+
gridWorldBBox: 560,
|
|
26
|
+
gridVoxelSize: 608,
|
|
27
|
+
gridClass: 632,
|
|
28
|
+
gridType: 636,
|
|
29
|
+
treeSize: 64,
|
|
30
|
+
/** u64, relative to `TreeData`. */
|
|
31
|
+
treeNodeOffsetRoot: 24,
|
|
32
|
+
rootBBoxMin: 0,
|
|
33
|
+
rootBBoxMax: 12,
|
|
34
|
+
/** `RootData` base size before the typed background/stats. */
|
|
35
|
+
rootBaseSize: 28,
|
|
36
|
+
/** Typed root fields for Float/Fp4/Fp8/Fp16/FpN (all store f32 here). */
|
|
37
|
+
rootBackground: 28,
|
|
38
|
+
rootMin: 32,
|
|
39
|
+
rootMax: 36,
|
|
40
|
+
/** Smallest `RootData` for the supported types (stride table `root_size`). */
|
|
41
|
+
rootSize: 64,
|
|
42
|
+
};
|
|
43
|
+
/** `GridData.mFlags` bit for min/max statistics (NanoVDB `GridFlags::HasMinMax`). */
|
|
44
|
+
export const NANOVDB_FLAG_HAS_MIN_MAX = 1 << 2;
|
|
45
|
+
/** NanoVDB ABI major this core reads. */
|
|
46
|
+
export const NANOVDB_ABI_MAJOR = 32;
|
|
47
|
+
/** `"NanoVDB1"` (grid) as two little-endian u32 words. */
|
|
48
|
+
const MAGIC_GRID_LO = 0x6f6e614e; // "Nano"
|
|
49
|
+
const MAGIC_GRID_HI_CURRENT = 0x31424456; // "VDB1"
|
|
50
|
+
const MAGIC_GRID_HI_LEGACY = 0x30424456; // "VDB0"
|
|
51
|
+
const TYPE_BY_ID = new Map(Object.entries(VDB_GRID_TYPE_IDS).map(([name, id]) => [id, name]));
|
|
52
|
+
/** Maps a NanoVDB `GridType` id to its pool type name, or `null` when the pool can't hold it. */
|
|
53
|
+
export function gridTypeName(id) {
|
|
54
|
+
return TYPE_BY_ID.get(id) ?? null;
|
|
55
|
+
}
|
|
56
|
+
/** NanoVDB `GridClass` names by id (NanoVDB.h). */
|
|
57
|
+
const GRID_CLASS_NAMES = [
|
|
58
|
+
"Unknown",
|
|
59
|
+
"LevelSet",
|
|
60
|
+
"FogVolume",
|
|
61
|
+
"Staggered",
|
|
62
|
+
"PointIndex",
|
|
63
|
+
"PointData",
|
|
64
|
+
"Topology",
|
|
65
|
+
"VoxelVolume",
|
|
66
|
+
"IndexGrid",
|
|
67
|
+
"TensorGrid",
|
|
68
|
+
"VoxelBVH",
|
|
69
|
+
];
|
|
70
|
+
/** NanoVDB `GridClass` name for an id (`"Unknown(n)"` past the known range). */
|
|
71
|
+
export function gridClassName(id) {
|
|
72
|
+
return GRID_CLASS_NAMES[id] ?? `Unknown(${id})`;
|
|
73
|
+
}
|
|
74
|
+
function bad(message) {
|
|
75
|
+
throw new VDBError("VDB_BAD_IMAGE", message);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parses and validates the header of a NanoVDB grid image (one grid, as
|
|
79
|
+
* `NvdbFile` from `@pmndrs/vdb/tools` returns it). Throws `VDB_BAD_IMAGE` or
|
|
80
|
+
* `VDB_UNSUPPORTED_GRID_TYPE` with the fix in the message.
|
|
81
|
+
*/
|
|
82
|
+
export function readImageHeader(image, what = "image") {
|
|
83
|
+
if (!(image instanceof Uint32Array)) {
|
|
84
|
+
bad(`${what} must be a Uint32Array holding one NanoVDB grid (NvdbFile from @pmndrs/vdb/tools returns one per grid).`);
|
|
85
|
+
}
|
|
86
|
+
const O = NANOVDB_OFFSETS;
|
|
87
|
+
const byteLength = image.byteLength;
|
|
88
|
+
const minBytes = O.gridSize + O.treeSize + O.rootSize;
|
|
89
|
+
if (byteLength < minBytes) {
|
|
90
|
+
bad(`${what} is ${byteLength} bytes; a NanoVDB grid is at least ${minBytes}. Pass a whole grid image, not a slice.`);
|
|
91
|
+
}
|
|
92
|
+
const view = new DataView(image.buffer, image.byteOffset, byteLength);
|
|
93
|
+
const u32 = (at) => view.getUint32(at, true);
|
|
94
|
+
const magicLo = u32(O.gridMagic);
|
|
95
|
+
const magicHi = u32(O.gridMagic + 4);
|
|
96
|
+
if (magicLo !== MAGIC_GRID_LO || (magicHi !== MAGIC_GRID_HI_CURRENT && magicHi !== MAGIC_GRID_HI_LEGACY)) {
|
|
97
|
+
bad(`${what} does not start with the NanoVDB grid magic "NanoVDB1". Pass a grid image (NvdbFile.grids[i].image), ` +
|
|
98
|
+
`not a whole .nvdb file.`);
|
|
99
|
+
}
|
|
100
|
+
const version = u32(O.gridVersion);
|
|
101
|
+
const major = (version >>> 21) & 0x7ff;
|
|
102
|
+
if (major !== NANOVDB_ABI_MAJOR) {
|
|
103
|
+
bad(`${what} is NanoVDB ABI ${major}.${(version >>> 10) & 0x7ff}; this core reads ABI ${NANOVDB_ABI_MAJOR}. ` +
|
|
104
|
+
`Re-export it with NanoVDB ${NANOVDB_ABI_MAJOR}.x.`);
|
|
105
|
+
}
|
|
106
|
+
const sizeLo = u32(O.gridByteSize);
|
|
107
|
+
const sizeHi = u32(O.gridByteSize + 4);
|
|
108
|
+
if (sizeHi !== 0) {
|
|
109
|
+
bad(`${what} declares a grid of 4 GiB or more; the pool addresses images with 32 bits. Split or downsample the grid.`);
|
|
110
|
+
}
|
|
111
|
+
if (sizeLo !== byteLength) {
|
|
112
|
+
bad(`${what} declares mGridSize ${sizeLo} but the array holds ${byteLength} bytes. Pass exactly one grid ` +
|
|
113
|
+
`(a multi-grid buffer must be split, which NvdbFile does).`);
|
|
114
|
+
}
|
|
115
|
+
const gridTypeId = u32(O.gridType);
|
|
116
|
+
const gridType = gridTypeName(gridTypeId);
|
|
117
|
+
if (gridType === null) {
|
|
118
|
+
throw new VDBError("VDB_UNSUPPORTED_GRID_TYPE", `${what} has NanoVDB GridType ${gridTypeId}; the pool holds Float (1), Fp4 (13), Fp8 (14), Fp16 (15) and FpN (16). ` +
|
|
119
|
+
`Convert it, e.g. quantize() from @pmndrs/vdb/tools or nanovdb_convert --fp8.`);
|
|
120
|
+
}
|
|
121
|
+
const flags = u32(O.gridFlags);
|
|
122
|
+
const gridClass = u32(O.gridClass);
|
|
123
|
+
if (gridClass > 0xff)
|
|
124
|
+
bad(`${what} has GridClass ${gridClass}; NanoVDB classes are < 256, so the header is corrupt. Re-export it.`);
|
|
125
|
+
const f64s = (at, n) => {
|
|
126
|
+
const out = new Float64Array(n);
|
|
127
|
+
for (let k = 0; k < n; k++)
|
|
128
|
+
out[k] = view.getFloat64(at + 8 * k, true);
|
|
129
|
+
return out;
|
|
130
|
+
};
|
|
131
|
+
const matD = f64s(O.gridMap + O.mapMatD, 9);
|
|
132
|
+
const invMatD = f64s(O.gridMap + O.mapInvMatD, 9);
|
|
133
|
+
const vecD = f64s(O.gridMap + O.mapVecD, 3);
|
|
134
|
+
for (const [label, arr] of [["matD", matD], ["invMatD", invMatD], ["vecD", vecD]]) {
|
|
135
|
+
if (!arr.every(Number.isFinite)) {
|
|
136
|
+
bad(`${what} has a non-finite map (${label}). Rewrite its transform (transform() in @pmndrs/vdb/tools) and re-add it.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const det = matD[0] * (matD[4] * matD[8] - matD[5] * matD[7]) -
|
|
140
|
+
matD[1] * (matD[3] * matD[8] - matD[5] * matD[6]) +
|
|
141
|
+
matD[2] * (matD[3] * matD[7] - matD[4] * matD[6]);
|
|
142
|
+
if (det === 0)
|
|
143
|
+
bad(`${what} has a singular map (zero voxel size). Rewrite its transform and re-add it.`);
|
|
144
|
+
const voxelSize = Array.from(f64s(O.gridVoxelSize, 3));
|
|
145
|
+
const rootRel = Number(view.getBigUint64(O.gridSize + O.treeNodeOffsetRoot, true));
|
|
146
|
+
const root = O.gridSize + rootRel;
|
|
147
|
+
if (!Number.isSafeInteger(rootRel) || root + O.rootSize > byteLength) {
|
|
148
|
+
bad(`${what} has a root node offset (${rootRel}) outside the image. The file is corrupt; re-export it.`);
|
|
149
|
+
}
|
|
150
|
+
const i3 = (at) => [view.getInt32(at, true), view.getInt32(at + 4, true), view.getInt32(at + 8, true)];
|
|
151
|
+
const nameBytes = new Uint8Array(image.buffer, image.byteOffset + O.gridName, O.gridNameMax);
|
|
152
|
+
let end = nameBytes.indexOf(0);
|
|
153
|
+
if (end < 0)
|
|
154
|
+
end = nameBytes.length;
|
|
155
|
+
const name = new TextDecoder().decode(nameBytes.subarray(0, end));
|
|
156
|
+
return {
|
|
157
|
+
gridType,
|
|
158
|
+
gridTypeId,
|
|
159
|
+
gridClass,
|
|
160
|
+
name,
|
|
161
|
+
flags,
|
|
162
|
+
hasStats: (flags & NANOVDB_FLAG_HAS_MIN_MAX) !== 0,
|
|
163
|
+
byteLength,
|
|
164
|
+
matD,
|
|
165
|
+
invMatD,
|
|
166
|
+
vecD,
|
|
167
|
+
indexBBoxMin: i3(root + O.rootBBoxMin),
|
|
168
|
+
indexBBoxMax: i3(root + O.rootBBoxMax),
|
|
169
|
+
voxelSize,
|
|
170
|
+
background: view.getFloat32(root + O.rootBackground, true),
|
|
171
|
+
rootMin: view.getFloat32(root + O.rootMin, true),
|
|
172
|
+
rootMax: view.getFloat32(root + O.rootMax, true),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=image-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-header.js","sourceRoot":"","sources":["../../../src/core/pool/image-header.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAwB,MAAM,aAAa,CAAC;AAGtE,iEAAiE;AACjE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,8CAA8C;IAC9C,QAAQ,EAAE,GAAG;IACb,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,EAAE;IACf,SAAS,EAAE,EAAE;IACb,uBAAuB;IACvB,YAAY,EAAE,EAAE;IAChB,QAAQ,EAAE,EAAE;IACZ,WAAW,EAAE,GAAG;IAChB,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,EAAE;IAC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AExH,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;IAC7F,IAAI,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,GAAG,GAAG,CAAC;QAAE,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAElE,OAAO;QACL,QAAQ;QACR,UAAU;QACV,SAAS;QACT,IAAI;QACJ,KAAK;QACL,QAAQ,EAAE,CAAC,KAAK,GAAG,wBAAwB,CAAC,KAAK,CAAC;QAClD,UAAU;QACV,IAAI;QACJ,OAAO;QACP,IAAI;QACJ,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC;QACtC,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC;QACtC,SAAS;QACT,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,IAAI,CAAC;QAC1D,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC;QAChD,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC;KACjD,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Reads the few NanoVDB `GridData` / `TreeData` / `RootData` fields a pool record\n * needs, by byte offset (docs/dev/design/K1-core.md §1.4). The core never imports\n * `tools` (D20), so the offsets are restated here; `test/core/image-header.test.ts`\n * cross-checks every one against `tools`' constants and `vendor/stride-tables.json`\n * (ABI 32.9.1, PNanoVDB.h).\n */\n\nimport { VDBError } from \"../errors.js\";\nimport { VDB_GRID_TYPE_IDS, type VDBGridTypeName } from \"../types.js\";\nimport type { VDBVec3 } from \"./layout.js\";\n\n/** Byte offsets inside a NanoVDB grid image used by the pool. */\nexport const NANOVDB_OFFSETS = {\n /** `GridData` size; `TreeData` follows it. */\n gridSize: 672,\n gridMagic: 0,\n gridVersion: 16,\n gridFlags: 20,\n /** u64 `mGridSize`. */\n gridByteSize: 32,\n gridName: 40,\n gridNameMax: 256,\n gridMap: 296,\n mapMatD: 88,\n mapInvMatD: 160,\n mapVecD: 232,\n gridWorldBBox: 560,\n gridVoxelSize: 608,\n gridClass: 632,\n gridType: 636,\n treeSize: 64,\n /** u64, relative to `TreeData`. */\n treeNodeOffsetRoot: 24,\n rootBBoxMin: 0,\n rootBBoxMax: 12,\n /** `RootData` base size before the typed background/stats. */\n rootBaseSize: 28,\n /** Typed root fields for Float/Fp4/Fp8/Fp16/FpN (all store f32 here). */\n rootBackground: 28,\n rootMin: 32,\n rootMax: 36,\n /** Smallest `RootData` for the supported types (stride table `root_size`). */\n rootSize: 64,\n} as const;\n\n/** `GridData.mFlags` bit for min/max statistics (NanoVDB `GridFlags::HasMinMax`). */\nexport const NANOVDB_FLAG_HAS_MIN_MAX = 1 << 2;\n\n/** NanoVDB ABI major this core reads. */\nexport const NANOVDB_ABI_MAJOR = 32;\n\n/** `\"NanoVDB1\"` (grid) as two little-endian u32 words. */\nconst MAGIC_GRID_LO = 0x6f6e614e; // \"Nano\"\nconst MAGIC_GRID_HI_CURRENT = 0x31424456; // \"VDB1\"\nconst MAGIC_GRID_HI_LEGACY = 0x30424456; // \"VDB0\"\n\nconst TYPE_BY_ID = new Map<number, VDBGridTypeName>(\n (Object.entries(VDB_GRID_TYPE_IDS) as [VDBGridTypeName, number][]).map(([name, id]) => [id, name]),\n);\n\n/** Maps a NanoVDB `GridType` id to its pool type name, or `null` when the pool can't hold it. */\nexport function gridTypeName(id: number): VDBGridTypeName | null {\n return TYPE_BY_ID.get(id) ?? null;\n}\n\n/** NanoVDB `GridClass` names by id (NanoVDB.h). */\nconst GRID_CLASS_NAMES = [\n \"Unknown\",\n \"LevelSet\",\n \"FogVolume\",\n \"Staggered\",\n \"PointIndex\",\n \"PointData\",\n \"Topology\",\n \"VoxelVolume\",\n \"IndexGrid\",\n \"TensorGrid\",\n \"VoxelBVH\",\n] as const;\n\n/** NanoVDB `GridClass` name for an id (`\"Unknown(n)\"` past the known range). */\nexport function gridClassName(id: number): string {\n return GRID_CLASS_NAMES[id] ?? `Unknown(${id})`;\n}\n\n/** What the pool reads from a grid image's header. */\nexport interface VDBImageHeader {\n gridType: VDBGridTypeName;\n gridTypeId: number;\n gridClass: number;\n name: string;\n /** `GridData.mFlags`. */\n flags: number;\n hasStats: boolean;\n /** Bytes in the image (`mGridSize`, equal to the array's byte length). */\n byteLength: number;\n /** f64 3x3 row-major index -> world linear part. */\n matD: Float64Array;\n /** f64 3x3 row-major world -> index linear part. */\n invMatD: Float64Array;\n /** f64 translation: `world = matD * ijk + vecD`. */\n vecD: Float64Array;\n indexBBoxMin: VDBVec3;\n indexBBoxMax: VDBVec3;\n voxelSize: VDBVec3;\n background: number;\n /** Root min statistic (f32 as stored); meaningful only when `hasStats`. */\n rootMin: number;\n /** Root max statistic; meaningful only when `hasStats`. */\n rootMax: number;\n}\n\nfunction bad(message: string): never {\n throw new VDBError(\"VDB_BAD_IMAGE\", message);\n}\n\n/**\n * Parses and validates the header of a NanoVDB grid image (one grid, as\n * `NvdbFile` from `@pmndrs/vdb/tools` returns it). Throws `VDB_BAD_IMAGE` or\n * `VDB_UNSUPPORTED_GRID_TYPE` with the fix in the message.\n */\nexport function readImageHeader(image: Uint32Array, what = \"image\"): VDBImageHeader {\n if (!(image instanceof Uint32Array)) {\n bad(`${what} must be a Uint32Array holding one NanoVDB grid (NvdbFile from @pmndrs/vdb/tools returns one per grid).`);\n }\n const O = NANOVDB_OFFSETS;\n const byteLength = image.byteLength;\n const minBytes = O.gridSize + O.treeSize + O.rootSize;\n if (byteLength < minBytes) {\n bad(`${what} is ${byteLength} bytes; a NanoVDB grid is at least ${minBytes}. Pass a whole grid image, not a slice.`);\n }\n const view = new DataView(image.buffer, image.byteOffset, byteLength);\n const u32 = (at: number) => view.getUint32(at, true);\n\n const magicLo = u32(O.gridMagic);\n const magicHi = u32(O.gridMagic + 4);\n if (magicLo !== MAGIC_GRID_LO || (magicHi !== MAGIC_GRID_HI_CURRENT && magicHi !== MAGIC_GRID_HI_LEGACY)) {\n bad(\n `${what} does not start with the NanoVDB grid magic \"NanoVDB1\". Pass a grid image (NvdbFile.grids[i].image), ` +\n `not a whole .nvdb file.`,\n );\n }\n const version = u32(O.gridVersion);\n const major = (version >>> 21) & 0x7ff;\n if (major !== NANOVDB_ABI_MAJOR) {\n bad(\n `${what} is NanoVDB ABI ${major}.${(version >>> 10) & 0x7ff}; this core reads ABI ${NANOVDB_ABI_MAJOR}. ` +\n `Re-export it with NanoVDB ${NANOVDB_ABI_MAJOR}.x.`,\n );\n }\n const sizeLo = u32(O.gridByteSize);\n const sizeHi = u32(O.gridByteSize + 4);\n if (sizeHi !== 0) {\n bad(`${what} declares a grid of 4 GiB or more; the pool addresses images with 32 bits. Split or downsample the grid.`);\n }\n if (sizeLo !== byteLength) {\n bad(\n `${what} declares mGridSize ${sizeLo} but the array holds ${byteLength} bytes. Pass exactly one grid ` +\n `(a multi-grid buffer must be split, which NvdbFile does).`,\n );\n }\n\n const gridTypeId = u32(O.gridType);\n const gridType = gridTypeName(gridTypeId);\n if (gridType === null) {\n throw new VDBError(\n \"VDB_UNSUPPORTED_GRID_TYPE\",\n `${what} has NanoVDB GridType ${gridTypeId}; the pool holds Float (1), Fp4 (13), Fp8 (14), Fp16 (15) and FpN (16). ` +\n `Convert it, e.g. quantize() from @pmndrs/vdb/tools or nanovdb_convert --fp8.`,\n );\n }\n const flags = u32(O.gridFlags);\n const gridClass = u32(O.gridClass);\n if (gridClass > 0xff) bad(`${what} has GridClass ${gridClass}; NanoVDB classes are < 256, so the header is corrupt. Re-export it.`);\n\n const f64s = (at: number, n: number) => {\n const out = new Float64Array(n);\n for (let k = 0; k < n; k++) out[k] = view.getFloat64(at + 8 * k, true);\n return out;\n };\n const matD = f64s(O.gridMap + O.mapMatD, 9);\n const invMatD = f64s(O.gridMap + O.mapInvMatD, 9);\n const vecD = f64s(O.gridMap + O.mapVecD, 3);\n for (const [label, arr] of [[\"matD\", matD], [\"invMatD\", invMatD], [\"vecD\", vecD]] as const) {\n if (!arr.every(Number.isFinite)) {\n bad(`${what} has a non-finite map (${label}). Rewrite its transform (transform() in @pmndrs/vdb/tools) and re-add it.`);\n }\n }\n const det =\n matD[0]! * (matD[4]! * matD[8]! - matD[5]! * matD[7]!) -\n matD[1]! * (matD[3]! * matD[8]! - matD[5]! * matD[6]!) +\n matD[2]! * (matD[3]! * matD[7]! - matD[4]! * matD[6]!);\n if (det === 0) bad(`${what} has a singular map (zero voxel size). Rewrite its transform and re-add it.`);\n const voxelSize = Array.from(f64s(O.gridVoxelSize, 3)) as VDBVec3;\n\n const rootRel = Number(view.getBigUint64(O.gridSize + O.treeNodeOffsetRoot, true));\n const root = O.gridSize + rootRel;\n if (!Number.isSafeInteger(rootRel) || root + O.rootSize > byteLength) {\n bad(`${what} has a root node offset (${rootRel}) outside the image. The file is corrupt; re-export it.`);\n }\n const i3 = (at: number): VDBVec3 => [view.getInt32(at, true), view.getInt32(at + 4, true), view.getInt32(at + 8, true)];\n\n const nameBytes = new Uint8Array(image.buffer, image.byteOffset + O.gridName, O.gridNameMax);\n let end = nameBytes.indexOf(0);\n if (end < 0) end = nameBytes.length;\n const name = new TextDecoder().decode(nameBytes.subarray(0, end));\n\n return {\n gridType,\n gridTypeId,\n gridClass,\n name,\n flags,\n hasStats: (flags & NANOVDB_FLAG_HAS_MIN_MAX) !== 0,\n byteLength,\n matD,\n invMatD,\n vecD,\n indexBBoxMin: i3(root + O.rootBBoxMin),\n indexBBoxMax: i3(root + O.rootBBoxMax),\n voxelSize,\n background: view.getFloat32(root + O.rootBackground, true),\n rootMin: view.getFloat32(root + O.rootMin, true),\n rootMax: view.getFloat32(root + O.rootMax, true),\n };\n}\n"]}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pool buffer layout 1 (docs/dev/design/K1-core.md §1): a 32-byte header, a table of
|
|
3
|
+
* fixed-stride 160-byte grid records, then 32-byte-aligned ranges (NanoVDB
|
|
4
|
+
* images, brick-majorant grids).
|
|
5
|
+
*
|
|
6
|
+
* This file is the single source of truth for every header word, record word
|
|
7
|
+
* and flag bit. The TypeScript encoders below and the WGSL constants returned by
|
|
8
|
+
* {@link vdbPoolLayoutWgsl} are both derived from the tables in this file, so the
|
|
9
|
+
* CPU writer and the GPU reader cannot drift apart. Any change to a word or its
|
|
10
|
+
* meaning bumps {@link VDB_GPU_LAYOUT_VERSION} and is a breaking change (§1.8).
|
|
11
|
+
*/
|
|
12
|
+
import type { VDBVec3 } from "../../tools/vdb/types.js";
|
|
13
|
+
/** Layout version written to header word 1 and baked into generated WGSL. */
|
|
14
|
+
export declare const VDB_GPU_LAYOUT_VERSION = 1;
|
|
15
|
+
/** Header word 0: `"VDBP"` read as a little-endian u32. */
|
|
16
|
+
export declare const VDB_POOL_MAGIC = 1346520150;
|
|
17
|
+
/** Every range in the pool (table, images, majorants) starts on this byte alignment (NanoVDB's data alignment). */
|
|
18
|
+
export declare const VDB_POOL_ALIGN = 32;
|
|
19
|
+
/** Header size in bytes. */
|
|
20
|
+
export declare const VDB_POOL_HEADER_BYTES = 32;
|
|
21
|
+
/** Header size in u32 words. */
|
|
22
|
+
export declare const VDB_POOL_HEADER_WORDS: number;
|
|
23
|
+
/** Byte offset of record 0 (fixed in layout 1). */
|
|
24
|
+
export declare const VDB_POOL_TABLE_OFFSET = 32;
|
|
25
|
+
/** Grid record size in bytes. A multiple of 16 so `vec4` loads stay possible. */
|
|
26
|
+
export declare const VDB_POOL_RECORD_BYTES = 160;
|
|
27
|
+
/** Grid record size in u32 words. */
|
|
28
|
+
export declare const VDB_POOL_RECORD_WORDS: number;
|
|
29
|
+
/** Header word indices (§1.1). */
|
|
30
|
+
export declare const VDB_HEADER_WORD: {
|
|
31
|
+
/** {@link VDB_POOL_MAGIC}. */
|
|
32
|
+
readonly magic: 0;
|
|
33
|
+
/** {@link VDB_GPU_LAYOUT_VERSION}. */
|
|
34
|
+
readonly layoutVersion: 1;
|
|
35
|
+
/** Records in the table. */
|
|
36
|
+
readonly gridCapacity: 2;
|
|
37
|
+
/** Highest live grid id + 1 (`vdbGridCount()` in WGSL). */
|
|
38
|
+
readonly gridCount: 3;
|
|
39
|
+
/** {@link VDB_POOL_TABLE_OFFSET}, written for readers that don't know the version. */
|
|
40
|
+
readonly tableOffset: 4;
|
|
41
|
+
/** {@link VDB_POOL_RECORD_BYTES}. */
|
|
42
|
+
readonly recordBytes: 5;
|
|
43
|
+
/** Allocation high-water mark in bytes (diagnostics). */
|
|
44
|
+
readonly usedBytes: 6;
|
|
45
|
+
/** Always 0 in layout 1. */
|
|
46
|
+
readonly reserved: 7;
|
|
47
|
+
};
|
|
48
|
+
/** Grid record word indices (§1.2). Multi-word fields name their first word. */
|
|
49
|
+
export declare const VDB_RECORD_WORD: {
|
|
50
|
+
/** u32: image byte offset from the start of the pool; a multiple of 32. */
|
|
51
|
+
readonly imageOffset: 0;
|
|
52
|
+
/** u32: NanoVDB `GridData.mGridSize` (its high word must be 0). */
|
|
53
|
+
readonly imageBytes: 1;
|
|
54
|
+
/** u32: NanoVDB `GridType` id (1 Float, 13 Fp4, 14 Fp8, 15 Fp16, 16 FpN). */
|
|
55
|
+
readonly gridType: 2;
|
|
56
|
+
/** u32: see {@link VDB_RECORD_FLAG} and the class / brick-log2 bit fields. */
|
|
57
|
+
readonly flags: 3;
|
|
58
|
+
/** f32 x12: world -> index, 3x4 row-major (`idx = M * [p, 1]`). */
|
|
59
|
+
readonly worldToIndex: 4;
|
|
60
|
+
/** f32 x12: index -> world, 3x4 row-major. */
|
|
61
|
+
readonly indexToWorld: 16;
|
|
62
|
+
/** i32 x3: root active bbox min. */
|
|
63
|
+
readonly indexBBoxMin: 28;
|
|
64
|
+
/** f32: root background value. */
|
|
65
|
+
readonly background: 31;
|
|
66
|
+
/** i32 x3: root active bbox max (inclusive). */
|
|
67
|
+
readonly indexBBoxMax: 32;
|
|
68
|
+
/** f32: `max(root max stat, background)` or the caller's bound; the `global` majorant. */
|
|
69
|
+
readonly valueMax: 35;
|
|
70
|
+
/** u32: brick-majorant range byte offset; 0 = none. */
|
|
71
|
+
readonly majorantOffset: 36;
|
|
72
|
+
/** u32 x3: brick-majorant grid dimensions in cells. */
|
|
73
|
+
readonly majorantDims: 37;
|
|
74
|
+
};
|
|
75
|
+
/** Single-bit record flags (record word 3). */
|
|
76
|
+
export declare const VDB_RECORD_FLAG: {
|
|
77
|
+
/** b0: the record describes a live grid; a dead id reads 0 everywhere. */
|
|
78
|
+
readonly live: number;
|
|
79
|
+
/** b1: the image carries min/max stats (`GridData` flag `HasMinMax`). */
|
|
80
|
+
readonly hasStats: number;
|
|
81
|
+
/** b2: `majorantOffset`/`majorantDims` describe a brick-majorant range. */
|
|
82
|
+
readonly hasBrickMajorant: number;
|
|
83
|
+
/** b3: the affines include a host instance transform (`setTransform`). */
|
|
84
|
+
readonly instanceTransform: number;
|
|
85
|
+
};
|
|
86
|
+
/** Bit position of the 8-bit NanoVDB `GridClass` field in record word 3. */
|
|
87
|
+
export declare const VDB_RECORD_GRID_CLASS_SHIFT = 8;
|
|
88
|
+
/** Bit position of the 8-bit brick log2 field in record word 3. */
|
|
89
|
+
export declare const VDB_RECORD_BRICK_LOG2_SHIFT = 16;
|
|
90
|
+
/** Mask (after shifting) of the 8-bit class and brick-log2 fields. */
|
|
91
|
+
export declare const VDB_RECORD_BYTE_FIELD_MASK = 255;
|
|
92
|
+
/** Decoded pool header (§1.1). */
|
|
93
|
+
export interface VDBPoolHeader {
|
|
94
|
+
magic: number;
|
|
95
|
+
layoutVersion: number;
|
|
96
|
+
gridCapacity: number;
|
|
97
|
+
gridCount: number;
|
|
98
|
+
tableOffset: number;
|
|
99
|
+
recordBytes: number;
|
|
100
|
+
usedBytes: number;
|
|
101
|
+
}
|
|
102
|
+
export type { VDBVec3 };
|
|
103
|
+
/**
|
|
104
|
+
* Decoded grid record (§1.2). Affines hold the f32-rounded values the GPU sees;
|
|
105
|
+
* 12 entries each, 3x4 row-major.
|
|
106
|
+
*/
|
|
107
|
+
export interface VDBGridRecord {
|
|
108
|
+
imageOffset: number;
|
|
109
|
+
imageBytes: number;
|
|
110
|
+
gridType: number;
|
|
111
|
+
live: boolean;
|
|
112
|
+
hasStats: boolean;
|
|
113
|
+
hasBrickMajorant: boolean;
|
|
114
|
+
instanceTransform: boolean;
|
|
115
|
+
/** NanoVDB `GridClass` id (0-255). */
|
|
116
|
+
gridClass: number;
|
|
117
|
+
/** log2 of the brick edge in voxels (0-255; 0 when there is no brick majorant). */
|
|
118
|
+
brickLog2: number;
|
|
119
|
+
worldToIndex: number[];
|
|
120
|
+
indexToWorld: number[];
|
|
121
|
+
indexBBoxMin: VDBVec3;
|
|
122
|
+
indexBBoxMax: VDBVec3;
|
|
123
|
+
background: number;
|
|
124
|
+
valueMax: number;
|
|
125
|
+
majorantOffset: number;
|
|
126
|
+
majorantDims: VDBVec3;
|
|
127
|
+
}
|
|
128
|
+
/** Rounds `n` up to the pool alignment ({@link VDB_POOL_ALIGN}). */
|
|
129
|
+
export declare function align32(n: number): number;
|
|
130
|
+
/** Byte offset of record `id`. */
|
|
131
|
+
export declare function recordByteOffset(id: number): number;
|
|
132
|
+
/** First byte after a table of `capacity` records, aligned: where ranges may start. */
|
|
133
|
+
export declare function dataStartOffset(capacity: number): number;
|
|
134
|
+
/** Writes the header's 8 words into `out` at `wordOffset` and returns `out`. */
|
|
135
|
+
export declare function encodeHeader(header: Omit<VDBPoolHeader, "magic" | "layoutVersion" | "tableOffset" | "recordBytes">, out?: Uint32Array, wordOffset?: number): Uint32Array;
|
|
136
|
+
/** Reads a header from `words` at `wordOffset` (no validation; see {@link VDBPoolHeader}). */
|
|
137
|
+
export declare function decodeHeader(words: Uint32Array, wordOffset?: number): VDBPoolHeader;
|
|
138
|
+
/**
|
|
139
|
+
* Writes `record` as 40 words into `out` at `wordOffset` and returns `out`.
|
|
140
|
+
* Affines are rounded to f32 here; pass the f64 values you composed.
|
|
141
|
+
*/
|
|
142
|
+
export declare function encodeRecord(record: VDBGridRecord, out?: Uint32Array, wordOffset?: number): Uint32Array;
|
|
143
|
+
/** Reads the 40-word record at `wordOffset` of `words`. */
|
|
144
|
+
export declare function decodeRecord(words: Uint32Array, wordOffset?: number): VDBGridRecord;
|
|
145
|
+
/**
|
|
146
|
+
* WGSL `const` declarations for layout {@link VDB_GPU_LAYOUT_VERSION}, generated
|
|
147
|
+
* from the tables in this file. Pure and deterministic: same package version,
|
|
148
|
+
* same text. Every name carries the `VDB_` prefix (D10, K1-core §3.4) and no
|
|
149
|
+
* comment contains a back-tick (CLAUDE.md Traps).
|
|
150
|
+
*
|
|
151
|
+
* Emitted names (all `u32`):
|
|
152
|
+
* - `VDB_GPU_LAYOUT_VERSION`, `VDB_POOL_MAGIC`
|
|
153
|
+
* - `VDB_POOL_TABLE_OFFSET` (bytes), `VDB_POOL_TABLE_WORD` (= offset / 4),
|
|
154
|
+
* `VDB_POOL_RECORD_BYTES`, `VDB_POOL_RECORD_WORDS`, `VDB_POOL_ALIGN`
|
|
155
|
+
* - `VDB_HEADER_<FIELD>` for every {@link VDB_HEADER_WORD} entry (word index),
|
|
156
|
+
* e.g. `VDB_HEADER_GRID_COUNT = 3u`
|
|
157
|
+
* - `VDB_REC_<FIELD>` for every {@link VDB_RECORD_WORD} entry (word index within
|
|
158
|
+
* a record), e.g. `VDB_REC_IMAGE_OFFSET = 0u`, `VDB_REC_WORLD_TO_INDEX = 4u`
|
|
159
|
+
* - `VDB_REC_FLAG_<NAME>` for every {@link VDB_RECORD_FLAG} bit, plus
|
|
160
|
+
* `VDB_REC_GRID_CLASS_SHIFT`, `VDB_REC_BRICK_LOG2_SHIFT`, `VDB_REC_BYTE_FIELD_MASK`
|
|
161
|
+
*
|
|
162
|
+
* Word `w` of record `g` is `vdb_load(VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w)`.
|
|
163
|
+
*/
|
|
164
|
+
export declare function vdbPoolLayoutWgsl(): string;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pool buffer layout 1 (docs/dev/design/K1-core.md §1): a 32-byte header, a table of
|
|
3
|
+
* fixed-stride 160-byte grid records, then 32-byte-aligned ranges (NanoVDB
|
|
4
|
+
* images, brick-majorant grids).
|
|
5
|
+
*
|
|
6
|
+
* This file is the single source of truth for every header word, record word
|
|
7
|
+
* and flag bit. The TypeScript encoders below and the WGSL constants returned by
|
|
8
|
+
* {@link vdbPoolLayoutWgsl} are both derived from the tables in this file, so the
|
|
9
|
+
* CPU writer and the GPU reader cannot drift apart. Any change to a word or its
|
|
10
|
+
* meaning bumps {@link VDB_GPU_LAYOUT_VERSION} and is a breaking change (§1.8).
|
|
11
|
+
*/
|
|
12
|
+
import { VDBError } from "../errors.js";
|
|
13
|
+
/** Layout version written to header word 1 and baked into generated WGSL. */
|
|
14
|
+
export const VDB_GPU_LAYOUT_VERSION = 1;
|
|
15
|
+
/** Header word 0: `"VDBP"` read as a little-endian u32. */
|
|
16
|
+
export const VDB_POOL_MAGIC = 0x50424456;
|
|
17
|
+
/** Every range in the pool (table, images, majorants) starts on this byte alignment (NanoVDB's data alignment). */
|
|
18
|
+
export const VDB_POOL_ALIGN = 32;
|
|
19
|
+
/** Header size in bytes. */
|
|
20
|
+
export const VDB_POOL_HEADER_BYTES = 32;
|
|
21
|
+
/** Header size in u32 words. */
|
|
22
|
+
export const VDB_POOL_HEADER_WORDS = VDB_POOL_HEADER_BYTES / 4;
|
|
23
|
+
/** Byte offset of record 0 (fixed in layout 1). */
|
|
24
|
+
export const VDB_POOL_TABLE_OFFSET = 32;
|
|
25
|
+
/** Grid record size in bytes. A multiple of 16 so `vec4` loads stay possible. */
|
|
26
|
+
export const VDB_POOL_RECORD_BYTES = 160;
|
|
27
|
+
/** Grid record size in u32 words. */
|
|
28
|
+
export const VDB_POOL_RECORD_WORDS = VDB_POOL_RECORD_BYTES / 4;
|
|
29
|
+
/** Header word indices (§1.1). */
|
|
30
|
+
export const VDB_HEADER_WORD = {
|
|
31
|
+
/** {@link VDB_POOL_MAGIC}. */
|
|
32
|
+
magic: 0,
|
|
33
|
+
/** {@link VDB_GPU_LAYOUT_VERSION}. */
|
|
34
|
+
layoutVersion: 1,
|
|
35
|
+
/** Records in the table. */
|
|
36
|
+
gridCapacity: 2,
|
|
37
|
+
/** Highest live grid id + 1 (`vdbGridCount()` in WGSL). */
|
|
38
|
+
gridCount: 3,
|
|
39
|
+
/** {@link VDB_POOL_TABLE_OFFSET}, written for readers that don't know the version. */
|
|
40
|
+
tableOffset: 4,
|
|
41
|
+
/** {@link VDB_POOL_RECORD_BYTES}. */
|
|
42
|
+
recordBytes: 5,
|
|
43
|
+
/** Allocation high-water mark in bytes (diagnostics). */
|
|
44
|
+
usedBytes: 6,
|
|
45
|
+
/** Always 0 in layout 1. */
|
|
46
|
+
reserved: 7,
|
|
47
|
+
};
|
|
48
|
+
/** Grid record word indices (§1.2). Multi-word fields name their first word. */
|
|
49
|
+
export const VDB_RECORD_WORD = {
|
|
50
|
+
/** u32: image byte offset from the start of the pool; a multiple of 32. */
|
|
51
|
+
imageOffset: 0,
|
|
52
|
+
/** u32: NanoVDB `GridData.mGridSize` (its high word must be 0). */
|
|
53
|
+
imageBytes: 1,
|
|
54
|
+
/** u32: NanoVDB `GridType` id (1 Float, 13 Fp4, 14 Fp8, 15 Fp16, 16 FpN). */
|
|
55
|
+
gridType: 2,
|
|
56
|
+
/** u32: see {@link VDB_RECORD_FLAG} and the class / brick-log2 bit fields. */
|
|
57
|
+
flags: 3,
|
|
58
|
+
/** f32 x12: world -> index, 3x4 row-major (`idx = M * [p, 1]`). */
|
|
59
|
+
worldToIndex: 4,
|
|
60
|
+
/** f32 x12: index -> world, 3x4 row-major. */
|
|
61
|
+
indexToWorld: 16,
|
|
62
|
+
/** i32 x3: root active bbox min. */
|
|
63
|
+
indexBBoxMin: 28,
|
|
64
|
+
/** f32: root background value. */
|
|
65
|
+
background: 31,
|
|
66
|
+
/** i32 x3: root active bbox max (inclusive). */
|
|
67
|
+
indexBBoxMax: 32,
|
|
68
|
+
/** f32: `max(root max stat, background)` or the caller's bound; the `global` majorant. */
|
|
69
|
+
valueMax: 35,
|
|
70
|
+
/** u32: brick-majorant range byte offset; 0 = none. */
|
|
71
|
+
majorantOffset: 36,
|
|
72
|
+
/** u32 x3: brick-majorant grid dimensions in cells. */
|
|
73
|
+
majorantDims: 37,
|
|
74
|
+
};
|
|
75
|
+
/** Single-bit record flags (record word 3). */
|
|
76
|
+
export const VDB_RECORD_FLAG = {
|
|
77
|
+
/** b0: the record describes a live grid; a dead id reads 0 everywhere. */
|
|
78
|
+
live: 1 << 0,
|
|
79
|
+
/** b1: the image carries min/max stats (`GridData` flag `HasMinMax`). */
|
|
80
|
+
hasStats: 1 << 1,
|
|
81
|
+
/** b2: `majorantOffset`/`majorantDims` describe a brick-majorant range. */
|
|
82
|
+
hasBrickMajorant: 1 << 2,
|
|
83
|
+
/** b3: the affines include a host instance transform (`setTransform`). */
|
|
84
|
+
instanceTransform: 1 << 3,
|
|
85
|
+
};
|
|
86
|
+
/** Bit position of the 8-bit NanoVDB `GridClass` field in record word 3. */
|
|
87
|
+
export const VDB_RECORD_GRID_CLASS_SHIFT = 8;
|
|
88
|
+
/** Bit position of the 8-bit brick log2 field in record word 3. */
|
|
89
|
+
export const VDB_RECORD_BRICK_LOG2_SHIFT = 16;
|
|
90
|
+
/** Mask (after shifting) of the 8-bit class and brick-log2 fields. */
|
|
91
|
+
export const VDB_RECORD_BYTE_FIELD_MASK = 0xff;
|
|
92
|
+
/** Rounds `n` up to the pool alignment ({@link VDB_POOL_ALIGN}). */
|
|
93
|
+
export function align32(n) {
|
|
94
|
+
return Math.ceil(n / VDB_POOL_ALIGN) * VDB_POOL_ALIGN;
|
|
95
|
+
}
|
|
96
|
+
/** Byte offset of record `id`. */
|
|
97
|
+
export function recordByteOffset(id) {
|
|
98
|
+
return VDB_POOL_TABLE_OFFSET + id * VDB_POOL_RECORD_BYTES;
|
|
99
|
+
}
|
|
100
|
+
/** First byte after a table of `capacity` records, aligned: where ranges may start. */
|
|
101
|
+
export function dataStartOffset(capacity) {
|
|
102
|
+
return align32(VDB_POOL_TABLE_OFFSET + capacity * VDB_POOL_RECORD_BYTES);
|
|
103
|
+
}
|
|
104
|
+
/** Writes the header's 8 words into `out` at `wordOffset` and returns `out`. */
|
|
105
|
+
export function encodeHeader(header, out = new Uint32Array(VDB_POOL_HEADER_WORDS), wordOffset = 0) {
|
|
106
|
+
const w = VDB_HEADER_WORD;
|
|
107
|
+
out[wordOffset + w.magic] = VDB_POOL_MAGIC;
|
|
108
|
+
out[wordOffset + w.layoutVersion] = VDB_GPU_LAYOUT_VERSION;
|
|
109
|
+
out[wordOffset + w.gridCapacity] = header.gridCapacity;
|
|
110
|
+
out[wordOffset + w.gridCount] = header.gridCount;
|
|
111
|
+
out[wordOffset + w.tableOffset] = VDB_POOL_TABLE_OFFSET;
|
|
112
|
+
out[wordOffset + w.recordBytes] = VDB_POOL_RECORD_BYTES;
|
|
113
|
+
out[wordOffset + w.usedBytes] = header.usedBytes;
|
|
114
|
+
out[wordOffset + w.reserved] = 0;
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
/** Reads a header from `words` at `wordOffset` (no validation; see {@link VDBPoolHeader}). */
|
|
118
|
+
export function decodeHeader(words, wordOffset = 0) {
|
|
119
|
+
const w = VDB_HEADER_WORD;
|
|
120
|
+
const at = (i) => words[wordOffset + i] ?? 0;
|
|
121
|
+
return {
|
|
122
|
+
magic: at(w.magic),
|
|
123
|
+
layoutVersion: at(w.layoutVersion),
|
|
124
|
+
gridCapacity: at(w.gridCapacity),
|
|
125
|
+
gridCount: at(w.gridCount),
|
|
126
|
+
tableOffset: at(w.tableOffset),
|
|
127
|
+
recordBytes: at(w.recordBytes),
|
|
128
|
+
usedBytes: at(w.usedBytes),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function views(words) {
|
|
132
|
+
return {
|
|
133
|
+
f32: new Float32Array(words.buffer, words.byteOffset, words.length),
|
|
134
|
+
i32: new Int32Array(words.buffer, words.byteOffset, words.length),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function byteField(name, value) {
|
|
138
|
+
if (!Number.isInteger(value) || value < 0 || value > VDB_RECORD_BYTE_FIELD_MASK) {
|
|
139
|
+
throw new VDBError("VDB_BAD_OPTION", `encodeRecord: ${name} must be an integer in 0..255, got ${value}.`);
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Writes `record` as 40 words into `out` at `wordOffset` and returns `out`.
|
|
145
|
+
* Affines are rounded to f32 here; pass the f64 values you composed.
|
|
146
|
+
*/
|
|
147
|
+
export function encodeRecord(record, out = new Uint32Array(VDB_POOL_RECORD_WORDS), wordOffset = 0) {
|
|
148
|
+
if (record.worldToIndex.length !== 12 || record.indexToWorld.length !== 12) {
|
|
149
|
+
throw new VDBError("VDB_BAD_OPTION", "encodeRecord: worldToIndex and indexToWorld must each have 12 entries (3x4 row-major).");
|
|
150
|
+
}
|
|
151
|
+
if (out.length < wordOffset + VDB_POOL_RECORD_WORDS) {
|
|
152
|
+
throw new VDBError("VDB_BAD_OPTION", `encodeRecord: output has ${out.length} words; a record at word ${wordOffset} needs ${wordOffset + VDB_POOL_RECORD_WORDS}.`);
|
|
153
|
+
}
|
|
154
|
+
const { f32, i32 } = views(out);
|
|
155
|
+
const r = VDB_RECORD_WORD;
|
|
156
|
+
const o = wordOffset;
|
|
157
|
+
const F = VDB_RECORD_FLAG;
|
|
158
|
+
let flags = 0;
|
|
159
|
+
if (record.live)
|
|
160
|
+
flags |= F.live;
|
|
161
|
+
if (record.hasStats)
|
|
162
|
+
flags |= F.hasStats;
|
|
163
|
+
if (record.hasBrickMajorant)
|
|
164
|
+
flags |= F.hasBrickMajorant;
|
|
165
|
+
if (record.instanceTransform)
|
|
166
|
+
flags |= F.instanceTransform;
|
|
167
|
+
flags |= byteField("gridClass", record.gridClass) << VDB_RECORD_GRID_CLASS_SHIFT;
|
|
168
|
+
flags |= byteField("brickLog2", record.brickLog2) << VDB_RECORD_BRICK_LOG2_SHIFT;
|
|
169
|
+
out[o + r.imageOffset] = record.imageOffset;
|
|
170
|
+
out[o + r.imageBytes] = record.imageBytes;
|
|
171
|
+
out[o + r.gridType] = record.gridType;
|
|
172
|
+
out[o + r.flags] = flags >>> 0;
|
|
173
|
+
for (let k = 0; k < 12; k++) {
|
|
174
|
+
f32[o + r.worldToIndex + k] = record.worldToIndex[k];
|
|
175
|
+
f32[o + r.indexToWorld + k] = record.indexToWorld[k];
|
|
176
|
+
}
|
|
177
|
+
for (let k = 0; k < 3; k++) {
|
|
178
|
+
i32[o + r.indexBBoxMin + k] = record.indexBBoxMin[k];
|
|
179
|
+
i32[o + r.indexBBoxMax + k] = record.indexBBoxMax[k];
|
|
180
|
+
out[o + r.majorantDims + k] = record.majorantDims[k];
|
|
181
|
+
}
|
|
182
|
+
f32[o + r.background] = record.background;
|
|
183
|
+
f32[o + r.valueMax] = record.valueMax;
|
|
184
|
+
out[o + r.majorantOffset] = record.majorantOffset;
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
/** Reads the 40-word record at `wordOffset` of `words`. */
|
|
188
|
+
export function decodeRecord(words, wordOffset = 0) {
|
|
189
|
+
if (words.length < wordOffset + VDB_POOL_RECORD_WORDS) {
|
|
190
|
+
throw new VDBError("VDB_BAD_OPTION", `decodeRecord: input has ${words.length} words; a record at word ${wordOffset} needs ${wordOffset + VDB_POOL_RECORD_WORDS}.`);
|
|
191
|
+
}
|
|
192
|
+
const { f32, i32 } = views(words);
|
|
193
|
+
const r = VDB_RECORD_WORD;
|
|
194
|
+
const o = wordOffset;
|
|
195
|
+
const flags = words[o + r.flags];
|
|
196
|
+
const F = VDB_RECORD_FLAG;
|
|
197
|
+
const vec = (src, at) => [src[o + at], src[o + at + 1], src[o + at + 2]];
|
|
198
|
+
return {
|
|
199
|
+
imageOffset: words[o + r.imageOffset],
|
|
200
|
+
imageBytes: words[o + r.imageBytes],
|
|
201
|
+
gridType: words[o + r.gridType],
|
|
202
|
+
live: (flags & F.live) !== 0,
|
|
203
|
+
hasStats: (flags & F.hasStats) !== 0,
|
|
204
|
+
hasBrickMajorant: (flags & F.hasBrickMajorant) !== 0,
|
|
205
|
+
instanceTransform: (flags & F.instanceTransform) !== 0,
|
|
206
|
+
gridClass: (flags >>> VDB_RECORD_GRID_CLASS_SHIFT) & VDB_RECORD_BYTE_FIELD_MASK,
|
|
207
|
+
brickLog2: (flags >>> VDB_RECORD_BRICK_LOG2_SHIFT) & VDB_RECORD_BYTE_FIELD_MASK,
|
|
208
|
+
worldToIndex: Array.from(f32.subarray(o + r.worldToIndex, o + r.worldToIndex + 12)),
|
|
209
|
+
indexToWorld: Array.from(f32.subarray(o + r.indexToWorld, o + r.indexToWorld + 12)),
|
|
210
|
+
indexBBoxMin: vec(i32, r.indexBBoxMin),
|
|
211
|
+
indexBBoxMax: vec(i32, r.indexBBoxMax),
|
|
212
|
+
background: f32[o + r.background],
|
|
213
|
+
valueMax: f32[o + r.valueMax],
|
|
214
|
+
majorantOffset: words[o + r.majorantOffset],
|
|
215
|
+
majorantDims: vec(words, r.majorantDims),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/** `fooBarBaz` -> `FOO_BAR_BAZ`. */
|
|
219
|
+
function upperSnake(name) {
|
|
220
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toUpperCase();
|
|
221
|
+
}
|
|
222
|
+
function u32Hex(n) {
|
|
223
|
+
return `0x${(n >>> 0).toString(16)}u`;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* WGSL `const` declarations for layout {@link VDB_GPU_LAYOUT_VERSION}, generated
|
|
227
|
+
* from the tables in this file. Pure and deterministic: same package version,
|
|
228
|
+
* same text. Every name carries the `VDB_` prefix (D10, K1-core §3.4) and no
|
|
229
|
+
* comment contains a back-tick (CLAUDE.md Traps).
|
|
230
|
+
*
|
|
231
|
+
* Emitted names (all `u32`):
|
|
232
|
+
* - `VDB_GPU_LAYOUT_VERSION`, `VDB_POOL_MAGIC`
|
|
233
|
+
* - `VDB_POOL_TABLE_OFFSET` (bytes), `VDB_POOL_TABLE_WORD` (= offset / 4),
|
|
234
|
+
* `VDB_POOL_RECORD_BYTES`, `VDB_POOL_RECORD_WORDS`, `VDB_POOL_ALIGN`
|
|
235
|
+
* - `VDB_HEADER_<FIELD>` for every {@link VDB_HEADER_WORD} entry (word index),
|
|
236
|
+
* e.g. `VDB_HEADER_GRID_COUNT = 3u`
|
|
237
|
+
* - `VDB_REC_<FIELD>` for every {@link VDB_RECORD_WORD} entry (word index within
|
|
238
|
+
* a record), e.g. `VDB_REC_IMAGE_OFFSET = 0u`, `VDB_REC_WORLD_TO_INDEX = 4u`
|
|
239
|
+
* - `VDB_REC_FLAG_<NAME>` for every {@link VDB_RECORD_FLAG} bit, plus
|
|
240
|
+
* `VDB_REC_GRID_CLASS_SHIFT`, `VDB_REC_BRICK_LOG2_SHIFT`, `VDB_REC_BYTE_FIELD_MASK`
|
|
241
|
+
*
|
|
242
|
+
* Word `w` of record `g` is `vdb_load(VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w)`.
|
|
243
|
+
*/
|
|
244
|
+
export function vdbPoolLayoutWgsl() {
|
|
245
|
+
const lines = [
|
|
246
|
+
`// @pmndrs/vdb pool layout ${VDB_GPU_LAYOUT_VERSION} (generated from core/pool/layout.ts; do not edit).`,
|
|
247
|
+
`const VDB_GPU_LAYOUT_VERSION: u32 = ${VDB_GPU_LAYOUT_VERSION}u;`,
|
|
248
|
+
`const VDB_POOL_MAGIC: u32 = ${u32Hex(VDB_POOL_MAGIC)};`,
|
|
249
|
+
`const VDB_POOL_ALIGN: u32 = ${VDB_POOL_ALIGN}u;`,
|
|
250
|
+
`const VDB_POOL_TABLE_OFFSET: u32 = ${VDB_POOL_TABLE_OFFSET}u;`,
|
|
251
|
+
`const VDB_POOL_TABLE_WORD: u32 = ${VDB_POOL_TABLE_OFFSET / 4}u;`,
|
|
252
|
+
`const VDB_POOL_RECORD_BYTES: u32 = ${VDB_POOL_RECORD_BYTES}u;`,
|
|
253
|
+
`const VDB_POOL_RECORD_WORDS: u32 = ${VDB_POOL_RECORD_WORDS}u;`,
|
|
254
|
+
];
|
|
255
|
+
for (const [name, word] of Object.entries(VDB_HEADER_WORD)) {
|
|
256
|
+
lines.push(`const VDB_HEADER_${upperSnake(name)}: u32 = ${word}u;`);
|
|
257
|
+
}
|
|
258
|
+
for (const [name, word] of Object.entries(VDB_RECORD_WORD)) {
|
|
259
|
+
lines.push(`const VDB_REC_${upperSnake(name)}: u32 = ${word}u;`);
|
|
260
|
+
}
|
|
261
|
+
for (const [name, bit] of Object.entries(VDB_RECORD_FLAG)) {
|
|
262
|
+
lines.push(`const VDB_REC_FLAG_${upperSnake(name)}: u32 = ${u32Hex(bit)};`);
|
|
263
|
+
}
|
|
264
|
+
lines.push(`const VDB_REC_GRID_CLASS_SHIFT: u32 = ${VDB_RECORD_GRID_CLASS_SHIFT}u;`, `const VDB_REC_BRICK_LOG2_SHIFT: u32 = ${VDB_RECORD_BRICK_LOG2_SHIFT}u;`, `const VDB_REC_BYTE_FIELD_MASK: u32 = ${u32Hex(VDB_RECORD_BYTE_FIELD_MASK)};`);
|
|
265
|
+
return lines.join("\n") + "\n";
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=layout.js.map
|