@pmndrs/vdb 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/CHANGELOG.md +727 -0
  2. package/LICENSE +21 -0
  3. package/README.md +496 -2
  4. package/THIRD_PARTY_NOTICES.md +315 -0
  5. package/dist/core/compute/atlas.d.ts +102 -0
  6. package/dist/core/compute/atlas.js +103 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/majorant-build.d.ts +45 -0
  12. package/dist/core/compute/majorant-build.js +193 -0
  13. package/dist/core/compute/majorant-build.js.map +1 -0
  14. package/dist/core/compute/multi-scale.d.ts +155 -0
  15. package/dist/core/compute/multi-scale.js +684 -0
  16. package/dist/core/compute/multi-scale.js.map +1 -0
  17. package/dist/core/compute/pyramid.d.ts +120 -0
  18. package/dist/core/compute/pyramid.js +468 -0
  19. package/dist/core/compute/pyramid.js.map +1 -0
  20. package/dist/core/compute/shared.d.ts +116 -0
  21. package/dist/core/compute/shared.js +211 -0
  22. package/dist/core/compute/shared.js.map +1 -0
  23. package/dist/core/compute/stats.d.ts +78 -0
  24. package/dist/core/compute/stats.js +193 -0
  25. package/dist/core/compute/stats.js.map +1 -0
  26. package/dist/core/compute/value-transform.d.ts +30 -0
  27. package/dist/core/compute/value-transform.js +64 -0
  28. package/dist/core/compute/value-transform.js.map +1 -0
  29. package/dist/core/errors.d.ts +21 -0
  30. package/dist/core/errors.js +17 -0
  31. package/dist/core/errors.js.map +1 -0
  32. package/dist/core/frame/emission.d.ts +85 -0
  33. package/dist/core/frame/emission.js +422 -0
  34. package/dist/core/frame/emission.js.map +1 -0
  35. package/dist/core/frame/environment.d.ts +47 -0
  36. package/dist/core/frame/environment.js +178 -0
  37. package/dist/core/frame/environment.js.map +1 -0
  38. package/dist/core/frame/index.d.ts +39 -0
  39. package/dist/core/frame/index.js +27 -0
  40. package/dist/core/frame/index.js.map +1 -0
  41. package/dist/core/frame/kernels.d.ts +115 -0
  42. package/dist/core/frame/kernels.js +496 -0
  43. package/dist/core/frame/kernels.js.map +1 -0
  44. package/dist/core/frame/limits.d.ts +67 -0
  45. package/dist/core/frame/limits.js +109 -0
  46. package/dist/core/frame/limits.js.map +1 -0
  47. package/dist/core/frame/phase.d.ts +17 -0
  48. package/dist/core/frame/phase.js +53 -0
  49. package/dist/core/frame/phase.js.map +1 -0
  50. package/dist/core/frame/pipelines.d.ts +49 -0
  51. package/dist/core/frame/pipelines.js +147 -0
  52. package/dist/core/frame/pipelines.js.map +1 -0
  53. package/dist/core/frame/renderer.d.ts +122 -0
  54. package/dist/core/frame/renderer.js +1712 -0
  55. package/dist/core/frame/renderer.js.map +1 -0
  56. package/dist/core/frame/resources.d.ts +71 -0
  57. package/dist/core/frame/resources.js +100 -0
  58. package/dist/core/frame/resources.js.map +1 -0
  59. package/dist/core/frame/scattering.d.ts +97 -0
  60. package/dist/core/frame/scattering.js +332 -0
  61. package/dist/core/frame/scattering.js.map +1 -0
  62. package/dist/core/frame/settings.d.ts +243 -0
  63. package/dist/core/frame/settings.js +67 -0
  64. package/dist/core/frame/settings.js.map +1 -0
  65. package/dist/core/frame/shadows.d.ts +55 -0
  66. package/dist/core/frame/shadows.js +460 -0
  67. package/dist/core/frame/shadows.js.map +1 -0
  68. package/dist/core/frame/types.d.ts +415 -0
  69. package/dist/core/frame/types.js +49 -0
  70. package/dist/core/frame/types.js.map +1 -0
  71. package/dist/core/frame/uniforms.d.ts +105 -0
  72. package/dist/core/frame/uniforms.js +276 -0
  73. package/dist/core/frame/uniforms.js.map +1 -0
  74. package/dist/core/frame/wgsl/chunks.d.ts +4 -0
  75. package/dist/core/frame/wgsl/chunks.js +728 -0
  76. package/dist/core/frame/wgsl/chunks.js.map +1 -0
  77. package/dist/core/frame/wgsl/emission.d.ts +82 -0
  78. package/dist/core/frame/wgsl/emission.js +353 -0
  79. package/dist/core/frame/wgsl/emission.js.map +1 -0
  80. package/dist/core/frame/wgsl/environment.d.ts +42 -0
  81. package/dist/core/frame/wgsl/environment.js +711 -0
  82. package/dist/core/frame/wgsl/environment.js.map +1 -0
  83. package/dist/core/frame/wgsl/gather.d.ts +55 -0
  84. package/dist/core/frame/wgsl/gather.js +850 -0
  85. package/dist/core/frame/wgsl/gather.js.map +1 -0
  86. package/dist/core/frame/wgsl/integrate.d.ts +78 -0
  87. package/dist/core/frame/wgsl/integrate.js +213 -0
  88. package/dist/core/frame/wgsl/integrate.js.map +1 -0
  89. package/dist/core/frame/wgsl/lighting.d.ts +103 -0
  90. package/dist/core/frame/wgsl/lighting.js +1636 -0
  91. package/dist/core/frame/wgsl/lighting.js.map +1 -0
  92. package/dist/core/frame/wgsl/occluders.d.ts +20 -0
  93. package/dist/core/frame/wgsl/occluders.js +95 -0
  94. package/dist/core/frame/wgsl/occluders.js.map +1 -0
  95. package/dist/core/frame/wgsl/resolve.d.ts +19 -0
  96. package/dist/core/frame/wgsl/resolve.js +205 -0
  97. package/dist/core/frame/wgsl/resolve.js.map +1 -0
  98. package/dist/core/frame/wgsl/shadows.d.ts +35 -0
  99. package/dist/core/frame/wgsl/shadows.js +328 -0
  100. package/dist/core/frame/wgsl/shadows.js.map +1 -0
  101. package/dist/core/half.d.ts +11 -0
  102. package/dist/core/half.js +22 -0
  103. package/dist/core/half.js.map +1 -0
  104. package/dist/core/index.d.ts +52 -0
  105. package/dist/core/index.js +46 -0
  106. package/dist/core/index.js.map +1 -0
  107. package/dist/core/internal.d.ts +31 -0
  108. package/dist/core/internal.js +32 -0
  109. package/dist/core/internal.js.map +1 -0
  110. package/dist/core/pool/affine.d.ts +34 -0
  111. package/dist/core/pool/affine.js +100 -0
  112. package/dist/core/pool/affine.js.map +1 -0
  113. package/dist/core/pool/allocator.d.ts +32 -0
  114. package/dist/core/pool/allocator.js +81 -0
  115. package/dist/core/pool/allocator.js.map +1 -0
  116. package/dist/core/pool/image-header.d.ts +93 -0
  117. package/dist/core/pool/image-header.js +194 -0
  118. package/dist/core/pool/image-header.js.map +1 -0
  119. package/dist/core/pool/layout.d.ts +198 -0
  120. package/dist/core/pool/layout.js +316 -0
  121. package/dist/core/pool/layout.js.map +1 -0
  122. package/dist/core/pool/limits.d.ts +41 -0
  123. package/dist/core/pool/limits.js +80 -0
  124. package/dist/core/pool/limits.js.map +1 -0
  125. package/dist/core/pool/pool.d.ts +384 -0
  126. package/dist/core/pool/pool.js +1184 -0
  127. package/dist/core/pool/pool.js.map +1 -0
  128. package/dist/core/reference/index.d.ts +6 -0
  129. package/dist/core/reference/index.js +7 -0
  130. package/dist/core/reference/index.js.map +1 -0
  131. package/dist/core/reference/renderer.d.ts +105 -0
  132. package/dist/core/reference/renderer.js +474 -0
  133. package/dist/core/reference/renderer.js.map +1 -0
  134. package/dist/core/reference/wgsl.d.ts +65 -0
  135. package/dist/core/reference/wgsl.js +803 -0
  136. package/dist/core/reference/wgsl.js.map +1 -0
  137. package/dist/core/sequence.d.ts +347 -0
  138. package/dist/core/sequence.js +548 -0
  139. package/dist/core/sequence.js.map +1 -0
  140. package/dist/core/source/brick-cache.d.ts +165 -0
  141. package/dist/core/source/brick-cache.js +627 -0
  142. package/dist/core/source/brick-cache.js.map +1 -0
  143. package/dist/core/source/dense-fill.d.ts +53 -0
  144. package/dist/core/source/dense-fill.js +377 -0
  145. package/dist/core/source/dense-fill.js.map +1 -0
  146. package/dist/core/source/dense.d.ts +50 -0
  147. package/dist/core/source/dense.js +384 -0
  148. package/dist/core/source/dense.js.map +1 -0
  149. package/dist/core/source/sparse-wgsl.d.ts +92 -0
  150. package/dist/core/source/sparse-wgsl.js +481 -0
  151. package/dist/core/source/sparse-wgsl.js.map +1 -0
  152. package/dist/core/source/sparse.d.ts +192 -0
  153. package/dist/core/source/sparse.js +762 -0
  154. package/dist/core/source/sparse.js.map +1 -0
  155. package/dist/core/source/types.d.ts +120 -0
  156. package/dist/core/source/types.js +9 -0
  157. package/dist/core/source/types.js.map +1 -0
  158. package/dist/core/surface/index.d.ts +10 -0
  159. package/dist/core/surface/index.js +9 -0
  160. package/dist/core/surface/index.js.map +1 -0
  161. package/dist/core/surface/level-set-pass.d.ts +140 -0
  162. package/dist/core/surface/level-set-pass.js +291 -0
  163. package/dist/core/surface/level-set-pass.js.map +1 -0
  164. package/dist/core/surface/level-set-wgsl.d.ts +46 -0
  165. package/dist/core/surface/level-set-wgsl.js +99 -0
  166. package/dist/core/surface/level-set-wgsl.js.map +1 -0
  167. package/dist/core/surface/points.d.ts +109 -0
  168. package/dist/core/surface/points.js +226 -0
  169. package/dist/core/surface/points.js.map +1 -0
  170. package/dist/core/types.d.ts +37 -0
  171. package/dist/core/types.js +32 -0
  172. package/dist/core/types.js.map +1 -0
  173. package/dist/core/wgsl/api.d.ts +65 -0
  174. package/dist/core/wgsl/api.js +546 -0
  175. package/dist/core/wgsl/api.js.map +1 -0
  176. package/dist/core/wgsl/generate.d.ts +90 -0
  177. package/dist/core/wgsl/generate.js +678 -0
  178. package/dist/core/wgsl/generate.js.map +1 -0
  179. package/dist/core/wgsl/lean.d.ts +50 -0
  180. package/dist/core/wgsl/lean.js +327 -0
  181. package/dist/core/wgsl/lean.js.map +1 -0
  182. package/dist/core/wgsl/level-set.d.ts +58 -0
  183. package/dist/core/wgsl/level-set.js +200 -0
  184. package/dist/core/wgsl/level-set.js.map +1 -0
  185. package/dist/core/wgsl/majorant.d.ts +62 -0
  186. package/dist/core/wgsl/majorant.js +381 -0
  187. package/dist/core/wgsl/majorant.js.map +1 -0
  188. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  189. package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
  190. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  191. package/dist/core/wgsl/reserved.d.ts +9 -0
  192. package/dist/core/wgsl/reserved.js +26 -0
  193. package/dist/core/wgsl/reserved.js.map +1 -0
  194. package/dist/core/wgsl/types.d.ts +198 -0
  195. package/dist/core/wgsl/types.js +2 -0
  196. package/dist/core/wgsl/types.js.map +1 -0
  197. package/dist/three/coarse-first.d.ts +207 -0
  198. package/dist/three/coarse-first.js +205 -0
  199. package/dist/three/coarse-first.js.map +1 -0
  200. package/dist/three/compute.d.ts +73 -0
  201. package/dist/three/compute.js +66 -0
  202. package/dist/three/compute.js.map +1 -0
  203. package/dist/three/device.d.ts +66 -0
  204. package/dist/three/device.js +62 -0
  205. package/dist/three/device.js.map +1 -0
  206. package/dist/three/frame/core-environment.d.ts +38 -0
  207. package/dist/three/frame/core-environment.js +154 -0
  208. package/dist/three/frame/core-environment.js.map +1 -0
  209. package/dist/three/frame/core-integrate-material.d.ts +34 -0
  210. package/dist/three/frame/core-integrate-material.js +162 -0
  211. package/dist/three/frame/core-integrate-material.js.map +1 -0
  212. package/dist/three/frame/core-occluders.d.ts +53 -0
  213. package/dist/three/frame/core-occluders.js +193 -0
  214. package/dist/three/frame/core-occluders.js.map +1 -0
  215. package/dist/three/frame/core-structs.d.ts +34 -0
  216. package/dist/three/frame/core-structs.js +61 -0
  217. package/dist/three/frame/core-structs.js.map +1 -0
  218. package/dist/three/frame/core-textures.d.ts +41 -0
  219. package/dist/three/frame/core-textures.js +114 -0
  220. package/dist/three/frame/core-textures.js.map +1 -0
  221. package/dist/three/frame/emission-light.d.ts +117 -0
  222. package/dist/three/frame/emission-light.js +276 -0
  223. package/dist/three/frame/emission-light.js.map +1 -0
  224. package/dist/three/frame/index.d.ts +19 -0
  225. package/dist/three/frame/index.js +15 -0
  226. package/dist/three/frame/index.js.map +1 -0
  227. package/dist/three/frame/medium.d.ts +33 -0
  228. package/dist/three/frame/medium.js +29 -0
  229. package/dist/three/frame/medium.js.map +1 -0
  230. package/dist/three/frame/renderer.d.ts +97 -0
  231. package/dist/three/frame/renderer.js +480 -0
  232. package/dist/three/frame/renderer.js.map +1 -0
  233. package/dist/three/frame/spectrum.d.ts +4 -0
  234. package/dist/three/frame/spectrum.js +15 -0
  235. package/dist/three/frame/spectrum.js.map +1 -0
  236. package/dist/three/frame/three-internals.d.ts +60 -0
  237. package/dist/three/frame/three-internals.js +152 -0
  238. package/dist/three/frame/three-internals.js.map +1 -0
  239. package/dist/three/frame/volume-shadows.d.ts +139 -0
  240. package/dist/three/frame/volume-shadows.js +403 -0
  241. package/dist/three/frame/volume-shadows.js.map +1 -0
  242. package/dist/three/frame/volume.d.ts +230 -0
  243. package/dist/three/frame/volume.js +268 -0
  244. package/dist/three/frame/volume.js.map +1 -0
  245. package/dist/three/grid-node.d.ts +229 -0
  246. package/dist/three/grid-node.js +545 -0
  247. package/dist/three/grid-node.js.map +1 -0
  248. package/dist/three/index.d.ts +52 -0
  249. package/dist/three/index.js +58 -0
  250. package/dist/three/index.js.map +1 -0
  251. package/dist/three/internal.d.ts +20 -0
  252. package/dist/three/internal.js +18 -0
  253. package/dist/three/internal.js.map +1 -0
  254. package/dist/three/level-set-material.d.ts +185 -0
  255. package/dist/three/level-set-material.js +241 -0
  256. package/dist/three/level-set-material.js.map +1 -0
  257. package/dist/three/level-set-physical-material.d.ts +154 -0
  258. package/dist/three/level-set-physical-material.js +253 -0
  259. package/dist/three/level-set-physical-material.js.map +1 -0
  260. package/dist/three/level-set-velocity.d.ts +94 -0
  261. package/dist/three/level-set-velocity.js +208 -0
  262. package/dist/three/level-set-velocity.js.map +1 -0
  263. package/dist/three/material.d.ts +324 -0
  264. package/dist/three/material.js +502 -0
  265. package/dist/three/material.js.map +1 -0
  266. package/dist/three/points.d.ts +140 -0
  267. package/dist/three/points.js +261 -0
  268. package/dist/three/points.js.map +1 -0
  269. package/dist/three/sparse-source.d.ts +165 -0
  270. package/dist/three/sparse-source.js +405 -0
  271. package/dist/three/sparse-source.js.map +1 -0
  272. package/dist/three/volume-source.d.ts +22 -0
  273. package/dist/three/volume-source.js +110 -0
  274. package/dist/three/volume-source.js.map +1 -0
  275. package/dist/tools/cpu/brick-atlas.d.ts +36 -0
  276. package/dist/tools/cpu/brick-atlas.js +129 -0
  277. package/dist/tools/cpu/brick-atlas.js.map +1 -0
  278. package/dist/tools/cpu/compute.d.ts +116 -0
  279. package/dist/tools/cpu/compute.js +239 -0
  280. package/dist/tools/cpu/compute.js.map +1 -0
  281. package/dist/tools/cpu/lean-reads.d.ts +81 -0
  282. package/dist/tools/cpu/lean-reads.js +262 -0
  283. package/dist/tools/cpu/lean-reads.js.map +1 -0
  284. package/dist/tools/cpu/level-set.d.ts +111 -0
  285. package/dist/tools/cpu/level-set.js +313 -0
  286. package/dist/tools/cpu/level-set.js.map +1 -0
  287. package/dist/tools/cpu/majorant.d.ts +265 -0
  288. package/dist/tools/cpu/majorant.js +541 -0
  289. package/dist/tools/cpu/majorant.js.map +1 -0
  290. package/dist/tools/cpu/march.d.ts +297 -0
  291. package/dist/tools/cpu/march.js +726 -0
  292. package/dist/tools/cpu/march.js.map +1 -0
  293. package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
  294. package/dist/tools/cpu/mesh-decimate.js +1225 -0
  295. package/dist/tools/cpu/mesh-decimate.js.map +1 -0
  296. package/dist/tools/cpu/points.d.ts +29 -0
  297. package/dist/tools/cpu/points.js +38 -0
  298. package/dist/tools/cpu/points.js.map +1 -0
  299. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  300. package/dist/tools/cpu/probe-coords.js +116 -0
  301. package/dist/tools/cpu/probe-coords.js.map +1 -0
  302. package/dist/tools/cpu/read-value.d.ts +44 -0
  303. package/dist/tools/cpu/read-value.js +351 -0
  304. package/dist/tools/cpu/read-value.js.map +1 -0
  305. package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
  306. package/dist/tools/cpu/sample-trilinear.js +168 -0
  307. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  308. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  309. package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
  310. package/dist/tools/cpu/stride-tables.generated.js +1267 -0
  311. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  312. package/dist/tools/cpu/stride-tables.js +78 -0
  313. package/dist/tools/cpu/stride-tables.js.map +1 -0
  314. package/dist/tools/cpu/surface-nets.d.ts +90 -0
  315. package/dist/tools/cpu/surface-nets.js +597 -0
  316. package/dist/tools/cpu/surface-nets.js.map +1 -0
  317. package/dist/tools/errors.d.ts +66 -0
  318. package/dist/tools/errors.js +67 -0
  319. package/dist/tools/errors.js.map +1 -0
  320. package/dist/tools/frame/ambient.d.ts +98 -0
  321. package/dist/tools/frame/ambient.js +274 -0
  322. package/dist/tools/frame/ambient.js.map +1 -0
  323. package/dist/tools/frame/blackbody.d.ts +57 -0
  324. package/dist/tools/frame/blackbody.js +151 -0
  325. package/dist/tools/frame/blackbody.js.map +1 -0
  326. package/dist/tools/frame/brick-cache.d.ts +165 -0
  327. package/dist/tools/frame/brick-cache.js +326 -0
  328. package/dist/tools/frame/brick-cache.js.map +1 -0
  329. package/dist/tools/frame/emission.d.ts +137 -0
  330. package/dist/tools/frame/emission.js +290 -0
  331. package/dist/tools/frame/emission.js.map +1 -0
  332. package/dist/tools/frame/environment-gpu.d.ts +111 -0
  333. package/dist/tools/frame/environment-gpu.js +280 -0
  334. package/dist/tools/frame/environment-gpu.js.map +1 -0
  335. package/dist/tools/frame/environment.d.ts +106 -0
  336. package/dist/tools/frame/environment.js +272 -0
  337. package/dist/tools/frame/environment.js.map +1 -0
  338. package/dist/tools/frame/froxel.d.ts +58 -0
  339. package/dist/tools/frame/froxel.js +115 -0
  340. package/dist/tools/frame/froxel.js.map +1 -0
  341. package/dist/tools/frame/grid.d.ts +392 -0
  342. package/dist/tools/frame/grid.js +802 -0
  343. package/dist/tools/frame/grid.js.map +1 -0
  344. package/dist/tools/frame/index.d.ts +150 -0
  345. package/dist/tools/frame/index.js +389 -0
  346. package/dist/tools/frame/index.js.map +1 -0
  347. package/dist/tools/frame/medium.d.ts +77 -0
  348. package/dist/tools/frame/medium.js +101 -0
  349. package/dist/tools/frame/medium.js.map +1 -0
  350. package/dist/tools/frame/mie-table.d.ts +6 -0
  351. package/dist/tools/frame/mie-table.js +16 -0
  352. package/dist/tools/frame/mie-table.js.map +1 -0
  353. package/dist/tools/frame/mie.d.ts +63 -0
  354. package/dist/tools/frame/mie.js +194 -0
  355. package/dist/tools/frame/mie.js.map +1 -0
  356. package/dist/tools/frame/mlp-nn.d.ts +36 -0
  357. package/dist/tools/frame/mlp-nn.js +159 -0
  358. package/dist/tools/frame/mlp-nn.js.map +1 -0
  359. package/dist/tools/frame/mlp-tza.d.ts +29 -0
  360. package/dist/tools/frame/mlp-tza.js +186 -0
  361. package/dist/tools/frame/mlp-tza.js.map +1 -0
  362. package/dist/tools/frame/mlp.d.ts +183 -0
  363. package/dist/tools/frame/mlp.js +434 -0
  364. package/dist/tools/frame/mlp.js.map +1 -0
  365. package/dist/tools/frame/ms-exit.d.ts +42 -0
  366. package/dist/tools/frame/ms-exit.js +90 -0
  367. package/dist/tools/frame/ms-exit.js.map +1 -0
  368. package/dist/tools/frame/multi-scale.d.ts +152 -0
  369. package/dist/tools/frame/multi-scale.js +302 -0
  370. package/dist/tools/frame/multi-scale.js.map +1 -0
  371. package/dist/tools/frame/neural-weights.d.ts +10 -0
  372. package/dist/tools/frame/neural-weights.js +244 -0
  373. package/dist/tools/frame/neural-weights.js.map +1 -0
  374. package/dist/tools/frame/neural.d.ts +80 -0
  375. package/dist/tools/frame/neural.js +150 -0
  376. package/dist/tools/frame/neural.js.map +1 -0
  377. package/dist/tools/frame/occluders.d.ts +51 -0
  378. package/dist/tools/frame/occluders.js +72 -0
  379. package/dist/tools/frame/occluders.js.map +1 -0
  380. package/dist/tools/frame/pyramid-layout.d.ts +55 -0
  381. package/dist/tools/frame/pyramid-layout.js +100 -0
  382. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  383. package/dist/tools/frame/shadows.d.ts +190 -0
  384. package/dist/tools/frame/shadows.js +468 -0
  385. package/dist/tools/frame/shadows.js.map +1 -0
  386. package/dist/tools/frame/sparse.d.ts +147 -0
  387. package/dist/tools/frame/sparse.js +432 -0
  388. package/dist/tools/frame/sparse.js.map +1 -0
  389. package/dist/tools/frame/spectral-stack.d.ts +159 -0
  390. package/dist/tools/frame/spectral-stack.js +391 -0
  391. package/dist/tools/frame/spectral-stack.js.map +1 -0
  392. package/dist/tools/frame/spectral.d.ts +222 -0
  393. package/dist/tools/frame/spectral.js +572 -0
  394. package/dist/tools/frame/spectral.js.map +1 -0
  395. package/dist/tools/frame/stack.d.ts +115 -0
  396. package/dist/tools/frame/stack.js +290 -0
  397. package/dist/tools/frame/stack.js.map +1 -0
  398. package/dist/tools/frame/view.d.ts +131 -0
  399. package/dist/tools/frame/view.js +337 -0
  400. package/dist/tools/frame/view.js.map +1 -0
  401. package/dist/tools/index.d.ts +157 -0
  402. package/dist/tools/index.js +132 -0
  403. package/dist/tools/index.js.map +1 -0
  404. package/dist/tools/internal.d.ts +87 -0
  405. package/dist/tools/internal.js +85 -0
  406. package/dist/tools/internal.js.map +1 -0
  407. package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
  408. package/dist/tools/nanovdb/build-from-vdb.js +100 -0
  409. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  410. package/dist/tools/nanovdb/bytes.d.ts +233 -0
  411. package/dist/tools/nanovdb/bytes.js +388 -0
  412. package/dist/tools/nanovdb/bytes.js.map +1 -0
  413. package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
  414. package/dist/tools/nanovdb/coarse-first.js +92 -0
  415. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  416. package/dist/tools/nanovdb/half.d.ts +22 -0
  417. package/dist/tools/nanovdb/half.js +73 -0
  418. package/dist/tools/nanovdb/half.js.map +1 -0
  419. package/dist/tools/nanovdb/index.d.ts +34 -0
  420. package/dist/tools/nanovdb/index.js +25 -0
  421. package/dist/tools/nanovdb/index.js.map +1 -0
  422. package/dist/tools/nanovdb/inspect.d.ts +33 -0
  423. package/dist/tools/nanovdb/inspect.js +70 -0
  424. package/dist/tools/nanovdb/inspect.js.map +1 -0
  425. package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
  426. package/dist/tools/nanovdb/leaf-codec.js +356 -0
  427. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  428. package/dist/tools/nanovdb/quantize.d.ts +72 -0
  429. package/dist/tools/nanovdb/quantize.js +329 -0
  430. package/dist/tools/nanovdb/quantize.js.map +1 -0
  431. package/dist/tools/nanovdb/resample.d.ts +177 -0
  432. package/dist/tools/nanovdb/resample.js +692 -0
  433. package/dist/tools/nanovdb/resample.js.map +1 -0
  434. package/dist/tools/nanovdb/serialize.d.ts +176 -0
  435. package/dist/tools/nanovdb/serialize.js +439 -0
  436. package/dist/tools/nanovdb/serialize.js.map +1 -0
  437. package/dist/tools/nanovdb/stats.d.ts +87 -0
  438. package/dist/tools/nanovdb/stats.js +225 -0
  439. package/dist/tools/nanovdb/stats.js.map +1 -0
  440. package/dist/tools/nanovdb/transform.d.ts +30 -0
  441. package/dist/tools/nanovdb/transform.js +94 -0
  442. package/dist/tools/nanovdb/transform.js.map +1 -0
  443. package/dist/tools/nanovdb/tree.d.ts +186 -0
  444. package/dist/tools/nanovdb/tree.js +530 -0
  445. package/dist/tools/nanovdb/tree.js.map +1 -0
  446. package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
  447. package/dist/tools/nanovdb/write-nvdb.js +290 -0
  448. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  449. package/dist/tools/nvdb-file.d.ts +265 -0
  450. package/dist/tools/nvdb-file.js +763 -0
  451. package/dist/tools/nvdb-file.js.map +1 -0
  452. package/dist/tools/nvdb-stream.d.ts +154 -0
  453. package/dist/tools/nvdb-stream.js +409 -0
  454. package/dist/tools/nvdb-stream.js.map +1 -0
  455. package/dist/tools/reference/analytic.d.ts +41 -0
  456. package/dist/tools/reference/analytic.js +95 -0
  457. package/dist/tools/reference/analytic.js.map +1 -0
  458. package/dist/tools/reference/environment.d.ts +62 -0
  459. package/dist/tools/reference/environment.js +154 -0
  460. package/dist/tools/reference/environment.js.map +1 -0
  461. package/dist/tools/reference/index.d.ts +12 -0
  462. package/dist/tools/reference/index.js +13 -0
  463. package/dist/tools/reference/index.js.map +1 -0
  464. package/dist/tools/reference/media.d.ts +14 -0
  465. package/dist/tools/reference/media.js +30 -0
  466. package/dist/tools/reference/media.js.map +1 -0
  467. package/dist/tools/reference/rng.d.ts +20 -0
  468. package/dist/tools/reference/rng.js +30 -0
  469. package/dist/tools/reference/rng.js.map +1 -0
  470. package/dist/tools/reference/scene.d.ts +312 -0
  471. package/dist/tools/reference/scene.js +169 -0
  472. package/dist/tools/reference/scene.js.map +1 -0
  473. package/dist/tools/reference/tables.d.ts +98 -0
  474. package/dist/tools/reference/tables.js +264 -0
  475. package/dist/tools/reference/tables.js.map +1 -0
  476. package/dist/tools/reference/trace.d.ts +160 -0
  477. package/dist/tools/reference/trace.js +497 -0
  478. package/dist/tools/reference/trace.js.map +1 -0
  479. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  480. package/dist/tools/vdb/bit-utils.js +42 -0
  481. package/dist/tools/vdb/bit-utils.js.map +1 -0
  482. package/dist/tools/vdb/blosc-write.d.ts +43 -0
  483. package/dist/tools/vdb/blosc-write.js +197 -0
  484. package/dist/tools/vdb/blosc-write.js.map +1 -0
  485. package/dist/tools/vdb/blosc.d.ts +86 -0
  486. package/dist/tools/vdb/blosc.js +287 -0
  487. package/dist/tools/vdb/blosc.js.map +1 -0
  488. package/dist/tools/vdb/blosclz.d.ts +33 -0
  489. package/dist/tools/vdb/blosclz.js +112 -0
  490. package/dist/tools/vdb/blosclz.js.map +1 -0
  491. package/dist/tools/vdb/byte-reader.d.ts +50 -0
  492. package/dist/tools/vdb/byte-reader.js +161 -0
  493. package/dist/tools/vdb/byte-reader.js.map +1 -0
  494. package/dist/tools/vdb/compression.d.ts +81 -0
  495. package/dist/tools/vdb/compression.js +260 -0
  496. package/dist/tools/vdb/compression.js.map +1 -0
  497. package/dist/tools/vdb/errors.d.ts +10 -0
  498. package/dist/tools/vdb/errors.js +11 -0
  499. package/dist/tools/vdb/errors.js.map +1 -0
  500. package/dist/tools/vdb/grid.d.ts +37 -0
  501. package/dist/tools/vdb/grid.js +153 -0
  502. package/dist/tools/vdb/grid.js.map +1 -0
  503. package/dist/tools/vdb/half-float.d.ts +9 -0
  504. package/dist/tools/vdb/half-float.js +24 -0
  505. package/dist/tools/vdb/half-float.js.map +1 -0
  506. package/dist/tools/vdb/index.d.ts +4 -0
  507. package/dist/tools/vdb/index.js +3 -0
  508. package/dist/tools/vdb/index.js.map +1 -0
  509. package/dist/tools/vdb/inflate.d.ts +24 -0
  510. package/dist/tools/vdb/inflate.js +334 -0
  511. package/dist/tools/vdb/inflate.js.map +1 -0
  512. package/dist/tools/vdb/lz4.d.ts +30 -0
  513. package/dist/tools/vdb/lz4.js +228 -0
  514. package/dist/tools/vdb/lz4.js.map +1 -0
  515. package/dist/tools/vdb/metadata.d.ts +17 -0
  516. package/dist/tools/vdb/metadata.js +72 -0
  517. package/dist/tools/vdb/metadata.js.map +1 -0
  518. package/dist/tools/vdb/parse.d.ts +47 -0
  519. package/dist/tools/vdb/parse.js +241 -0
  520. package/dist/tools/vdb/parse.js.map +1 -0
  521. package/dist/tools/vdb/point-render-data.d.ts +79 -0
  522. package/dist/tools/vdb/point-render-data.js +137 -0
  523. package/dist/tools/vdb/point-render-data.js.map +1 -0
  524. package/dist/tools/vdb/points.d.ts +186 -0
  525. package/dist/tools/vdb/points.js +835 -0
  526. package/dist/tools/vdb/points.js.map +1 -0
  527. package/dist/tools/vdb/transform.d.ts +23 -0
  528. package/dist/tools/vdb/transform.js +54 -0
  529. package/dist/tools/vdb/transform.js.map +1 -0
  530. package/dist/tools/vdb/tree.d.ts +111 -0
  531. package/dist/tools/vdb/tree.js +228 -0
  532. package/dist/tools/vdb/tree.js.map +1 -0
  533. package/dist/tools/vdb/types.d.ts +195 -0
  534. package/dist/tools/vdb/types.js +3 -0
  535. package/dist/tools/vdb/types.js.map +1 -0
  536. package/dist/tools/wvdb/bake.d.ts +145 -0
  537. package/dist/tools/wvdb/bake.js +361 -0
  538. package/dist/tools/wvdb/bake.js.map +1 -0
  539. package/dist/tools/wvdb/dense.d.ts +191 -0
  540. package/dist/tools/wvdb/dense.js +368 -0
  541. package/dist/tools/wvdb/dense.js.map +1 -0
  542. package/dist/tools/wvdb/format.d.ts +220 -0
  543. package/dist/tools/wvdb/format.js +306 -0
  544. package/dist/tools/wvdb/format.js.map +1 -0
  545. package/dist/tools/wvdb/index.d.ts +14 -0
  546. package/dist/tools/wvdb/index.js +15 -0
  547. package/dist/tools/wvdb/index.js.map +1 -0
  548. package/dist/tools/wvdb/level-set.d.ts +56 -0
  549. package/dist/tools/wvdb/level-set.js +153 -0
  550. package/dist/tools/wvdb/level-set.js.map +1 -0
  551. package/dist/tools/wvdb/nanovdb.d.ts +59 -0
  552. package/dist/tools/wvdb/nanovdb.js +64 -0
  553. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  554. package/dist/tools/wvdb/partial.d.ts +74 -0
  555. package/dist/tools/wvdb/partial.js +233 -0
  556. package/dist/tools/wvdb/partial.js.map +1 -0
  557. package/dist/tools/wvdb/read.d.ts +336 -0
  558. package/dist/tools/wvdb/read.js +766 -0
  559. package/dist/tools/wvdb/read.js.map +1 -0
  560. package/dist/tools/wvdb/sha256.d.ts +7 -0
  561. package/dist/tools/wvdb/sha256.js +76 -0
  562. package/dist/tools/wvdb/sha256.js.map +1 -0
  563. package/dist/tools/wvdb/write.d.ts +149 -0
  564. package/dist/tools/wvdb/write.js +403 -0
  565. package/dist/tools/wvdb/write.js.map +1 -0
  566. package/package.json +83 -4
  567. package/vendor/LICENSE +201 -0
  568. package/vendor/NOTICE +19 -0
  569. package/vendor/VENDOR.md +100 -0
  570. package/vendor/pnanovdb.wgsl +1577 -0
@@ -0,0 +1,546 @@
1
+ /**
2
+ * The public `vdb*` WGSL API layered over the vendored traversal
3
+ * (docs/dev/design/K1-core.md §3.2). Written in the generated module's final names:
4
+ * vendored declarations appear renamed (`vdb_*`, `VDB_*`), and the generator
5
+ * pulls in exactly the vendored declarations this text references.
6
+ *
7
+ * Every pool read goes through `vdb_load`, the module's one buffer access,
8
+ * which the generator emits for the chosen binding mode.
9
+ *
10
+ * Layers stack: `sample` includes `read`, `march` includes `sample`, and
11
+ * `majorant` (P1.3) includes `sample` and, with `majorant: 'nodeMax'`, `march`
12
+ * (`./majorant.ts`). `reader: 'lean'` (P1.5) swaps the vendored accessor for
13
+ * `./lean.ts`. Each layer is a function of the normalized options and the
14
+ * profile rank.
15
+ *
16
+ * Conventions every layer keeps:
17
+ * - A grid id is usable when it is below `vdbGridCount()` and its record is
18
+ * live. Every per-grid function checks that first: a dead or out-of-range
19
+ * id never reads a zeroed record or image bytes as a record.
20
+ * - Voxel centres sit at integer index coordinates (the vendored trilinear and
21
+ * NanoVDB `SampleFromVoxels`); HDDA cells are floor-based, so voxel `i`
22
+ * occupies `[i, i + 1)` for ray clipping and traversal.
23
+ */
24
+ import { leanHelperFunctions, leanReadLayer, leanSampleFunctions } from "./lean.js";
25
+ import { levelSetWgsl } from "./level-set.js";
26
+ import { majorantHelpersWgsl, majorantWgsl } from "./majorant.js";
27
+ /** Whether the module has the march layer: `march`, or `majorant` with `'nodeMax'`. */
28
+ export function hasMarch(profileRank, o) {
29
+ return profileRank === 2 || (profileRank === 3 && o.majorant === "nodeMax");
30
+ }
31
+ /** Vendored grid-type constant names (after the rename) per compiled type. */
32
+ export const GRID_TYPE_CONSTANT = {
33
+ float: "VDB_GRID_TYPE_FLOAT",
34
+ fp4: "VDB_GRID_TYPE_FP4",
35
+ fp8: "VDB_GRID_TYPE_FP8",
36
+ fp16: "VDB_GRID_TYPE_FP16",
37
+ fpn: "VDB_GRID_TYPE_FPN",
38
+ half: "VDB_GRID_TYPE_HALF",
39
+ };
40
+ /** Whether the accessor carries the index bbox (only `sample`+ with `outside: 'zero'`). */
41
+ function carriesBBox(profileRank, o) {
42
+ return profileRank >= 1 && o.outside === "zero";
43
+ }
44
+ /** Whether the accessor carries the stats flag and `valueMax` (the march layer). */
45
+ function carriesStats(profileRank, o) {
46
+ return hasMarch(profileRank, o);
47
+ }
48
+ /** The record functions every reader shares, in emission order. */
49
+ function recordFunctions(o) {
50
+ const typeOk = o.types.map((t) => `t == ${GRID_TYPE_CONSTANT[t]}`).join(" || ");
51
+ return [
52
+ `fn vdb_rec(g: u32, w: u32) -> u32 {
53
+ return vdb_load(VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w);
54
+ }`,
55
+ `fn vdb_type_ok(t: u32) -> bool {
56
+ return ${typeOk};
57
+ }`,
58
+ `fn vdbGridCount() -> u32 {
59
+ return vdb_load(VDB_HEADER_GRID_COUNT);
60
+ }`,
61
+ `fn vdb_live(g: u32) -> bool {
62
+ return g < vdbGridCount() && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_LIVE) != 0u;
63
+ }`,
64
+ `fn vdbGridType(g: u32) -> u32 {
65
+ if !vdb_live(g) {
66
+ return 0u;
67
+ }
68
+ return vdb_rec(g, VDB_REC_GRID_TYPE);
69
+ }`,
70
+ `fn vdbIndexMin(g: u32) -> vec3i {
71
+ if !vdb_live(g) {
72
+ return vec3i(0);
73
+ }
74
+ return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MIN), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 2u)));
75
+ }`,
76
+ `fn vdbIndexMax(g: u32) -> vec3i {
77
+ if !vdb_live(g) {
78
+ return vec3i(-1);
79
+ }
80
+ return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MAX), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 2u)));
81
+ }`,
82
+ ];
83
+ }
84
+ function readLayer(o, profileRank) {
85
+ const bbox = carriesBBox(profileRank, o);
86
+ if (o.reader === "lean")
87
+ return leanReadLayer(o, bbox, recordFunctions(o));
88
+ const stats = carriesStats(profileRank, o);
89
+ const extraFields = (bbox ? "\n lo: vec3i,\n hi: vec3i," : "") + (stats ? "\n stats: bool,\n vmax: f32," : "");
90
+ const extraInit = (bbox ? "\n a.lo = vdbIndexMin(g);\n a.hi = vdbIndexMax(g);" : "") +
91
+ (stats
92
+ ? "\n a.stats = (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;\n a.vmax = bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));"
93
+ : "");
94
+ const parts = [
95
+ `struct VdbAccessor {
96
+ buf: vdb_buf_t,
97
+ gridType: u32,
98
+ ok: bool,
99
+ inner: vdb_readaccessor_t,${extraFields}
100
+ }`,
101
+ ...recordFunctions(o),
102
+ `fn vdbAccessorInit(g: u32) -> VdbAccessor {
103
+ var a: VdbAccessor;
104
+ a.gridType = vdbGridType(g);
105
+ a.ok = vdb_type_ok(a.gridType);
106
+ var root = vdb_root_handle_t(0u);
107
+ if a.ok {
108
+ a.buf = vdb_make_buffer(vdb_rec(g, VDB_REC_IMAGE_OFFSET), vdb_rec(g, VDB_REC_IMAGE_BYTES) >> 2u);
109
+ root = vdb_tree_get_root(a.buf, vdb_grid_get_tree(vdb_grid_handle_t(0u)));${extraInit}
110
+ }
111
+ var inner: vdb_readaccessor_t;
112
+ vdb_readaccessor_init(&inner, root);
113
+ a.inner = inner;
114
+ return a;
115
+ }`,
116
+ `fn vdbReadValue(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {
117
+ if !(*acc).ok {
118
+ return 0.0;
119
+ }
120
+ var inner = (*acc).inner;
121
+ let v = vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ijk);
122
+ (*acc).inner = inner;
123
+ return v;
124
+ }`,
125
+ ];
126
+ if (o.isActive) {
127
+ parts.push(`fn vdbIsActive(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> bool {
128
+ if !(*acc).ok {
129
+ return false;
130
+ }
131
+ var inner = (*acc).inner;
132
+ let v = vdb_readaccessor_is_active((*acc).gridType, (*acc).buf, &inner, ijk);
133
+ (*acc).inner = inner;
134
+ return v;
135
+ }`);
136
+ }
137
+ return parts.join("\n");
138
+ }
139
+ /**
140
+ * `vdbSample` per sampler and `outside` mode.
141
+ *
142
+ * `outside: 'background'` reads the tree everywhere (NanoVDB: outside the
143
+ * tree the background value).
144
+ *
145
+ * `outside: 'zero'` samples the field that equals the tree inside the index
146
+ * bbox `[min, max]` (voxels, inclusive) and 0 outside it, so both samplers
147
+ * see the same box with voxel centres at integers:
148
+ * - trilinear: each of the 8 taps outside `[min, max]` reads 0. A point is
149
+ * 0 unless its base voxel `floor(xyz)` lies in `[min - 1, max]` (some tap
150
+ * inside), i.e. `xyz` in `[min - 1, max + 1)`.
151
+ * - nearest: the voxel `floor(xyz + 0.5)` must lie in `[min, max]`, i.e.
152
+ * `xyz` in `[min - 0.5, max + 0.5)`; else 0.
153
+ * CPU twins: `tools` `vdbSampleTrilinearCpu` / `vdbSampleNearestCpu` with `{ outside: 'zero' }`.
154
+ */
155
+ function sampleFunction(o, profileRank) {
156
+ if (o.reader === "lean")
157
+ return leanSampleFunctions(o, carriesBBox(profileRank, o));
158
+ const read = (ijk) => `vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ${ijk})`;
159
+ if (!carriesBBox(profileRank, o)) {
160
+ const lookup = o.sampler === "trilinear" ? "vdb_sample_trilinear_typed((*acc).gridType, (*acc).buf, &inner, xyz)" : read("vec3i(floor(xyz + vec3f(0.5)))");
161
+ return [
162
+ `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
163
+ if !(*acc).ok {
164
+ return 0.0;
165
+ }
166
+ var inner = (*acc).inner;
167
+ let v = ${lookup};
168
+ (*acc).inner = inner;
169
+ return v;
170
+ }`,
171
+ ];
172
+ }
173
+ if (o.sampler === "nearest") {
174
+ return [
175
+ `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
176
+ let ijk = vec3i(floor(xyz + vec3f(0.5)));
177
+ if !(*acc).ok || any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {
178
+ return 0.0;
179
+ }
180
+ var inner = (*acc).inner;
181
+ let v = ${read("ijk")};
182
+ (*acc).inner = inner;
183
+ return v;
184
+ }`,
185
+ ];
186
+ }
187
+ // Same tap order and lerp structure as the vendored sample_trilinear_typed.
188
+ return [
189
+ `fn vdb_tap0(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {
190
+ if any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {
191
+ return 0.0;
192
+ }
193
+ var inner = (*acc).inner;
194
+ let v = ${read("ijk")};
195
+ (*acc).inner = inner;
196
+ return v;
197
+ }`,
198
+ `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
199
+ let b = vec3i(floor(xyz));
200
+ if !(*acc).ok || any(b < (*acc).lo - vec3i(1)) || any(b > (*acc).hi) {
201
+ return 0.0;
202
+ }
203
+ let u = xyz - vec3f(b);
204
+ let x00 = mix(vdb_tap0(acc, b), vdb_tap0(acc, b + vec3i(1, 0, 0)), u.x);
205
+ let x10 = mix(vdb_tap0(acc, b + vec3i(0, 1, 0)), vdb_tap0(acc, b + vec3i(1, 1, 0)), u.x);
206
+ let x01 = mix(vdb_tap0(acc, b + vec3i(0, 0, 1)), vdb_tap0(acc, b + vec3i(1, 0, 1)), u.x);
207
+ let x11 = mix(vdb_tap0(acc, b + vec3i(0, 1, 1)), vdb_tap0(acc, b + vec3i(1, 1, 1)), u.x);
208
+ return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);
209
+ }`,
210
+ ];
211
+ }
212
+ function sampleLayer(o, profileRank) {
213
+ return [
214
+ `fn vdb_row(b: u32) -> vec4f {
215
+ return bitcast<vec4f>(vec4u(vdb_load(b), vdb_load(b + 1u), vdb_load(b + 2u), vdb_load(b + 3u)));
216
+ }`,
217
+ `fn vdb_affine(g: u32, w: u32, p: vec4f) -> vec3f {
218
+ if !vdb_live(g) {
219
+ return vec3f(0.0);
220
+ }
221
+ let b = VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w;
222
+ return vec3f(dot(vdb_row(b), p), dot(vdb_row(b + 4u), p), dot(vdb_row(b + 8u), p));
223
+ }`,
224
+ `fn vdbWorldToIndex(g: u32, p: vec3f) -> vec3f {
225
+ return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(p, 1.0));
226
+ }`,
227
+ `fn vdbWorldToIndexDir(g: u32, d: vec3f) -> vec3f {
228
+ return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(d, 0.0));
229
+ }`,
230
+ `fn vdbIndexToWorld(g: u32, p: vec3f) -> vec3f {
231
+ return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(p, 1.0));
232
+ }`,
233
+ `fn vdbIndexToWorldDir(g: u32, d: vec3f) -> vec3f {
234
+ return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(d, 0.0));
235
+ }`,
236
+ ...sampleFunction(o, profileRank),
237
+ `fn vdbRayClip(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {
238
+ if !vdb_live(g) {
239
+ return false;
240
+ }
241
+ var t0 = (*t).x;
242
+ var t1 = (*t).y;
243
+ let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)), vec3f(vdbIndexMax(g) + vec3i(1)), o, &t0, d, &t1);
244
+ *t = vec2f(t0, t1);
245
+ return hit && t0 <= t1;
246
+ }`,
247
+ ].join("\n");
248
+ }
249
+ /**
250
+ * `march` (design note §3.2): the vendored HDDA, the accessor's node size at a
251
+ * voxel, and node stats.
252
+ *
253
+ * `vdbGetDim(acc, ijk)` is the vendored `readaccessor_get_dim`: 1 inside a
254
+ * leaf, 8 in a lower-node tile, 128 in an upper-node tile, 4096 in a root tile
255
+ * or the background (and 4096 for a grid the accessor can't read, so a walk
256
+ * ends after one cell instead of stalling at dim 0).
257
+ *
258
+ * `vdbNodeMax(acc, ijk, dim)` bounds the aligned cell of size `dim` holding
259
+ * `ijk`. With `a = vdbGetDim(acc, ijk)`:
260
+ * - `a > 1` and `dim <= a`: the cell lies in one tile; returns its value
261
+ * (exact, active or not).
262
+ * - otherwise the max statistic of the smallest node spanning the cell: the
263
+ * leaf for `dim <= 8`, lower for `<= 128`, upper for `<= 4096`, else root.
264
+ * NanoVDB stats cover ACTIVE values only: the result bounds the active
265
+ * voxels and active tiles of that node, not inactive values, and not a
266
+ * trilinear sample, whose taps reach one voxel into the neighbours.
267
+ * - without stats (record flag b1 clear) the stats branches return the
268
+ * record's `valueMax`: the caller's bound from `pool.add`, else +Infinity
269
+ * (the pool convention for "no bound"). Test `vdbHasStats(g)` rather than
270
+ * relying on infinity arithmetic.
271
+ * The node handles come from the accessor cache that `vdbGetDim` just filled
272
+ * along `ijk`'s path (leaf, lower and upper are all valid whenever the level
273
+ * below them is, see the vendored `readaccessor_iscached*`).
274
+ */
275
+ function marchLayer() {
276
+ return [
277
+ `alias VdbHdda = vdb_hdda_t;`,
278
+ `fn vdbHddaInit(h: ptr<function, VdbHdda>, o: vec3f, tmin: f32, d: vec3f, tmax: f32, dim: u32) {
279
+ vdb_hdda_init(h, o, tmin, d, tmax, i32(dim));
280
+ }`,
281
+ `fn vdbHddaUpdate(h: ptr<function, VdbHdda>, o: vec3f, d: vec3f, dim: u32) -> bool {
282
+ return vdb_hdda_update(h, o, d, i32(dim));
283
+ }`,
284
+ `fn vdbHddaStep(h: ptr<function, VdbHdda>) -> bool {
285
+ return vdb_hdda_step(h);
286
+ }`,
287
+ `fn vdbGetDim(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> u32 {
288
+ if !(*acc).ok {
289
+ return 4096u;
290
+ }
291
+ var inner = (*acc).inner;
292
+ let v = vdb_readaccessor_get_dim((*acc).gridType, (*acc).buf, &inner, ijk);
293
+ (*acc).inner = inner;
294
+ return v;
295
+ }`,
296
+ `fn vdbHasStats(g: u32) -> bool {
297
+ return vdb_live(g) && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;
298
+ }`,
299
+ `fn vdbValueMax(g: u32) -> f32 {
300
+ if !vdb_live(g) {
301
+ return 0.0;
302
+ }
303
+ return bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));
304
+ }`,
305
+ `fn vdbNodeMax(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {
306
+ if !(*acc).ok {
307
+ return 0.0;
308
+ }
309
+ let a = vdbGetDim(acc, ijk);
310
+ if a > 1u && dim <= a {
311
+ return vdbReadValue(acc, ijk);
312
+ }
313
+ if !(*acc).stats {
314
+ return (*acc).vmax;
315
+ }
316
+ let t = (*acc).gridType;
317
+ let b = (*acc).buf;
318
+ if dim <= 8u {
319
+ return vdb_leaf_get_max_float(t, b, (*acc).inner.leaf);
320
+ }
321
+ if dim <= 128u {
322
+ return vdb_lower_get_max_float(t, b, (*acc).inner.lower);
323
+ }
324
+ if dim <= 4096u {
325
+ return vdb_upper_get_max_float(t, b, (*acc).inner.upper);
326
+ }
327
+ return vdb_root_get_max_float(t, b, (*acc).inner.root);
328
+ }`,
329
+ ].join("\n");
330
+ }
331
+ /**
332
+ * Opt-in helpers (K1.7a, the `helpers` option). Each is emitted only when
333
+ * asked for, so modules without helpers keep their bytes (the size snapshot).
334
+ *
335
+ * `vdbCellBoundTrilinear(acc, ijk, dim)`: the max of `vdbNodeMax` over the
336
+ * 2x2x2 block of aligned `dim`-cells whose min corner is the cell holding
337
+ * `ijk` (that cell and its +x/+y/+z neighbours). A trilinear sample at `p`
338
+ * reads voxels `floor(p) + {0,1}^3`, so when `floor(p)` lies in the cell every
339
+ * tap lies in the block and the result bounds the sample, with `vdbNodeMax`'s
340
+ * caveat: stats bound ACTIVE values, so inactive leaf voxels must be <= their
341
+ * leaf's max (true of fog volumes). With `outside: 'zero'` and a negative
342
+ * field, also take max(result, 0). This is the skip test a march needs; the
343
+ * cell's own `vdbNodeMax` is not one (CLAUDE.md Traps). CPU twin: `tools`
344
+ * `cellBoundTrilinear`.
345
+ *
346
+ * `vdbHddaCellEnd(h)`: the ray `t` where the HDDA's current cell ends,
347
+ * `min(next.x, next.y, next.z, tmax)` of the vendored state, so a host
348
+ * needn't name `VdbHdda`'s vendored fields. CPU twin: `tools` `hddaCellEnd`.
349
+ *
350
+ * `vdbNodeAverage(acc, ijk, dim)` (K3.2): the box mean of the aligned
351
+ * `dim`-cell holding `ijk`, from node statistics instead of voxels (the
352
+ * sparse volume source's `'node-average'` LOD). A cell inside one tile (or the
353
+ * background) is that tile's value, exactly. Otherwise, for `dim <= 8`, the
354
+ * leaf's average times its active fraction (`countOneBits` of the value mask
355
+ * / 512): the exact mean when the leaf's inactive voxels are 0 (fog); for
356
+ * `dim <= 128`, the lower node's average, which is the mean of its ACTIVE
357
+ * voxels (NanoVDB stores no active count per lower node), so it overstates a
358
+ * partly empty lower node; larger cells read the lower node too (`dim` is
359
+ * meant to be 8 or 128; no upper level, to keep the module small). Without stats it is the value at `ijk` (no
360
+ * prefilter). CPU twin: `tools` `nodeAverage`.
361
+ *
362
+ * `vdbRayClipSupport(g, o, d, t)`: `vdbRayClip` against the box where
363
+ * `vdbSample` can read the grid's voxels: `[min - 1, max + 1]` for trilinear
364
+ * (the taps of a point in `[min - 1, min)` reach voxel `min`) and
365
+ * `[min - 0.5, max + 0.5]` for nearest. `vdbRayClip`'s box, `[min, max + 1]`,
366
+ * is the voxel-cell box the HDDA walks; it cuts the min-side half voxel of the
367
+ * trilinear support. CPU twin: `tools` `rayClipSupport`.
368
+ */
369
+ function helperFunctions(o) {
370
+ const out = [];
371
+ if (o.helpers.includes("rayClipSupport")) {
372
+ const pad = o.sampler === "nearest" ? "0.5" : "1.0";
373
+ out.push(`fn vdbRayClipSupport(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {
374
+ if !vdb_live(g) {
375
+ return false;
376
+ }
377
+ var t0 = (*t).x;
378
+ var t1 = (*t).y;
379
+ let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)) - vec3f(${pad}), vec3f(vdbIndexMax(g)) + vec3f(${pad}), o, &t0, d, &t1);
380
+ *t = vec2f(t0, t1);
381
+ return hit && t0 <= t1;
382
+ }`);
383
+ }
384
+ if (o.helpers.includes("cellBoundTrilinear")) {
385
+ out.push(`fn vdbCellBoundTrilinear(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {
386
+ var m = vdbNodeMax(acc, ijk, dim);
387
+ for (var k = 1u; k < 8u; k++) {
388
+ let c = vec3i(vec3u(k & 1u, (k >> 1u) & 1u, (k >> 2u) & 1u)) * i32(dim);
389
+ m = max(m, vdbNodeMax(acc, ijk + c, dim));
390
+ }
391
+ return m;
392
+ }`);
393
+ }
394
+ if (o.helpers.includes("hddaCellEnd")) {
395
+ out.push(`fn vdbHddaCellEnd(h: ptr<function, VdbHdda>) -> f32 {
396
+ return min(min((*h).next.x, (*h).next.y), min((*h).next.z, (*h).tmax));
397
+ }`);
398
+ }
399
+ // P1.16: the lean reader's own helpers (its vdbSampleFast, the unchecked init).
400
+ if (o.reader === "lean")
401
+ out.push(...leanHelperFunctions(o, carriesBBox(1, o)));
402
+ if (o.reader !== "lean" && o.helpers.includes("fastTrilinear")) {
403
+ // Only trilinear has 8 taps to share (the generator rejects the helper with 'nearest').
404
+ const inside = carriesBBox(1, o) ? " || any(b < (*acc).lo) || any(b >= (*acc).hi)" : "";
405
+ // Uniform per-tap work (no per-lane choice between a leaf read and a descent: lanes of a SIMD group that
406
+ // disagree would run both). All 8 taps lie in the base voxel's lower node (128-block) unless the base is
407
+ // on its +x/+y/+z face; each tap is then one lower-node child lookup (the same words for taps in the same
408
+ // leaf), never a tree walk. The vendored taps instead thrash the accessor's one-leaf cache when the cell
409
+ // straddles leaves (x-fastest tap order alternates them).
410
+ // A tap: one lower-node child lookup (the caching variant the accessor already uses, on a scratch cache).
411
+ // vdbSampleFast: the lower node holding the base is the accessor's cached one, else a descent (which caches
412
+ // it); at level 2+ the base's 128-block, which holds all 8 taps, is one tile (or the background): one value.
413
+ // c0 holds taps 0-3 (z = 0), c1 taps 4-7 (z = 1), x fastest: the vendored c000, c100, c010, c110, c001, ...
414
+ // No comments inside the WGSL: generated modules carry only the banner.
415
+ out.push(`fn vdb_lower_tap(t: u32, buf: vdb_buf_t, node: vdb_lower_handle_t, b: vec3i, k: u32) -> f32 {
416
+ let ijk = b + vec3i(vec3u(k & 1u, (k >> 1u) & 1u, k >> 2u));
417
+ var s: vdb_readaccessor_t;
418
+ let al = vdb_lower_get_value_address_and_level_and_cache(t, buf, node, ijk, &s);
419
+ return vdb_read_float_typed(t, buf, al.address, ijk, al.level);
420
+ }`);
421
+ const taps = (from) => [0, 1, 2, 3].map((k) => `vdb_lower_tap(t, buf, n, b, ${from + k}u)`).join(", ");
422
+ out.push(`fn vdbSampleFast(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {
423
+ let b = vec3i(floor(xyz));
424
+ if !(*acc).ok || any((b & vec3i(127)) == vec3i(127))${inside} {
425
+ return vdbSample(acc, xyz);
426
+ }
427
+ let t = (*acc).gridType;
428
+ let buf = (*acc).buf;
429
+ var inner = (*acc).inner;
430
+ var lower = vdb_readaccessor_iscached1(&inner, vdb_readaccessor_computedirty(&inner, b));
431
+ var v = 0.0;
432
+ if !lower {
433
+ let al = vdb_readaccessor_get_value_address_and_level(t, buf, &inner, b);
434
+ lower = al.level <= 1u;
435
+ v = vdb_read_float_typed(t, buf, al.address, b, al.level);
436
+ }
437
+ (*acc).inner = inner;
438
+ var c0 = vec4f(v);
439
+ var c1 = vec4f(v);
440
+ if lower {
441
+ let n = inner.lower;
442
+ c0 = vec4f(${taps(0)});
443
+ c1 = vec4f(${taps(4)});
444
+ }
445
+ let u = xyz - vec3f(b);
446
+ return mix(mix(mix(c0.x, c0.y, u.x), mix(c0.z, c0.w, u.x), u.y), mix(mix(c1.x, c1.y, u.x), mix(c1.z, c1.w, u.x), u.y), u.z);
447
+ }`);
448
+ }
449
+ if (o.helpers.includes("nodeAverage")) {
450
+ out.push(`fn vdbNodeAverage(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {
451
+ if !(*acc).ok {
452
+ return 0.0;
453
+ }
454
+ let a = vdbGetDim(acc, ijk);
455
+ if (a > 1u && dim <= a) || !(*acc).stats || dim <= 1u {
456
+ return vdbReadValue(acc, ijk);
457
+ }
458
+ let t = (*acc).gridType;
459
+ let b = (*acc).buf;
460
+ if dim <= 8u {
461
+ let leaf = (*acc).inner.leaf;
462
+ var n = 0u;
463
+ for (var w = 0u; w < 16u; w++) {
464
+ n += countOneBits(vdb_read_uint32(b, vdb_address_offset(leaf.address, VDB_LEAF_OFF_VALUE_MASK + 4u * w)));
465
+ }
466
+ return vdb_leaf_get_ave_float(t, b, leaf) * (f32(n) / 512.0);
467
+ }
468
+ return vdb_lower_get_ave_float(t, b, (*acc).inner.lower);
469
+ }`);
470
+ }
471
+ // K3.7: the level-set zero-crossing finder and normal (./level-set.ts).
472
+ if (o.helpers.includes("levelSet"))
473
+ out.push(...levelSetWgsl());
474
+ // EX1f-b: the majorant profile's helpers (world and global inits, the two trackers; ./majorant.ts).
475
+ out.push(...majorantHelpersWgsl(o));
476
+ return out;
477
+ }
478
+ /**
479
+ * API layers in profile order. A profile's API is every layer up to and
480
+ * including its own, except that `majorant` (rank 3) takes the march layer
481
+ * only with `majorant: 'nodeMax'` (P1.3: `brick` / `global` are `sample` plus
482
+ * the walk, K1-core §3.2).
483
+ */
484
+ export const API_LAYERS = [
485
+ readLayer,
486
+ sampleLayer,
487
+ marchLayer,
488
+ (o) => majorantWgsl(o),
489
+ ];
490
+ /** The public API text for the profile at `profileRank` (0 = read, 1 = sample, 2 = march, 3 = majorant), then the requested helpers. */
491
+ export function apiWgsl(profileRank, o) {
492
+ const layers = API_LAYERS.slice(0, profileRank + 1).filter((_, i) => i !== 2 || hasMarch(profileRank, o));
493
+ return [...layers.map((layer) => layer(o, profileRank)), ...helperFunctions(o)].join("\n");
494
+ }
495
+ /** The API text as its top-level declarations, in order (every one starts a line with `fn`, `struct` or `alias`). */
496
+ function apiDeclarations(api) {
497
+ const out = [];
498
+ let lines = [];
499
+ const flush = () => {
500
+ if (lines.length === 0)
501
+ return;
502
+ const m = /^(fn|struct|alias)\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(lines[0]);
503
+ if (!m)
504
+ throw new Error(`@pmndrs/vdb: unexpected API text before a declaration: ${lines[0]}`);
505
+ out.push({ kind: m[1], name: m[2], text: lines.join("\n") });
506
+ lines = [];
507
+ };
508
+ for (const line of api.split("\n")) {
509
+ if (/^(fn|struct|alias)\s/.test(line))
510
+ flush();
511
+ lines.push(line);
512
+ }
513
+ flush();
514
+ return out;
515
+ }
516
+ /** The public functions of an API text: what `keep` can name. */
517
+ export function apiPublicFunctions(api) {
518
+ return apiDeclarations(api)
519
+ .filter((d) => d.kind === "fn" && /^vdb[A-Z]/.test(d.name))
520
+ .map((d) => d.name);
521
+ }
522
+ /**
523
+ * P1.16 `keep`: the API text cut to the named public functions and the declarations they reach (by identifier),
524
+ * in the original order. The generator's vendored closure then follows from the cut text.
525
+ */
526
+ export function pruneApiWgsl(api, keep) {
527
+ const decls = apiDeclarations(api);
528
+ const byName = new Map(decls.map((d) => [d.name, d]));
529
+ const kept = new Set();
530
+ const stack = [...keep];
531
+ while (stack.length > 0) {
532
+ const name = stack.pop();
533
+ if (kept.has(name))
534
+ continue;
535
+ kept.add(name);
536
+ for (const m of byName.get(name).text.matchAll(/[A-Za-z_][A-Za-z0-9_]*/g)) {
537
+ if (byName.has(m[0]) && !kept.has(m[0]))
538
+ stack.push(m[0]);
539
+ }
540
+ }
541
+ return decls
542
+ .filter((d) => kept.has(d.name))
543
+ .map((d) => d.text)
544
+ .join("\n");
545
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O,KAAK;SACT,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SAClB,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["/**\n * The public `vdb*` WGSL API layered over the vendored traversal\n * (docs/dev/design/K1-core.md §3.2). Written in the generated module's final names:\n * vendored declarations appear renamed (`vdb_*`, `VDB_*`), and the generator\n * pulls in exactly the vendored declarations this text references.\n *\n * Every pool read goes through `vdb_load`, the module's one buffer access,\n * which the generator emits for the chosen binding mode.\n *\n * Layers stack: `sample` includes `read`, `march` includes `sample`, and\n * `majorant` (P1.3) includes `sample` and, with `majorant: 'nodeMax'`, `march`\n * (`./majorant.ts`). `reader: 'lean'` (P1.5) swaps the vendored accessor for\n * `./lean.ts`. Each layer is a function of the normalized options and the\n * profile rank.\n *\n * Conventions every layer keeps:\n * - A grid id is usable when it is below `vdbGridCount()` and its record is\n * live. Every per-grid function checks that first: a dead or out-of-range\n * id never reads a zeroed record or image bytes as a record.\n * - Voxel centres sit at integer index coordinates (the vendored trilinear and\n * NanoVDB `SampleFromVoxels`); HDDA cells are floor-based, so voxel `i`\n * occupies `[i, i + 1)` for ray clipping and traversal.\n */\n\nimport type { VDBGridTypeName } from \"../types.js\";\nimport { leanHelperFunctions, leanReadLayer, leanSampleFunctions } from \"./lean.js\";\nimport { levelSetWgsl } from \"./level-set.js\";\nimport { majorantHelpersWgsl, majorantWgsl, type VDBMajorantMode } from \"./majorant.js\";\nimport type { VDBModuleHelper } from \"./types.js\";\n\n/** Options the API layer depends on (normalized by the generator). */\nexport interface ApiOptions {\n readonly types: readonly VDBGridTypeName[];\n readonly isActive: boolean;\n readonly sampler: \"trilinear\" | \"nearest\";\n readonly outside: \"background\" | \"zero\";\n /** Opt-in helpers, canonical order; the generator has checked each one's profile. */\n readonly helpers: readonly VDBModuleHelper[];\n /** P1.5: the vendored accessor or the lean reader (`./lean.ts`). */\n readonly reader: \"vendored\" | \"lean\";\n /** P1.3/P1.4, `majorant` profile only (else `'brick'`): which walk. `'nodeMax'` includes the march layer. */\n readonly majorant: VDBMajorantMode;\n /** `majorant` profile only (else false): emit `vdbMajorantMinimum`. */\n readonly minima: boolean;\n /** EX1f-b: the host's random function the tracking helpers call (a WGSL identifier), else null. */\n readonly random: string | null;\n /** P1.16: what the lean accessor caches (`'leaf'` for the vendored reader, which has its own cache). */\n readonly cache: \"leaf\" | \"lower\" | \"lowerLeaf\";\n}\n\n/** Whether the module has the march layer: `march`, or `majorant` with `'nodeMax'`. */\nexport function hasMarch(profileRank: number, o: Pick<ApiOptions, \"majorant\">): boolean {\n return profileRank === 2 || (profileRank === 3 && o.majorant === \"nodeMax\");\n}\n\n/** Vendored grid-type constant names (after the rename) per compiled type. */\nexport const GRID_TYPE_CONSTANT: Readonly<Record<VDBGridTypeName, string>> = {\n float: \"VDB_GRID_TYPE_FLOAT\",\n fp4: \"VDB_GRID_TYPE_FP4\",\n fp8: \"VDB_GRID_TYPE_FP8\",\n fp16: \"VDB_GRID_TYPE_FP16\",\n fpn: \"VDB_GRID_TYPE_FPN\",\n half: \"VDB_GRID_TYPE_HALF\",\n};\n\n/** Whether the accessor carries the index bbox (only `sample`+ with `outside: 'zero'`). */\nfunction carriesBBox(profileRank: number, o: ApiOptions): boolean {\n return profileRank >= 1 && o.outside === \"zero\";\n}\n\n/** Whether the accessor carries the stats flag and `valueMax` (the march layer). */\nfunction carriesStats(profileRank: number, o: ApiOptions): boolean {\n return hasMarch(profileRank, o);\n}\n\n/** The record functions every reader shares, in emission order. */\nfunction recordFunctions(o: ApiOptions): string[] {\n const typeOk = o.types.map((t) => `t == ${GRID_TYPE_CONSTANT[t]}`).join(\" || \");\n return [\n `fn vdb_rec(g: u32, w: u32) -> u32 {\n return vdb_load(VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w);\n}`,\n `fn vdb_type_ok(t: u32) -> bool {\n return ${typeOk};\n}`,\n `fn vdbGridCount() -> u32 {\n return vdb_load(VDB_HEADER_GRID_COUNT);\n}`,\n `fn vdb_live(g: u32) -> bool {\n return g < vdbGridCount() && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_LIVE) != 0u;\n}`,\n `fn vdbGridType(g: u32) -> u32 {\n if !vdb_live(g) {\n return 0u;\n }\n return vdb_rec(g, VDB_REC_GRID_TYPE);\n}`,\n `fn vdbIndexMin(g: u32) -> vec3i {\n if !vdb_live(g) {\n return vec3i(0);\n }\n return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MIN), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MIN + 2u)));\n}`,\n `fn vdbIndexMax(g: u32) -> vec3i {\n if !vdb_live(g) {\n return vec3i(-1);\n }\n return bitcast<vec3i>(vec3u(vdb_rec(g, VDB_REC_INDEX_BBOX_MAX), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 1u), vdb_rec(g, VDB_REC_INDEX_BBOX_MAX + 2u)));\n}`,\n ];\n}\n\nfunction readLayer(o: ApiOptions, profileRank: number): string {\n const bbox = carriesBBox(profileRank, o);\n if (o.reader === \"lean\") return leanReadLayer(o, bbox, recordFunctions(o));\n const stats = carriesStats(profileRank, o);\n const extraFields = (bbox ? \"\\n lo: vec3i,\\n hi: vec3i,\" : \"\") + (stats ? \"\\n stats: bool,\\n vmax: f32,\" : \"\");\n const extraInit =\n (bbox ? \"\\n a.lo = vdbIndexMin(g);\\n a.hi = vdbIndexMax(g);\" : \"\") +\n (stats\n ? \"\\n a.stats = (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;\\n a.vmax = bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));\"\n : \"\");\n const parts = [\n `struct VdbAccessor {\n buf: vdb_buf_t,\n gridType: u32,\n ok: bool,\n inner: vdb_readaccessor_t,${extraFields}\n}`,\n ...recordFunctions(o),\n `fn vdbAccessorInit(g: u32) -> VdbAccessor {\n var a: VdbAccessor;\n a.gridType = vdbGridType(g);\n a.ok = vdb_type_ok(a.gridType);\n var root = vdb_root_handle_t(0u);\n if a.ok {\n a.buf = vdb_make_buffer(vdb_rec(g, VDB_REC_IMAGE_OFFSET), vdb_rec(g, VDB_REC_IMAGE_BYTES) >> 2u);\n root = vdb_tree_get_root(a.buf, vdb_grid_get_tree(vdb_grid_handle_t(0u)));${extraInit}\n }\n var inner: vdb_readaccessor_t;\n vdb_readaccessor_init(&inner, root);\n a.inner = inner;\n return a;\n}`,\n `fn vdbReadValue(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ijk);\n (*acc).inner = inner;\n return v;\n}`,\n ];\n if (o.isActive) {\n parts.push(`fn vdbIsActive(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> bool {\n if !(*acc).ok {\n return false;\n }\n var inner = (*acc).inner;\n let v = vdb_readaccessor_is_active((*acc).gridType, (*acc).buf, &inner, ijk);\n (*acc).inner = inner;\n return v;\n}`);\n }\n return parts.join(\"\\n\");\n}\n\n/**\n * `vdbSample` per sampler and `outside` mode.\n *\n * `outside: 'background'` reads the tree everywhere (NanoVDB: outside the\n * tree the background value).\n *\n * `outside: 'zero'` samples the field that equals the tree inside the index\n * bbox `[min, max]` (voxels, inclusive) and 0 outside it, so both samplers\n * see the same box with voxel centres at integers:\n * - trilinear: each of the 8 taps outside `[min, max]` reads 0. A point is\n * 0 unless its base voxel `floor(xyz)` lies in `[min - 1, max]` (some tap\n * inside), i.e. `xyz` in `[min - 1, max + 1)`.\n * - nearest: the voxel `floor(xyz + 0.5)` must lie in `[min, max]`, i.e.\n * `xyz` in `[min - 0.5, max + 0.5)`; else 0.\n * CPU twins: `tools` `vdbSampleTrilinearCpu` / `vdbSampleNearestCpu` with `{ outside: 'zero' }`.\n */\nfunction sampleFunction(o: ApiOptions, profileRank: number): string[] {\n if (o.reader === \"lean\") return leanSampleFunctions(o, carriesBBox(profileRank, o));\n const read =(ijk: string) => `vdb_readaccessor_get_value_float((*acc).gridType, (*acc).buf, &inner, ${ijk})`;\n if (!carriesBBox(profileRank, o)) {\n const lookup =\n o.sampler === \"trilinear\" ? \"vdb_sample_trilinear_typed((*acc).gridType, (*acc).buf, &inner, xyz)\" : read(\"vec3i(floor(xyz + vec3f(0.5)))\");\n return [\n `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = ${lookup};\n (*acc).inner = inner;\n return v;\n}`,\n ];\n }\n if (o.sampler === \"nearest\") {\n return [\n `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n let ijk = vec3i(floor(xyz + vec3f(0.5)));\n if !(*acc).ok || any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = ${read(\"ijk\")};\n (*acc).inner = inner;\n return v;\n}`,\n ];\n }\n // Same tap order and lerp structure as the vendored sample_trilinear_typed.\n return [\n `fn vdb_tap0(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> f32 {\n if any(ijk < (*acc).lo) || any(ijk > (*acc).hi) {\n return 0.0;\n }\n var inner = (*acc).inner;\n let v = ${read(\"ijk\")};\n (*acc).inner = inner;\n return v;\n}`,\n `fn vdbSample(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n let b = vec3i(floor(xyz));\n if !(*acc).ok || any(b < (*acc).lo - vec3i(1)) || any(b > (*acc).hi) {\n return 0.0;\n }\n let u = xyz - vec3f(b);\n let x00 = mix(vdb_tap0(acc, b), vdb_tap0(acc, b + vec3i(1, 0, 0)), u.x);\n let x10 = mix(vdb_tap0(acc, b + vec3i(0, 1, 0)), vdb_tap0(acc, b + vec3i(1, 1, 0)), u.x);\n let x01 = mix(vdb_tap0(acc, b + vec3i(0, 0, 1)), vdb_tap0(acc, b + vec3i(1, 0, 1)), u.x);\n let x11 = mix(vdb_tap0(acc, b + vec3i(0, 1, 1)), vdb_tap0(acc, b + vec3i(1, 1, 1)), u.x);\n return mix(mix(x00, x10, u.y), mix(x01, x11, u.y), u.z);\n}`,\n ];\n}\n\nfunction sampleLayer(o: ApiOptions, profileRank: number): string {\n return [\n `fn vdb_row(b: u32) -> vec4f {\n return bitcast<vec4f>(vec4u(vdb_load(b), vdb_load(b + 1u), vdb_load(b + 2u), vdb_load(b + 3u)));\n}`,\n `fn vdb_affine(g: u32, w: u32, p: vec4f) -> vec3f {\n if !vdb_live(g) {\n return vec3f(0.0);\n }\n let b = VDB_POOL_TABLE_WORD + g * VDB_POOL_RECORD_WORDS + w;\n return vec3f(dot(vdb_row(b), p), dot(vdb_row(b + 4u), p), dot(vdb_row(b + 8u), p));\n}`,\n `fn vdbWorldToIndex(g: u32, p: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(p, 1.0));\n}`,\n `fn vdbWorldToIndexDir(g: u32, d: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_WORLD_TO_INDEX, vec4f(d, 0.0));\n}`,\n `fn vdbIndexToWorld(g: u32, p: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(p, 1.0));\n}`,\n `fn vdbIndexToWorldDir(g: u32, d: vec3f) -> vec3f {\n return vdb_affine(g, VDB_REC_INDEX_TO_WORLD, vec4f(d, 0.0));\n}`,\n ...sampleFunction(o, profileRank),\n `fn vdbRayClip(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {\n if !vdb_live(g) {\n return false;\n }\n var t0 = (*t).x;\n var t1 = (*t).y;\n let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)), vec3f(vdbIndexMax(g) + vec3i(1)), o, &t0, d, &t1);\n *t = vec2f(t0, t1);\n return hit && t0 <= t1;\n}`,\n ].join(\"\\n\");\n}\n\n/**\n * `march` (design note §3.2): the vendored HDDA, the accessor's node size at a\n * voxel, and node stats.\n *\n * `vdbGetDim(acc, ijk)` is the vendored `readaccessor_get_dim`: 1 inside a\n * leaf, 8 in a lower-node tile, 128 in an upper-node tile, 4096 in a root tile\n * or the background (and 4096 for a grid the accessor can't read, so a walk\n * ends after one cell instead of stalling at dim 0).\n *\n * `vdbNodeMax(acc, ijk, dim)` bounds the aligned cell of size `dim` holding\n * `ijk`. With `a = vdbGetDim(acc, ijk)`:\n * - `a > 1` and `dim <= a`: the cell lies in one tile; returns its value\n * (exact, active or not).\n * - otherwise the max statistic of the smallest node spanning the cell: the\n * leaf for `dim <= 8`, lower for `<= 128`, upper for `<= 4096`, else root.\n * NanoVDB stats cover ACTIVE values only: the result bounds the active\n * voxels and active tiles of that node, not inactive values, and not a\n * trilinear sample, whose taps reach one voxel into the neighbours.\n * - without stats (record flag b1 clear) the stats branches return the\n * record's `valueMax`: the caller's bound from `pool.add`, else +Infinity\n * (the pool convention for \"no bound\"). Test `vdbHasStats(g)` rather than\n * relying on infinity arithmetic.\n * The node handles come from the accessor cache that `vdbGetDim` just filled\n * along `ijk`'s path (leaf, lower and upper are all valid whenever the level\n * below them is, see the vendored `readaccessor_iscached*`).\n */\nfunction marchLayer(): string {\n return [\n `alias VdbHdda = vdb_hdda_t;`,\n `fn vdbHddaInit(h: ptr<function, VdbHdda>, o: vec3f, tmin: f32, d: vec3f, tmax: f32, dim: u32) {\n vdb_hdda_init(h, o, tmin, d, tmax, i32(dim));\n}`,\n `fn vdbHddaUpdate(h: ptr<function, VdbHdda>, o: vec3f, d: vec3f, dim: u32) -> bool {\n return vdb_hdda_update(h, o, d, i32(dim));\n}`,\n `fn vdbHddaStep(h: ptr<function, VdbHdda>) -> bool {\n return vdb_hdda_step(h);\n}`,\n `fn vdbGetDim(acc: ptr<function, VdbAccessor>, ijk: vec3i) -> u32 {\n if !(*acc).ok {\n return 4096u;\n }\n var inner = (*acc).inner;\n let v = vdb_readaccessor_get_dim((*acc).gridType, (*acc).buf, &inner, ijk);\n (*acc).inner = inner;\n return v;\n}`,\n `fn vdbHasStats(g: u32) -> bool {\n return vdb_live(g) && (vdb_rec(g, VDB_REC_FLAGS) & VDB_REC_FLAG_HAS_STATS) != 0u;\n}`,\n `fn vdbValueMax(g: u32) -> f32 {\n if !vdb_live(g) {\n return 0.0;\n }\n return bitcast<f32>(vdb_rec(g, VDB_REC_VALUE_MAX));\n}`,\n `fn vdbNodeMax(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n let a = vdbGetDim(acc, ijk);\n if a > 1u && dim <= a {\n return vdbReadValue(acc, ijk);\n }\n if !(*acc).stats {\n return (*acc).vmax;\n }\n let t = (*acc).gridType;\n let b = (*acc).buf;\n if dim <= 8u {\n return vdb_leaf_get_max_float(t, b, (*acc).inner.leaf);\n }\n if dim <= 128u {\n return vdb_lower_get_max_float(t, b, (*acc).inner.lower);\n }\n if dim <= 4096u {\n return vdb_upper_get_max_float(t, b, (*acc).inner.upper);\n }\n return vdb_root_get_max_float(t, b, (*acc).inner.root);\n}`,\n ].join(\"\\n\");\n}\n\n/**\n * Opt-in helpers (K1.7a, the `helpers` option). Each is emitted only when\n * asked for, so modules without helpers keep their bytes (the size snapshot).\n *\n * `vdbCellBoundTrilinear(acc, ijk, dim)`: the max of `vdbNodeMax` over the\n * 2x2x2 block of aligned `dim`-cells whose min corner is the cell holding\n * `ijk` (that cell and its +x/+y/+z neighbours). A trilinear sample at `p`\n * reads voxels `floor(p) + {0,1}^3`, so when `floor(p)` lies in the cell every\n * tap lies in the block and the result bounds the sample, with `vdbNodeMax`'s\n * caveat: stats bound ACTIVE values, so inactive leaf voxels must be <= their\n * leaf's max (true of fog volumes). With `outside: 'zero'` and a negative\n * field, also take max(result, 0). This is the skip test a march needs; the\n * cell's own `vdbNodeMax` is not one (CLAUDE.md Traps). CPU twin: `tools`\n * `cellBoundTrilinear`.\n *\n * `vdbHddaCellEnd(h)`: the ray `t` where the HDDA's current cell ends,\n * `min(next.x, next.y, next.z, tmax)` of the vendored state, so a host\n * needn't name `VdbHdda`'s vendored fields. CPU twin: `tools` `hddaCellEnd`.\n *\n * `vdbNodeAverage(acc, ijk, dim)` (K3.2): the box mean of the aligned\n * `dim`-cell holding `ijk`, from node statistics instead of voxels (the\n * sparse volume source's `'node-average'` LOD). A cell inside one tile (or the\n * background) is that tile's value, exactly. Otherwise, for `dim <= 8`, the\n * leaf's average times its active fraction (`countOneBits` of the value mask\n * / 512): the exact mean when the leaf's inactive voxels are 0 (fog); for\n * `dim <= 128`, the lower node's average, which is the mean of its ACTIVE\n * voxels (NanoVDB stores no active count per lower node), so it overstates a\n * partly empty lower node; larger cells read the lower node too (`dim` is\n * meant to be 8 or 128; no upper level, to keep the module small). Without stats it is the value at `ijk` (no\n * prefilter). CPU twin: `tools` `nodeAverage`.\n *\n * `vdbRayClipSupport(g, o, d, t)`: `vdbRayClip` against the box where\n * `vdbSample` can read the grid's voxels: `[min - 1, max + 1]` for trilinear\n * (the taps of a point in `[min - 1, min)` reach voxel `min`) and\n * `[min - 0.5, max + 0.5]` for nearest. `vdbRayClip`'s box, `[min, max + 1]`,\n * is the voxel-cell box the HDDA walks; it cuts the min-side half voxel of the\n * trilinear support. CPU twin: `tools` `rayClipSupport`.\n */\nfunction helperFunctions(o: ApiOptions): string[] {\n const out: string[] = [];\n if (o.helpers.includes(\"rayClipSupport\")) {\n const pad = o.sampler === \"nearest\" ? \"0.5\" : \"1.0\";\n out.push(`fn vdbRayClipSupport(g: u32, o: vec3f, d: vec3f, t: ptr<function, vec2f>) -> bool {\n if !vdb_live(g) {\n return false;\n }\n var t0 = (*t).x;\n var t1 = (*t).y;\n let hit = vdb_hdda_ray_clip(vec3f(vdbIndexMin(g)) - vec3f(${pad}), vec3f(vdbIndexMax(g)) + vec3f(${pad}), o, &t0, d, &t1);\n *t = vec2f(t0, t1);\n return hit && t0 <= t1;\n}`);\n }\n if (o.helpers.includes(\"cellBoundTrilinear\")) {\n out.push(`fn vdbCellBoundTrilinear(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {\n var m = vdbNodeMax(acc, ijk, dim);\n for (var k = 1u; k < 8u; k++) {\n let c = vec3i(vec3u(k & 1u, (k >> 1u) & 1u, (k >> 2u) & 1u)) * i32(dim);\n m = max(m, vdbNodeMax(acc, ijk + c, dim));\n }\n return m;\n}`);\n }\n if (o.helpers.includes(\"hddaCellEnd\")) {\n out.push(`fn vdbHddaCellEnd(h: ptr<function, VdbHdda>) -> f32 {\n return min(min((*h).next.x, (*h).next.y), min((*h).next.z, (*h).tmax));\n}`);\n }\n // P1.16: the lean reader's own helpers (its vdbSampleFast, the unchecked init).\n if (o.reader === \"lean\") out.push(...leanHelperFunctions(o, carriesBBox(1, o)));\n if (o.reader !== \"lean\" && o.helpers.includes(\"fastTrilinear\")) {\n // Only trilinear has 8 taps to share (the generator rejects the helper with 'nearest').\n const inside = carriesBBox(1, o) ? \" || any(b < (*acc).lo) || any(b >= (*acc).hi)\" : \"\";\n // Uniform per-tap work (no per-lane choice between a leaf read and a descent: lanes of a SIMD group that\n // disagree would run both). All 8 taps lie in the base voxel's lower node (128-block) unless the base is\n // on its +x/+y/+z face; each tap is then one lower-node child lookup (the same words for taps in the same\n // leaf), never a tree walk. The vendored taps instead thrash the accessor's one-leaf cache when the cell\n // straddles leaves (x-fastest tap order alternates them).\n // A tap: one lower-node child lookup (the caching variant the accessor already uses, on a scratch cache).\n // vdbSampleFast: the lower node holding the base is the accessor's cached one, else a descent (which caches\n // it); at level 2+ the base's 128-block, which holds all 8 taps, is one tile (or the background): one value.\n // c0 holds taps 0-3 (z = 0), c1 taps 4-7 (z = 1), x fastest: the vendored c000, c100, c010, c110, c001, ...\n // No comments inside the WGSL: generated modules carry only the banner.\n out.push(`fn vdb_lower_tap(t: u32, buf: vdb_buf_t, node: vdb_lower_handle_t, b: vec3i, k: u32) -> f32 {\n let ijk = b + vec3i(vec3u(k & 1u, (k >> 1u) & 1u, k >> 2u));\n var s: vdb_readaccessor_t;\n let al = vdb_lower_get_value_address_and_level_and_cache(t, buf, node, ijk, &s);\n return vdb_read_float_typed(t, buf, al.address, ijk, al.level);\n}`);\n const taps = (from: number) => [0, 1, 2, 3].map((k) => `vdb_lower_tap(t, buf, n, b, ${from + k}u)`).join(\", \");\n out.push(`fn vdbSampleFast(acc: ptr<function, VdbAccessor>, xyz: vec3f) -> f32 {\n let b = vec3i(floor(xyz));\n if !(*acc).ok || any((b & vec3i(127)) == vec3i(127))${inside} {\n return vdbSample(acc, xyz);\n }\n let t = (*acc).gridType;\n let buf = (*acc).buf;\n var inner = (*acc).inner;\n var lower = vdb_readaccessor_iscached1(&inner, vdb_readaccessor_computedirty(&inner, b));\n var v = 0.0;\n if !lower {\n let al = vdb_readaccessor_get_value_address_and_level(t, buf, &inner, b);\n lower = al.level <= 1u;\n v = vdb_read_float_typed(t, buf, al.address, b, al.level);\n }\n (*acc).inner = inner;\n var c0 = vec4f(v);\n var c1 = vec4f(v);\n if lower {\n let n = inner.lower;\n c0 = vec4f(${taps(0)});\n c1 = vec4f(${taps(4)});\n }\n let u = xyz - vec3f(b);\n return mix(mix(mix(c0.x, c0.y, u.x), mix(c0.z, c0.w, u.x), u.y), mix(mix(c1.x, c1.y, u.x), mix(c1.z, c1.w, u.x), u.y), u.z);\n}`);\n }\n if (o.helpers.includes(\"nodeAverage\")) {\n out.push(`fn vdbNodeAverage(acc: ptr<function, VdbAccessor>, ijk: vec3i, dim: u32) -> f32 {\n if !(*acc).ok {\n return 0.0;\n }\n let a = vdbGetDim(acc, ijk);\n if (a > 1u && dim <= a) || !(*acc).stats || dim <= 1u {\n return vdbReadValue(acc, ijk);\n }\n let t = (*acc).gridType;\n let b = (*acc).buf;\n if dim <= 8u {\n let leaf = (*acc).inner.leaf;\n var n = 0u;\n for (var w = 0u; w < 16u; w++) {\n n += countOneBits(vdb_read_uint32(b, vdb_address_offset(leaf.address, VDB_LEAF_OFF_VALUE_MASK + 4u * w)));\n }\n return vdb_leaf_get_ave_float(t, b, leaf) * (f32(n) / 512.0);\n }\n return vdb_lower_get_ave_float(t, b, (*acc).inner.lower);\n}`);\n }\n // K3.7: the level-set zero-crossing finder and normal (./level-set.ts).\n if (o.helpers.includes(\"levelSet\")) out.push(...levelSetWgsl());\n // EX1f-b: the majorant profile's helpers (world and global inits, the two trackers; ./majorant.ts).\n out.push(...majorantHelpersWgsl(o));\n return out;\n}\n\n/**\n * API layers in profile order. A profile's API is every layer up to and\n * including its own, except that `majorant` (rank 3) takes the march layer\n * only with `majorant: 'nodeMax'` (P1.3: `brick` / `global` are `sample` plus\n * the walk, K1-core §3.2).\n */\nexport const API_LAYERS: readonly ((o: ApiOptions, profileRank: number) => string)[] = [\n readLayer,\n sampleLayer,\n marchLayer,\n (o) => majorantWgsl(o),\n];\n\n/** The public API text for the profile at `profileRank` (0 = read, 1 = sample, 2 = march, 3 = majorant), then the requested helpers. */\nexport function apiWgsl(profileRank: number, o: ApiOptions): string {\n const layers = API_LAYERS.slice(0, profileRank + 1).filter((_, i) => i !== 2 || hasMarch(profileRank, o));\n return [...layers.map((layer) => layer(o, profileRank)), ...helperFunctions(o)].join(\"\\n\");\n}\n\n/** A top-level declaration of the API text. */\ninterface ApiDeclaration {\n readonly kind: \"fn\" | \"struct\" | \"alias\";\n readonly name: string;\n readonly text: string;\n}\n\n/** The API text as its top-level declarations, in order (every one starts a line with `fn`, `struct` or `alias`). */\nfunction apiDeclarations(api: string): ApiDeclaration[] {\n const out: ApiDeclaration[] = [];\n let lines: string[] = [];\n const flush = () => {\n if (lines.length === 0) return;\n const m = /^(fn|struct|alias)\\s+([A-Za-z_][A-Za-z0-9_]*)/.exec(lines[0] as string);\n if (!m) throw new Error(`@pmndrs/vdb: unexpected API text before a declaration: ${lines[0]}`);\n out.push({ kind: m[1] as ApiDeclaration[\"kind\"], name: m[2] as string, text: lines.join(\"\\n\") });\n lines = [];\n };\n for (const line of api.split(\"\\n\")) {\n if (/^(fn|struct|alias)\\s/.test(line)) flush();\n lines.push(line);\n }\n flush();\n return out;\n}\n\n/** The public functions of an API text: what `keep` can name. */\nexport function apiPublicFunctions(api: string): string[] {\n return apiDeclarations(api)\n .filter((d) => d.kind === \"fn\" && /^vdb[A-Z]/.test(d.name))\n .map((d) => d.name);\n}\n\n/**\n * P1.16 `keep`: the API text cut to the named public functions and the declarations they reach (by identifier),\n * in the original order. The generator's vendored closure then follows from the cut text.\n */\nexport function pruneApiWgsl(api: string, keep: readonly string[]): string {\n const decls = apiDeclarations(api);\n const byName = new Map(decls.map((d) => [d.name, d]));\n const kept = new Set<string>();\n const stack = [...keep];\n while (stack.length > 0) {\n const name = stack.pop() as string;\n if (kept.has(name)) continue;\n kept.add(name);\n for (const m of (byName.get(name) as ApiDeclaration).text.matchAll(/[A-Za-z_][A-Za-z0-9_]*/g)) {\n if (byName.has(m[0]) && !kept.has(m[0])) stack.push(m[0]);\n }\n }\n return decls\n .filter((d) => kept.has(d.name))\n .map((d) => d.text)\n .join(\"\\n\");\n}\n"]}