@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,165 @@
1
+ /**
2
+ * K3.2f: the CPU side and the CPU twins of the core sparse source's brick cache (`core/source/brick-cache.ts`,
3
+ * design: docs/archive/handoffs/K3-2d.md "Design note: a brick cache", built in K3-2f.md).
4
+ *
5
+ * The cache serves level-0 density samples of a sparse source from a dense atlas instead of the tree:
6
+ *
7
+ * - **Pages.** One page per 8³ block of a volume's density index box, the blocks aligned to the grid's leaves
8
+ * (block `c` holds voxels `8c … 8c + 7`). A trilinear sample with base voxel `b = floor(p)` reads `b … b + 1`, all
9
+ * inside the 9³ voxels `8c … 8c + 8` of the block `c = b >> 3` holding `b`.
10
+ * - **Bricks.** A resident page names a brick of the atlas: those 9³ voxels (the block plus a +x/+y/+z apron), decoded
11
+ * from the tree. Every sample whose base voxel lies in the block reads its 8 taps from that one brick.
12
+ * - **Residency.** The sampler marks the pages it reads (a bit per page); the source reads the marks back, and
13
+ * {@link VDBBrickResidency} gives each marked page that is not resident a brick (evicting the least recently marked
14
+ * ones when the atlas is full). A page that is not resident is a miss: the sampler reads the tree (exact).
15
+ *
16
+ * Twins: {@link vdbBrickFillCpu} (the fill kernel), {@link vdbBrickSampleCpu} (the f32 brick sample, eight taps, and
17
+ * the r16f one, a hardware-filtered fetch over f16 texels with exact weights), {@link vdbBrickPageCpu} (the page
18
+ * lookup) and {@link vdbBrickHalfBound} (how far an r16f sample may sit from the tree's).
19
+ *
20
+ * Engine-free and core-free (D20).
21
+ */
22
+ type Vec3 = [number, number, number];
23
+ /** Voxels per page side (one leaf). */
24
+ export declare const VDB_BRICK_BLOCK = 8;
25
+ /** Texels per brick side: the block plus the +x/+y/+z apron. */
26
+ export declare const VDB_BRICK_SIDE = 9;
27
+ /** Texels per brick. */
28
+ export declare const VDB_BRICK_TEXELS: number;
29
+ /** A page-table header base that marks a volume without pages (it always reads the tree). */
30
+ export declare const VDB_BRICK_NO_PAGES = 4294967295;
31
+ /** The pages of one volume: the 8³ blocks its density index box touches. */
32
+ export interface VDBBrickPageLayout {
33
+ /** First block (`indexBox.min >> 3`, floor division). */
34
+ readonly blockMin: Vec3;
35
+ /** Blocks per axis. */
36
+ readonly dims: Vec3;
37
+ /** Pages (`dims` product). */
38
+ readonly count: number;
39
+ }
40
+ /** The pages of a density index box (inclusive voxel box). */
41
+ export declare function vdbBrickPageLayout(box: {
42
+ readonly min: readonly number[];
43
+ readonly max: readonly number[];
44
+ }): VDBBrickPageLayout;
45
+ /**
46
+ * Twin of the sampler's page lookup: the page (local to the volume, `x + (y + z·dy)·dx`) holding the base voxel of
47
+ * the index-space sample position `p`, or -1 when the base lies outside the layout (the sampler then reads the tree).
48
+ */
49
+ export declare function vdbBrickPageCpu(layout: VDBBrickPageLayout, p: readonly number[]): number;
50
+ /**
51
+ * K3.2f-e: the frame kernels that read a sparse source's level-0 density, in mark-section order: the gather (the view
52
+ * slices; in 'volume' lighting also the shadow marches), the 'frame' lighting grid density pass, the emission
53
+ * direction pass. A source's WGSL made for no kernel (probes, the reference renderer) counts as the gather.
54
+ */
55
+ export declare const VDB_BRICK_KERNELS: readonly ["gather", "grid", "emission"];
56
+ /** One of {@link VDB_BRICK_KERNELS}. */
57
+ export type VDBBrickKernel = (typeof VDB_BRICK_KERNELS)[number];
58
+ /**
59
+ * K3.2f-e: which kernels use the cache. `'all'` (default, K3.2f): every kernel reads through it and marks its pages.
60
+ * `'gather-marks'`: every kernel reads through it (hits read the brick, misses the tree), only the gather marks, so
61
+ * only the gather's pages take bricks. `'gather-only'`: only the gather reads and marks; the others read the tree.
62
+ */
63
+ export type VDBBrickKernels = "all" | "gather-marks" | "gather-only";
64
+ /** How one kernel's WGSL uses the cache (see {@link vdbBrickKernelUse}). */
65
+ export interface VDBBrickKernelUse {
66
+ /** Read resident bricks (else every sample reads the tree). */
67
+ readonly read: boolean;
68
+ /** Set the page's mark bit. */
69
+ readonly mark: boolean;
70
+ /** The marks section it sets (with `sections` > 1, one per kernel). */
71
+ readonly section: number;
72
+ /** Sections of the marks buffer: 1, or one per kernel with the internal `brickMarkStats`. */
73
+ readonly sections: number;
74
+ }
75
+ /**
76
+ * K3.2f-e: a kernel's use of the cache under `kernels`. With `stats` (the internal `brickMarkStats`) every kernel marks
77
+ * its own section of the marks buffer, so the source can count which kernel read which page; the residency still
78
+ * follows `kernels` (the gather's section only, unless `'all'`), so the images are the ones without `stats`.
79
+ */
80
+ export declare function vdbBrickKernelUse(kernels: VDBBrickKernels, kernel: VDBBrickKernel, stats?: boolean): VDBBrickKernelUse;
81
+ /** Twin of the sampler's mark address: the word of `page` in `section` of a marks buffer of `sectionWords` per section. */
82
+ export declare function vdbBrickMarkWordCpu(page: number, section: number, sectionWords: number): number;
83
+ /**
84
+ * K3.2f-e: the pages each section of a marks readback holds (ascending), pages ≥ `pages` dropped. `bits` holds
85
+ * `sections` equal sections (the buffer the WGSL splits by `arrayLength / sections`).
86
+ */
87
+ export declare function vdbBrickMarkSections(bits: Uint32Array, sections: number, pages: number): number[][];
88
+ /**
89
+ * K3.2f-e: the pages that take bricks from one observation: the union of the sections (ascending) under `'all'`, else
90
+ * the gather's section (section 0; with one section it holds whatever marked).
91
+ */
92
+ export declare function vdbBrickPolicyPages(kernels: VDBBrickKernels, sections: readonly (readonly number[])[]): number[];
93
+ /** The first voxel of a page's brick (`8 · block`). */
94
+ export declare function vdbBrickOrigin(layout: VDBBrickPageLayout, page: number): Vec3;
95
+ /**
96
+ * Twin of the fill kernel: the 9³ tree values of the brick at voxel `origin` (x fastest), read as the sampler's
97
+ * taps read them (`vdbReadValueF32Cpu`; on Fp grids the GPU decode may differ by 1 f32 ulp, as for every reader).
98
+ */
99
+ export declare function vdbBrickFillCpu(image: Uint32Array, origin: readonly number[]): Float32Array;
100
+ /** The r16f brick: each value rounded to binary16, nearest even (the fill kernel's pack; NanoVDB `FloatToHalf`). */
101
+ export declare function vdbBrickToHalf(values: Float32Array): Uint16Array;
102
+ /** The values of an r16f brick. */
103
+ export declare function vdbBrickFromHalf(bits: Uint16Array): Float32Array;
104
+ /** The 8 taps of the base voxel `b` from a brick (c000, c100, c010, c110, c001, c101, c011, c111). */
105
+ export declare function vdbBrickTaps(brick: Float32Array, b: readonly number[]): number[];
106
+ /**
107
+ * Twin of the brick sample at index-space position `p` from the brick of the block holding `floor(p)`: the trilinear
108
+ * blend (the vendored lerp order: x, then y, then z) of its 8 taps, in f64. For an f32 brick it is the tree's
109
+ * trilinear sample (`vdbSampleTrilinearCpu`) to f32 rounding; for an r16f brick (values from {@link vdbBrickFromHalf})
110
+ * it is the hardware filter with exact weights.
111
+ */
112
+ export declare function vdbBrickSampleCpu(brick: Float32Array, p: readonly number[]): number;
113
+ /**
114
+ * The bound on |r16f brick sample − tree sample| at a sample whose 8 tree taps are `taps` (K3.2f, justified in
115
+ * K3-2f.md):
116
+ *
117
+ * - values: each tap rounds to binary16 to nearest, an error ≤ half an ulp: ≤ 2⁻¹¹ |v| for normal halves, ≤ 2⁻²⁵ for
118
+ * subnormal ones; a convex blend of the taps keeps the largest (2⁻¹¹ max|v| + 2⁻²⁵);
119
+ * - weights: `weightError` per axis (0 for exact weights; the hardware filter quantizes the fraction: 8 bits on Apple
120
+ * GPUs, ≤ 2⁻⁹ per axis), three nested lerps, each moving the result by ≤ weightError · (max − min of its inputs);
121
+ * - f32 arithmetic of the blend: 2⁻²¹ max|v| (a few roundings of values ≤ max|v|).
122
+ */
123
+ export declare function vdbBrickHalfBound(taps: readonly number[], weightError?: number): number;
124
+ /** What one {@link VDBBrickResidency.observe} did. */
125
+ export interface VDBBrickObservation {
126
+ /** Pages given a brick: `[page, slot]` (the fill must write those bricks before the pages are sampled). */
127
+ readonly allocated: readonly (readonly [number, number])[];
128
+ /** Pages that lost their brick (their entry must read 0 again). */
129
+ readonly evicted: readonly number[];
130
+ /** Marked pages that were not resident (each read the tree since the previous observation). */
131
+ readonly misses: number;
132
+ /** Misses left without a brick (the fill budget, or every brick marked in this observation). */
133
+ readonly overflow: number;
134
+ }
135
+ /**
136
+ * The brick allocator of the cache: which page holds which atlas slot, least recently marked first out. Pure (no
137
+ * GPU); the core source applies its answers to the page table and records the fills.
138
+ *
139
+ * `observe(marked, now, budget)` takes the pages the sampler marked since the previous observation: a marked
140
+ * resident page is stamped `now`; a marked page without a brick takes a free slot, else the slot of the resident
141
+ * page with the oldest stamp, never one stamped `now` (a page every frame reads is never evicted for another one the
142
+ * same frames read: such misses overflow instead, and read the tree).
143
+ */
144
+ export declare class VDBBrickResidency {
145
+ #private;
146
+ /** Atlas slots. */
147
+ capacity: number;
148
+ constructor(capacity: number);
149
+ /** Resident pages. */
150
+ get resident(): number;
151
+ /** The slot of `page`, or -1. */
152
+ slotOf(page: number): number;
153
+ /** The page in `slot`, or -1. */
154
+ pageOf(slot: number): number;
155
+ /** Resident pages with their slots. */
156
+ entries(): [number, number][];
157
+ /** More slots (the atlas grew; slots keep their numbers). */
158
+ grow(capacity: number): void;
159
+ observe(marked: Iterable<number>, now: number, budget?: number): VDBBrickObservation;
160
+ /** Frees the bricks of the pages `keep` rejects (an image or layout change); returns the dropped pages. */
161
+ drop(keep: (page: number) => boolean): number[];
162
+ /** Renumbers resident pages (a layout change moved a volume's page range); `to` returns the new page. */
163
+ remap(to: (page: number) => number): void;
164
+ }
165
+ export {};
@@ -0,0 +1,326 @@
1
+ /**
2
+ * K3.2f: the CPU side and the CPU twins of the core sparse source's brick cache (`core/source/brick-cache.ts`,
3
+ * design: docs/archive/handoffs/K3-2d.md "Design note: a brick cache", built in K3-2f.md).
4
+ *
5
+ * The cache serves level-0 density samples of a sparse source from a dense atlas instead of the tree:
6
+ *
7
+ * - **Pages.** One page per 8³ block of a volume's density index box, the blocks aligned to the grid's leaves
8
+ * (block `c` holds voxels `8c … 8c + 7`). A trilinear sample with base voxel `b = floor(p)` reads `b … b + 1`, all
9
+ * inside the 9³ voxels `8c … 8c + 8` of the block `c = b >> 3` holding `b`.
10
+ * - **Bricks.** A resident page names a brick of the atlas: those 9³ voxels (the block plus a +x/+y/+z apron), decoded
11
+ * from the tree. Every sample whose base voxel lies in the block reads its 8 taps from that one brick.
12
+ * - **Residency.** The sampler marks the pages it reads (a bit per page); the source reads the marks back, and
13
+ * {@link VDBBrickResidency} gives each marked page that is not resident a brick (evicting the least recently marked
14
+ * ones when the atlas is full). A page that is not resident is a miss: the sampler reads the tree (exact).
15
+ *
16
+ * Twins: {@link vdbBrickFillCpu} (the fill kernel), {@link vdbBrickSampleCpu} (the f32 brick sample, eight taps, and
17
+ * the r16f one, a hardware-filtered fetch over f16 texels with exact weights), {@link vdbBrickPageCpu} (the page
18
+ * lookup) and {@link vdbBrickHalfBound} (how far an r16f sample may sit from the tree's).
19
+ *
20
+ * Engine-free and core-free (D20).
21
+ */
22
+ import { vdbReadValueF32Cpu } from "../cpu/march.js";
23
+ import { vdbFloatToHalf, vdbHalfToFloat } from "../nanovdb/half.js";
24
+ /** Voxels per page side (one leaf). */
25
+ export const VDB_BRICK_BLOCK = 8;
26
+ /** Texels per brick side: the block plus the +x/+y/+z apron. */
27
+ export const VDB_BRICK_SIDE = 9;
28
+ /** Texels per brick. */
29
+ export const VDB_BRICK_TEXELS = VDB_BRICK_SIDE ** 3;
30
+ /** A page-table header base that marks a volume without pages (it always reads the tree). */
31
+ export const VDB_BRICK_NO_PAGES = 0xffffffff;
32
+ /** The pages of a density index box (inclusive voxel box). */
33
+ export function vdbBrickPageLayout(box) {
34
+ const blockMin = [0, 1, 2].map((a) => box.min[a] >> 3);
35
+ const dims = [0, 1, 2].map((a) => (box.max[a] >> 3) - blockMin[a] + 1);
36
+ if (dims.some((d) => !(d > 0)))
37
+ throw new RangeError(`vdbBrickPageLayout: empty box ${JSON.stringify(box)}`);
38
+ return { blockMin, dims, count: dims[0] * dims[1] * dims[2] };
39
+ }
40
+ /**
41
+ * Twin of the sampler's page lookup: the page (local to the volume, `x + (y + z·dy)·dx`) holding the base voxel of
42
+ * the index-space sample position `p`, or -1 when the base lies outside the layout (the sampler then reads the tree).
43
+ */
44
+ export function vdbBrickPageCpu(layout, p) {
45
+ const c = [0, 1, 2].map((a) => (Math.floor(p[a]) >> 3) - layout.blockMin[a]);
46
+ if (c.some((v, a) => v < 0 || v >= layout.dims[a]))
47
+ return -1;
48
+ return c[0] + (c[1] + c[2] * layout.dims[1]) * layout.dims[0];
49
+ }
50
+ /**
51
+ * K3.2f-e: the frame kernels that read a sparse source's level-0 density, in mark-section order: the gather (the view
52
+ * slices; in 'volume' lighting also the shadow marches), the 'frame' lighting grid density pass, the emission
53
+ * direction pass. A source's WGSL made for no kernel (probes, the reference renderer) counts as the gather.
54
+ */
55
+ export const VDB_BRICK_KERNELS = ["gather", "grid", "emission"];
56
+ /**
57
+ * K3.2f-e: a kernel's use of the cache under `kernels`. With `stats` (the internal `brickMarkStats`) every kernel marks
58
+ * its own section of the marks buffer, so the source can count which kernel read which page; the residency still
59
+ * follows `kernels` (the gather's section only, unless `'all'`), so the images are the ones without `stats`.
60
+ */
61
+ export function vdbBrickKernelUse(kernels, kernel, stats = false) {
62
+ const k = VDB_BRICK_KERNELS.indexOf(kernel);
63
+ if (k < 0)
64
+ throw new RangeError(`vdbBrickKernelUse: unknown kernel ${JSON.stringify(kernel)}`);
65
+ if (kernels !== "all" && kernels !== "gather-marks" && kernels !== "gather-only")
66
+ throw new RangeError(`vdbBrickKernelUse: unknown kernels ${JSON.stringify(kernels)}`);
67
+ return {
68
+ read: kernels !== "gather-only" || kernel === "gather",
69
+ mark: stats || kernels === "all" || kernel === "gather",
70
+ section: stats ? k : 0,
71
+ sections: stats ? VDB_BRICK_KERNELS.length : 1,
72
+ };
73
+ }
74
+ /** Twin of the sampler's mark address: the word of `page` in `section` of a marks buffer of `sectionWords` per section. */
75
+ export function vdbBrickMarkWordCpu(page, section, sectionWords) {
76
+ return section * sectionWords + (page >> 5);
77
+ }
78
+ /**
79
+ * K3.2f-e: the pages each section of a marks readback holds (ascending), pages ≥ `pages` dropped. `bits` holds
80
+ * `sections` equal sections (the buffer the WGSL splits by `arrayLength / sections`).
81
+ */
82
+ export function vdbBrickMarkSections(bits, sections, pages) {
83
+ if (!Number.isInteger(sections) || sections < 1 || bits.length % sections !== 0)
84
+ throw new RangeError(`vdbBrickMarkSections: ${bits.length} words do not split into ${sections} sections`);
85
+ const words = bits.length / sections;
86
+ const out = [];
87
+ for (let s = 0; s < sections; s++) {
88
+ const list = [];
89
+ for (let w = 0; w < words; w++) {
90
+ let word = bits[s * words + w];
91
+ while (word !== 0) {
92
+ const bit = 31 - Math.clz32(word & -word);
93
+ word &= word - 1;
94
+ const page = w * 32 + bit;
95
+ if (page < pages)
96
+ list.push(page);
97
+ }
98
+ }
99
+ out.push(list);
100
+ }
101
+ return out;
102
+ }
103
+ /**
104
+ * K3.2f-e: the pages that take bricks from one observation: the union of the sections (ascending) under `'all'`, else
105
+ * the gather's section (section 0; with one section it holds whatever marked).
106
+ */
107
+ export function vdbBrickPolicyPages(kernels, sections) {
108
+ if (kernels !== "all" || sections.length === 1)
109
+ return [...(sections[0] ?? [])];
110
+ const all = new Set();
111
+ for (const s of sections)
112
+ for (const p of s)
113
+ all.add(p);
114
+ return [...all].sort((a, b) => a - b);
115
+ }
116
+ /** The first voxel of a page's brick (`8 · block`). */
117
+ export function vdbBrickOrigin(layout, page) {
118
+ const [dx, dy] = layout.dims;
119
+ const c = [page % dx, Math.floor(page / dx) % dy, Math.floor(page / (dx * dy))];
120
+ return [0, 1, 2].map((a) => (layout.blockMin[a] + c[a]) * VDB_BRICK_BLOCK);
121
+ }
122
+ /**
123
+ * Twin of the fill kernel: the 9³ tree values of the brick at voxel `origin` (x fastest), read as the sampler's
124
+ * taps read them (`vdbReadValueF32Cpu`; on Fp grids the GPU decode may differ by 1 f32 ulp, as for every reader).
125
+ */
126
+ export function vdbBrickFillCpu(image, origin) {
127
+ const out = new Float32Array(VDB_BRICK_TEXELS);
128
+ let i = 0;
129
+ for (let z = 0; z < VDB_BRICK_SIDE; z++)
130
+ for (let y = 0; y < VDB_BRICK_SIDE; y++)
131
+ for (let x = 0; x < VDB_BRICK_SIDE; x++)
132
+ out[i++] = vdbReadValueF32Cpu(image, [origin[0] + x, origin[1] + y, origin[2] + z]);
133
+ return out;
134
+ }
135
+ /** The r16f brick: each value rounded to binary16, nearest even (the fill kernel's pack; NanoVDB `FloatToHalf`). */
136
+ export function vdbBrickToHalf(values) {
137
+ const out = new Uint16Array(values.length);
138
+ for (let i = 0; i < values.length; i++)
139
+ out[i] = vdbFloatToHalf(values[i]);
140
+ return out;
141
+ }
142
+ /** The values of an r16f brick. */
143
+ export function vdbBrickFromHalf(bits) {
144
+ const out = new Float32Array(bits.length);
145
+ for (let i = 0; i < bits.length; i++)
146
+ out[i] = vdbHalfToFloat(bits[i]);
147
+ return out;
148
+ }
149
+ /** The 8 taps of the base voxel `b` from a brick (c000, c100, c010, c110, c001, c101, c011, c111). */
150
+ export function vdbBrickTaps(brick, b) {
151
+ const l = [b[0] & 7, b[1] & 7, b[2] & 7];
152
+ const taps = [];
153
+ for (let k = 0; k < 8; k++) {
154
+ const x = l[0] + (k & 1);
155
+ const y = l[1] + ((k >> 1) & 1);
156
+ const z = l[2] + (k >> 2);
157
+ taps.push(brick[x + (y + z * VDB_BRICK_SIDE) * VDB_BRICK_SIDE]);
158
+ }
159
+ return taps;
160
+ }
161
+ /**
162
+ * Twin of the brick sample at index-space position `p` from the brick of the block holding `floor(p)`: the trilinear
163
+ * blend (the vendored lerp order: x, then y, then z) of its 8 taps, in f64. For an f32 brick it is the tree's
164
+ * trilinear sample (`vdbSampleTrilinearCpu`) to f32 rounding; for an r16f brick (values from {@link vdbBrickFromHalf})
165
+ * it is the hardware filter with exact weights.
166
+ */
167
+ export function vdbBrickSampleCpu(brick, p) {
168
+ const b = [Math.floor(p[0]), Math.floor(p[1]), Math.floor(p[2])];
169
+ const u = [p[0] - b[0], p[1] - b[1], p[2] - b[2]];
170
+ const t = vdbBrickTaps(brick, b);
171
+ const lerp = (a, c, w) => a + w * (c - a);
172
+ const x00 = lerp(t[0], t[1], u[0]);
173
+ const x10 = lerp(t[2], t[3], u[0]);
174
+ const x01 = lerp(t[4], t[5], u[0]);
175
+ const x11 = lerp(t[6], t[7], u[0]);
176
+ return lerp(lerp(x00, x10, u[1]), lerp(x01, x11, u[1]), u[2]);
177
+ }
178
+ /**
179
+ * The bound on |r16f brick sample − tree sample| at a sample whose 8 tree taps are `taps` (K3.2f, justified in
180
+ * K3-2f.md):
181
+ *
182
+ * - values: each tap rounds to binary16 to nearest, an error ≤ half an ulp: ≤ 2⁻¹¹ |v| for normal halves, ≤ 2⁻²⁵ for
183
+ * subnormal ones; a convex blend of the taps keeps the largest (2⁻¹¹ max|v| + 2⁻²⁵);
184
+ * - weights: `weightError` per axis (0 for exact weights; the hardware filter quantizes the fraction: 8 bits on Apple
185
+ * GPUs, ≤ 2⁻⁹ per axis), three nested lerps, each moving the result by ≤ weightError · (max − min of its inputs);
186
+ * - f32 arithmetic of the blend: 2⁻²¹ max|v| (a few roundings of values ≤ max|v|).
187
+ */
188
+ export function vdbBrickHalfBound(taps, weightError = 0) {
189
+ let lo = Infinity;
190
+ let hi = -Infinity;
191
+ let big = 0;
192
+ for (const v of taps) {
193
+ lo = Math.min(lo, v);
194
+ hi = Math.max(hi, v);
195
+ big = Math.max(big, Math.abs(v));
196
+ }
197
+ // Past the largest half (65504) a tap rounds to infinity: no bound.
198
+ if (big > 65504)
199
+ return Infinity;
200
+ return 2 ** -11 * big + 2 ** -25 + 3 * weightError * (hi - lo) + 2 ** -21 * big;
201
+ }
202
+ /**
203
+ * The brick allocator of the cache: which page holds which atlas slot, least recently marked first out. Pure (no
204
+ * GPU); the core source applies its answers to the page table and records the fills.
205
+ *
206
+ * `observe(marked, now, budget)` takes the pages the sampler marked since the previous observation: a marked
207
+ * resident page is stamped `now`; a marked page without a brick takes a free slot, else the slot of the resident
208
+ * page with the oldest stamp, never one stamped `now` (a page every frame reads is never evicted for another one the
209
+ * same frames read: such misses overflow instead, and read the tree).
210
+ */
211
+ export class VDBBrickResidency {
212
+ /** Atlas slots. */
213
+ capacity;
214
+ #slotOf = new Map();
215
+ #pageOf;
216
+ #stamp;
217
+ #free = [];
218
+ constructor(capacity) {
219
+ if (!Number.isInteger(capacity) || capacity < 0)
220
+ throw new RangeError(`VDBBrickResidency: capacity must be a non-negative integer, got ${capacity}`);
221
+ this.capacity = capacity;
222
+ this.#pageOf = new Int32Array(capacity).fill(-1);
223
+ this.#stamp = new Float64Array(capacity);
224
+ for (let s = capacity - 1; s >= 0; s--)
225
+ this.#free.push(s);
226
+ }
227
+ /** Resident pages. */
228
+ get resident() {
229
+ return this.#slotOf.size;
230
+ }
231
+ /** The slot of `page`, or -1. */
232
+ slotOf(page) {
233
+ return this.#slotOf.get(page) ?? -1;
234
+ }
235
+ /** The page in `slot`, or -1. */
236
+ pageOf(slot) {
237
+ return this.#pageOf[slot] ?? -1;
238
+ }
239
+ /** Resident pages with their slots. */
240
+ entries() {
241
+ return [...this.#slotOf.entries()];
242
+ }
243
+ /** More slots (the atlas grew; slots keep their numbers). */
244
+ grow(capacity) {
245
+ if (capacity <= this.capacity)
246
+ return;
247
+ const pageOf = new Int32Array(capacity).fill(-1);
248
+ pageOf.set(this.#pageOf);
249
+ const stamp = new Float64Array(capacity);
250
+ stamp.set(this.#stamp);
251
+ for (let s = this.capacity; s < capacity; s++)
252
+ this.#free.push(s);
253
+ // A stack popped from the end: lowest slot last.
254
+ this.#free.sort((a, b) => b - a);
255
+ this.#pageOf = pageOf;
256
+ this.#stamp = stamp;
257
+ this.capacity = capacity;
258
+ }
259
+ observe(marked, now, budget = Infinity) {
260
+ const missing = [];
261
+ for (const page of marked) {
262
+ const s = this.#slotOf.get(page);
263
+ if (s === undefined)
264
+ missing.push(page);
265
+ else
266
+ this.#stamp[s] = now;
267
+ }
268
+ const allocated = [];
269
+ const evicted = [];
270
+ let want = Math.min(missing.length, budget);
271
+ // Free slots first (lowest slot first: the atlas fills front to back), then the oldest stamps.
272
+ const victims = [];
273
+ if (want > this.#free.length) {
274
+ for (let s = 0; s < this.capacity; s++)
275
+ if (this.#pageOf[s] >= 0 && this.#stamp[s] < now)
276
+ victims.push(s);
277
+ victims.sort((a, b) => this.#stamp[a] - this.#stamp[b] || a - b);
278
+ }
279
+ let v = 0;
280
+ for (const page of missing) {
281
+ if (want <= 0)
282
+ break;
283
+ let slot = this.#free.pop();
284
+ if (slot === undefined) {
285
+ if (v >= victims.length)
286
+ break;
287
+ slot = victims[v++];
288
+ const old = this.#pageOf[slot];
289
+ this.#slotOf.delete(old);
290
+ evicted.push(old);
291
+ }
292
+ this.#pageOf[slot] = page;
293
+ this.#slotOf.set(page, slot);
294
+ this.#stamp[slot] = now;
295
+ allocated.push([page, slot]);
296
+ want--;
297
+ }
298
+ return { allocated, evicted, misses: missing.length, overflow: missing.length - allocated.length };
299
+ }
300
+ /** Frees the bricks of the pages `keep` rejects (an image or layout change); returns the dropped pages. */
301
+ drop(keep) {
302
+ const dropped = [];
303
+ for (const [page, slot] of [...this.#slotOf]) {
304
+ if (keep(page))
305
+ continue;
306
+ this.#slotOf.delete(page);
307
+ this.#pageOf[slot] = -1;
308
+ this.#stamp[slot] = 0;
309
+ this.#free.push(slot);
310
+ dropped.push(page);
311
+ }
312
+ // Lowest free slot next.
313
+ this.#free.sort((a, b) => b - a);
314
+ return dropped;
315
+ }
316
+ /** Renumbers resident pages (a layout change moved a volume's page range); `to` returns the new page. */
317
+ remap(to) {
318
+ const moved = [...this.#slotOf].map(([page, slot]) => [to(page), slot]);
319
+ this.#slotOf.clear();
320
+ for (const [page, slot] of moved) {
321
+ this.#slotOf.set(page, slot);
322
+ this.#pageOf[slot] = page;
323
+ }
324
+ }
325
+ }
326
+ //# sourceMappingURL=brick-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brick-cache.js","sourceRoot":"","sources":["../../../src/tools/frame/brick-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpE,uCAAuC;AACvC,MAAM,CAAC,M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the core sparse source's brick cache (`core/source/brick-cache.ts`,\n * design: docs/archive/handoffs/K3-2d.md \"Design note: a brick cache\", built in K3-2f.md).\n *\n * The cache serves level-0 density samples of a sparse source from a dense atlas instead of the tree:\n *\n * - **Pages.** One page per 8³ block of a volume's density index box, the blocks aligned to the grid's leaves\n * (block `c` holds voxels `8c … 8c + 7`). A trilinear sample with base voxel `b = floor(p)` reads `b … b + 1`, all\n * inside the 9³ voxels `8c … 8c + 8` of the block `c = b >> 3` holding `b`.\n * - **Bricks.** A resident page names a brick of the atlas: those 9³ voxels (the block plus a +x/+y/+z apron), decoded\n * from the tree. Every sample whose base voxel lies in the block reads its 8 taps from that one brick.\n * - **Residency.** The sampler marks the pages it reads (a bit per page); the source reads the marks back, and\n * {@link VDBBrickResidency} gives each marked page that is not resident a brick (evicting the least recently marked\n * ones when the atlas is full). A page that is not resident is a miss: the sampler reads the tree (exact).\n *\n * Twins: {@link vdbBrickFillCpu} (the fill kernel), {@link vdbBrickSampleCpu} (the f32 brick sample, eight taps, and\n * the r16f one, a hardware-filtered fetch over f16 texels with exact weights), {@link vdbBrickPageCpu} (the page\n * lookup) and {@link vdbBrickHalfBound} (how far an r16f sample may sit from the tree's).\n *\n * Engine-free and core-free (D20).\n */\n\nimport { vdbReadValueF32Cpu } from \"../cpu/march.js\";\nimport { vdbFloatToHalf, vdbHalfToFloat } from \"../nanovdb/half.js\";\n\ntype Vec3 = [number, number, number];\n\n/** Voxels per page side (one leaf). */\nexport const VDB_BRICK_BLOCK = 8;\n/** Texels per brick side: the block plus the +x/+y/+z apron. */\nexport const VDB_BRICK_SIDE = 9;\n/** Texels per brick. */\nexport const VDB_BRICK_TEXELS = VDB_BRICK_SIDE ** 3;\n/** A page-table header base that marks a volume without pages (it always reads the tree). */\nexport const VDB_BRICK_NO_PAGES = 0xffffffff;\n\n/** The pages of one volume: the 8³ blocks its density index box touches. */\nexport interface VDBBrickPageLayout {\n /** First block (`indexBox.min >> 3`, floor division). */\n readonly blockMin: Vec3;\n /** Blocks per axis. */\n readonly dims: Vec3;\n /** Pages (`dims` product). */\n readonly count: number;\n}\n\n/** The pages of a density index box (inclusive voxel box). */\nexport function vdbBrickPageLayout(box: { readonly min: readonly number[]; readonly max: readonly number[] }): VDBBrickPageLayout {\n const blockMin = [0, 1, 2].map((a) => box.min[a]! >> 3) as Vec3;\n const dims = [0, 1, 2].map((a) => (box.max[a]! >> 3) - blockMin[a]! + 1) as Vec3;\n if (dims.some((d) => !(d > 0))) throw new RangeError(`vdbBrickPageLayout: empty box ${JSON.stringify(box)}`);\n return { blockMin, dims, count: dims[0] * dims[1] * dims[2] };\n}\n\n/**\n * Twin of the sampler's page lookup: the page (local to the volume, `x + (y + z·dy)·dx`) holding the base voxel of\n * the index-space sample position `p`, or -1 when the base lies outside the layout (the sampler then reads the tree).\n */\nexport function vdbBrickPageCpu(layout: VDBBrickPageLayout, p: readonly number[]): number {\n const c = [0, 1, 2].map((a) => (Math.floor(p[a]!) >> 3) - layout.blockMin[a]!);\n if (c.some((v, a) => v < 0 || v >= layout.dims[a]!)) return -1;\n return c[0]! + (c[1]! + c[2]! * layout.dims[1]) * layout.dims[0];\n}\n\n/**\n * K3.2f-e: the frame kernels that read a sparse source's level-0 density, in mark-section order: the gather (the view\n * slices; in 'volume' lighting also the shadow marches), the 'frame' lighting grid density pass, the emission\n * direction pass. A source's WGSL made for no kernel (probes, the reference renderer) counts as the gather.\n */\nexport const VDB_BRICK_KERNELS = [\"gather\", \"grid\", \"emission\"] as const;\n/** One of {@link VDB_BRICK_KERNELS}. */\nexport type VDBBrickKernel = (typeof VDB_BRICK_KERNELS)[number];\n\n/**\n * K3.2f-e: which kernels use the cache. `'all'` (default, K3.2f): every kernel reads through it and marks its pages.\n * `'gather-marks'`: every kernel reads through it (hits read the brick, misses the tree), only the gather marks, so\n * only the gather's pages take bricks. `'gather-only'`: only the gather reads and marks; the others read the tree.\n */\nexport type VDBBrickKernels = \"all\" | \"gather-marks\" | \"gather-only\";\n\n/** How one kernel's WGSL uses the cache (see {@link vdbBrickKernelUse}). */\nexport interface VDBBrickKernelUse {\n /** Read resident bricks (else every sample reads the tree). */\n readonly read: boolean;\n /** Set the page's mark bit. */\n readonly mark: boolean;\n /** The marks section it sets (with `sections` > 1, one per kernel). */\n readonly section: number;\n /** Sections of the marks buffer: 1, or one per kernel with the internal `brickMarkStats`. */\n readonly sections: number;\n}\n\n/**\n * K3.2f-e: a kernel's use of the cache under `kernels`. With `stats` (the internal `brickMarkStats`) every kernel marks\n * its own section of the marks buffer, so the source can count which kernel read which page; the residency still\n * follows `kernels` (the gather's section only, unless `'all'`), so the images are the ones without `stats`.\n */\nexport function vdbBrickKernelUse(kernels: VDBBrickKernels, kernel: VDBBrickKernel, stats = false): VDBBrickKernelUse {\n const k = VDB_BRICK_KERNELS.indexOf(kernel);\n if (k < 0) throw new RangeError(`vdbBrickKernelUse: unknown kernel ${JSON.stringify(kernel)}`);\n if (kernels !== \"all\" && kernels !== \"gather-marks\" && kernels !== \"gather-only\") throw new RangeError(`vdbBrickKernelUse: unknown kernels ${JSON.stringify(kernels)}`);\n return {\n read: kernels !== \"gather-only\" || kernel === \"gather\",\n mark: stats || kernels === \"all\" || kernel === \"gather\",\n section: stats ? k : 0,\n sections: stats ? VDB_BRICK_KERNELS.length : 1,\n };\n}\n\n/** Twin of the sampler's mark address: the word of `page` in `section` of a marks buffer of `sectionWords` per section. */\nexport function vdbBrickMarkWordCpu(page: number, section: number, sectionWords: number): number {\n return section * sectionWords + (page >> 5);\n}\n\n/**\n * K3.2f-e: the pages each section of a marks readback holds (ascending), pages ≥ `pages` dropped. `bits` holds\n * `sections` equal sections (the buffer the WGSL splits by `arrayLength / sections`).\n */\nexport function vdbBrickMarkSections(bits: Uint32Array, sections: number, pages: number): number[][] {\n if (!Number.isInteger(sections) || sections < 1 || bits.length % sections !== 0) throw new RangeError(`vdbBrickMarkSections: ${bits.length} words do not split into ${sections} sections`);\n const words = bits.length / sections;\n const out: number[][] = [];\n for (let s = 0; s < sections; s++) {\n const list: number[] = [];\n for (let w = 0; w < words; w++) {\n let word = bits[s * words + w]!;\n while (word !== 0) {\n const bit = 31 - Math.clz32(word & -word);\n word &= word - 1;\n const page = w * 32 + bit;\n if (page < pages) list.push(page);\n }\n }\n out.push(list);\n }\n return out;\n}\n\n/**\n * K3.2f-e: the pages that take bricks from one observation: the union of the sections (ascending) under `'all'`, else\n * the gather's section (section 0; with one section it holds whatever marked).\n */\nexport function vdbBrickPolicyPages(kernels: VDBBrickKernels, sections: readonly (readonly number[])[]): number[] {\n if (kernels !== \"all\" || sections.length === 1) return [...(sections[0] ?? [])];\n const all = new Set<number>();\n for (const s of sections) for (const p of s) all.add(p);\n return [...all].sort((a, b) => a - b);\n}\n\n/** The first voxel of a page's brick (`8 · block`). */\nexport function vdbBrickOrigin(layout: VDBBrickPageLayout, page: number): Vec3 {\n const [dx, dy] = layout.dims;\n const c = [page % dx, Math.floor(page / dx) % dy, Math.floor(page / (dx * dy))];\n return [0, 1, 2].map((a) => (layout.blockMin[a]! + c[a]!) * VDB_BRICK_BLOCK) as Vec3;\n}\n\n/**\n * Twin of the fill kernel: the 9³ tree values of the brick at voxel `origin` (x fastest), read as the sampler's\n * taps read them (`vdbReadValueF32Cpu`; on Fp grids the GPU decode may differ by 1 f32 ulp, as for every reader).\n */\nexport function vdbBrickFillCpu(image: Uint32Array, origin: readonly number[]): Float32Array {\n const out = new Float32Array(VDB_BRICK_TEXELS);\n let i = 0;\n for (let z = 0; z < VDB_BRICK_SIDE; z++)\n for (let y = 0; y < VDB_BRICK_SIDE; y++)\n for (let x = 0; x < VDB_BRICK_SIDE; x++) out[i++] = vdbReadValueF32Cpu(image, [origin[0]! + x, origin[1]! + y, origin[2]! + z]);\n return out;\n}\n\n/** The r16f brick: each value rounded to binary16, nearest even (the fill kernel's pack; NanoVDB `FloatToHalf`). */\nexport function vdbBrickToHalf(values: Float32Array): Uint16Array {\n const out = new Uint16Array(values.length);\n for (let i = 0; i < values.length; i++) out[i] = vdbFloatToHalf(values[i]!);\n return out;\n}\n\n/** The values of an r16f brick. */\nexport function vdbBrickFromHalf(bits: Uint16Array): Float32Array {\n const out = new Float32Array(bits.length);\n for (let i = 0; i < bits.length; i++) out[i] = vdbHalfToFloat(bits[i]!);\n return out;\n}\n\n/** The 8 taps of the base voxel `b` from a brick (c000, c100, c010, c110, c001, c101, c011, c111). */\nexport function vdbBrickTaps(brick: Float32Array, b: readonly number[]): number[] {\n const l = [b[0]! & 7, b[1]! & 7, b[2]! & 7];\n const taps: number[] = [];\n for (let k = 0; k < 8; k++) {\n const x = l[0]! + (k & 1);\n const y = l[1]! + ((k >> 1) & 1);\n const z = l[2]! + (k >> 2);\n taps.push(brick[x + (y + z * VDB_BRICK_SIDE) * VDB_BRICK_SIDE]!);\n }\n return taps;\n}\n\n/**\n * Twin of the brick sample at index-space position `p` from the brick of the block holding `floor(p)`: the trilinear\n * blend (the vendored lerp order: x, then y, then z) of its 8 taps, in f64. For an f32 brick it is the tree's\n * trilinear sample (`vdbSampleTrilinearCpu`) to f32 rounding; for an r16f brick (values from {@link vdbBrickFromHalf})\n * it is the hardware filter with exact weights.\n */\nexport function vdbBrickSampleCpu(brick: Float32Array, p: readonly number[]): number {\n const b = [Math.floor(p[0]!), Math.floor(p[1]!), Math.floor(p[2]!)];\n const u = [p[0]! - b[0]!, p[1]! - b[1]!, p[2]! - b[2]!];\n const t = vdbBrickTaps(brick, b);\n const lerp = (a: number, c: number, w: number) => a + w * (c - a);\n const x00 = lerp(t[0]!, t[1]!, u[0]!);\n const x10 = lerp(t[2]!, t[3]!, u[0]!);\n const x01 = lerp(t[4]!, t[5]!, u[0]!);\n const x11 = lerp(t[6]!, t[7]!, u[0]!);\n return lerp(lerp(x00, x10, u[1]!), lerp(x01, x11, u[1]!), u[2]!);\n}\n\n/**\n * The bound on |r16f brick sample − tree sample| at a sample whose 8 tree taps are `taps` (K3.2f, justified in\n * K3-2f.md):\n *\n * - values: each tap rounds to binary16 to nearest, an error ≤ half an ulp: ≤ 2⁻¹¹ |v| for normal halves, ≤ 2⁻²⁵ for\n * subnormal ones; a convex blend of the taps keeps the largest (2⁻¹¹ max|v| + 2⁻²⁵);\n * - weights: `weightError` per axis (0 for exact weights; the hardware filter quantizes the fraction: 8 bits on Apple\n * GPUs, ≤ 2⁻⁹ per axis), three nested lerps, each moving the result by ≤ weightError · (max − min of its inputs);\n * - f32 arithmetic of the blend: 2⁻²¹ max|v| (a few roundings of values ≤ max|v|).\n */\nexport function vdbBrickHalfBound(taps: readonly number[], weightError = 0): number {\n let lo = Infinity;\n let hi = -Infinity;\n let big = 0;\n for (const v of taps) {\n lo = Math.min(lo, v);\n hi = Math.max(hi, v);\n big = Math.max(big, Math.abs(v));\n }\n // Past the largest half (65504) a tap rounds to infinity: no bound.\n if (big > 65504) return Infinity;\n return 2 ** -11 * big + 2 ** -25 + 3 * weightError * (hi - lo) + 2 ** -21 * big;\n}\n\n/** What one {@link VDBBrickResidency.observe} did. */\nexport interface VDBBrickObservation {\n /** Pages given a brick: `[page, slot]` (the fill must write those bricks before the pages are sampled). */\n readonly allocated: readonly (readonly [number, number])[];\n /** Pages that lost their brick (their entry must read 0 again). */\n readonly evicted: readonly number[];\n /** Marked pages that were not resident (each read the tree since the previous observation). */\n readonly misses: number;\n /** Misses left without a brick (the fill budget, or every brick marked in this observation). */\n readonly overflow: number;\n}\n\n/**\n * The brick allocator of the cache: which page holds which atlas slot, least recently marked first out. Pure (no\n * GPU); the core source applies its answers to the page table and records the fills.\n *\n * `observe(marked, now, budget)` takes the pages the sampler marked since the previous observation: a marked\n * resident page is stamped `now`; a marked page without a brick takes a free slot, else the slot of the resident\n * page with the oldest stamp, never one stamped `now` (a page every frame reads is never evicted for another one the\n * same frames read: such misses overflow instead, and read the tree).\n */\nexport class VDBBrickResidency {\n /** Atlas slots. */\n capacity: number;\n readonly #slotOf = new Map<number, number>();\n #pageOf: Int32Array;\n #stamp: Float64Array;\n #free: number[] = [];\n\n constructor(capacity: number) {\n if (!Number.isInteger(capacity) || capacity < 0) throw new RangeError(`VDBBrickResidency: capacity must be a non-negative integer, got ${capacity}`);\n this.capacity = capacity;\n this.#pageOf = new Int32Array(capacity).fill(-1);\n this.#stamp = new Float64Array(capacity);\n for (let s = capacity - 1; s >= 0; s--) this.#free.push(s);\n }\n\n /** Resident pages. */\n get resident(): number {\n return this.#slotOf.size;\n }\n\n /** The slot of `page`, or -1. */\n slotOf(page: number): number {\n return this.#slotOf.get(page) ?? -1;\n }\n\n /** The page in `slot`, or -1. */\n pageOf(slot: number): number {\n return this.#pageOf[slot] ?? -1;\n }\n\n /** Resident pages with their slots. */\n entries(): [number, number][] {\n return [...this.#slotOf.entries()];\n }\n\n /** More slots (the atlas grew; slots keep their numbers). */\n grow(capacity: number): void {\n if (capacity <= this.capacity) return;\n const pageOf = new Int32Array(capacity).fill(-1);\n pageOf.set(this.#pageOf);\n const stamp = new Float64Array(capacity);\n stamp.set(this.#stamp);\n for (let s = this.capacity; s < capacity; s++) this.#free.push(s);\n // A stack popped from the end: lowest slot last.\n this.#free.sort((a, b) => b - a);\n this.#pageOf = pageOf;\n this.#stamp = stamp;\n this.capacity = capacity;\n }\n\n observe(marked: Iterable<number>, now: number, budget = Infinity): VDBBrickObservation {\n const missing: number[] = [];\n for (const page of marked) {\n const s = this.#slotOf.get(page);\n if (s === undefined) missing.push(page);\n else this.#stamp[s] = now;\n }\n const allocated: [number, number][] = [];\n const evicted: number[] = [];\n let want = Math.min(missing.length, budget);\n // Free slots first (lowest slot first: the atlas fills front to back), then the oldest stamps.\n const victims: number[] = [];\n if (want > this.#free.length) {\n for (let s = 0; s < this.capacity; s++) if (this.#pageOf[s]! >= 0 && this.#stamp[s]! < now) victims.push(s);\n victims.sort((a, b) => this.#stamp[a]! - this.#stamp[b]! || a - b);\n }\n let v = 0;\n for (const page of missing) {\n if (want <= 0) break;\n let slot = this.#free.pop();\n if (slot === undefined) {\n if (v >= victims.length) break;\n slot = victims[v++]!;\n const old = this.#pageOf[slot]!;\n this.#slotOf.delete(old);\n evicted.push(old);\n }\n this.#pageOf[slot] = page;\n this.#slotOf.set(page, slot);\n this.#stamp[slot] = now;\n allocated.push([page, slot]);\n want--;\n }\n return { allocated, evicted, misses: missing.length, overflow: missing.length - allocated.length };\n }\n\n /** Frees the bricks of the pages `keep` rejects (an image or layout change); returns the dropped pages. */\n drop(keep: (page: number) => boolean): number[] {\n const dropped: number[] = [];\n for (const [page, slot] of [...this.#slotOf]) {\n if (keep(page)) continue;\n this.#slotOf.delete(page);\n this.#pageOf[slot] = -1;\n this.#stamp[slot] = 0;\n this.#free.push(slot);\n dropped.push(page);\n }\n // Lowest free slot next.\n this.#free.sort((a, b) => b - a);\n return dropped;\n }\n\n /** Renumbers resident pages (a layout change moved a volume's page range); `to` returns the new page. */\n remap(to: (page: number) => number): void {\n const moved = [...this.#slotOf].map(([page, slot]) => [to(page), slot] as const);\n this.#slotOf.clear();\n for (const [page, slot] of moved) {\n this.#slotOf.set(page, slot);\n this.#pageOf[slot] = page;\n }\n }\n}\n"]}